
Mnesia and LevelDB: Liberating Mnesia from the limitations of DETS - rdtsc
http://www.erlang-factory.com/euc2015/mikael-pettersson
======
rdtsc
Klarna (the European payment processor) and WhatsApp architectures are built
on Mnesia. Mnesia is Erlang's built-in distributed database. Due to its age it
has a few bad corner cases, that could be fixed if it just had a better
backend (the front-end API is nice, well designed, supports transactions, is
built-in to the lanauge).

So this effort brought in the ability to have a better backend, and make
Mnesia a better option as a general purpose distributed database.

Here is an talk on how WhatsApp uses Mnesia:

Erlang Factory 2014 - That's 'Billion' with a 'B': Scaling to the Next Level
at WhatsApp

[https://www.youtube.com/watch?v=c12cYAUTXXs](https://www.youtube.com/watch?v=c12cYAUTXXs)

Here is an example of using Mnesia:

[https://en.wikibooks.org/wiki/Erlang_Programming/Using_mnesi...](https://en.wikibooks.org/wiki/Erlang_Programming/Using_mnesia)

~~~
scurvy
Raise your hand if you're ever actually run mnesia on a busy server in a
distributed system. OK, show of hands of how many people will do that again?
Thought so.

mnesia should not be in the OTP. Not by a longshot.

I love Erlang. I hate mnesia.

~~~
derefr
I think people are trying to use mnesia for things it wasn't made for. mnesia
basically has exactly one purpose:

• in a 1:1 master:hot-spare setup,

• where the nodes contain _their own_ data in process-memory-space rather than
relying on a separate "database" node,

• and you need to be able to fail-over to the hot-spare and promote it to
master, without business logic being aware of this,

• and your system has time tolerances allowing you to _manually fix the old
master_ and bring it up as the new hot-spare,

then mnesia is perfect.

You know what system I'm describing?

Call switching!

You know what system I'm _not_ describing?

Most things!

~~~
seiji
_You know what system I 'm describing? Call switching!_

Exactly right!

The "distributed" part of Erlang (including mnesia) was designed to run in a
blade-like system where the networking was provided by a physical common
backplane among all the compute cards in the chassis.

So, a lot of distributed erlang and mnesia falls apart when dealing with
network partitions and resyncs and real-world scenarios that wouldn't really
happen on a common physical substrate.

That's why most sane erlang people won't run distributed erlang (gotta love
that epmd), they'll run their own TCP servers connecting to external DBs.

~~~
mononcqc
Distributed Erlang on its own is fine to run in production (particularly as a
control plane for metadata between nodes) because few assumptions about
reliability of the network are baked in; most of them can be made by the
application designer.

Distributed OTP applications (with the automated takeover/failover mechanism)
see very little use in the real world because of their set of assumptions that
network failures are rarer than software or hardware failure, which result in
perceiving all netsplits as nodes going down (a great way to get split
brains!)

------
Ixiaus
Plumtree is an excellent alternative to Mnesia:
[https://github.com/helium/plumtree](https://github.com/helium/plumtree)

------
istvan__
Thanks for sharing this. Mnesia is a little bit quirky at the first glance but
it is a pretty cool system. LevelDB also battle tested lots of systems build
on it. I am curious how good is combining the two.

