Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why big companies use Mnesia instead of using Riak or CouchDB [closed]

I can see 2 big companies like Klarna and Whatsapp are using Mnesia as their in memory database (not sure how they persist data with Mnesia with 2GB limit). My question is: why companies like those, and may be more I don't know, use Mnesia instead of Riak or couchDB, both are Erlang, where both databases support faster in memory databases, better painless persistence, and much more features. Do I miss something here?

like image 206
securecurve Avatar asked Apr 20 '14 09:04

securecurve


2 Answers

You are missing a number of important points:

First of all, mnesia has no 2 gigabyte limit. It is limited on a 32bit architecture, but hardly any are present anymore for real work. And on 64bit, you are not limited to 2 gigabyte. I have seen databases on the order of several hundred gigabytes. The only problem is the initial start-up time for those.

Mnesia is built to handle:

  • Very low latency K/V lookup, not necessarily linearizible.
  • Proper transactions with linearizible changes (C in the CAP theorem). These are allowed to run at a much worse latency as they are expected to be relatively rare.
  • On-line schema change
  • Survival even if nodes fail in a cluster (where cluster is smallish, say 10-50 machines at most)

The design is such that you avoid a separate process since data is in the Erlang system already. You have QLC for datalog-like queries. And you have the ability to store any Erlang term.

Mnesia fares well if the above is what you need. Its limits are:

  • You can't get a machine with more than 2 terabytes of memory. And loading 2 teras from scratch is going to be slow.
  • Since it is a CP system and not an AP system, the loss of nodes requires manual intervention. You may not need transactions as well. You might also want to be able to seamlessly add more nodes to the system and so on. For this, Riak is a better choice.
  • It uses optimistic locking which gives trouble if many processes tries to access the same row in a transaction.

My normal goto-trick is to start out with Mnesia in Erlang-systems and then switch over to another system as the data size grows. If data sizes grows slowly, then you can keep everything in memory in Mnesia and get up and running extremely quickly.

like image 123
I GIVE CRAP ANSWERS Avatar answered Nov 06 '22 06:11

I GIVE CRAP ANSWERS


  • As for persistent storage capacity for mnesia, "the 2 gb limit for disk tables" is a common delusion. Read this post What is the storage capacity of a Mnesia database?

very attentively. There are no actual limits for mnesia disk table size.

  • Mnesia is free unlike riak(for commercial usage).
  • Read about cap theorem. You can build your own ca or cp or ap database using plain mnesia as a backend. But if you take a particular dbms, say couchdb, it is designed to be ap out of box. And you cant make it, say , ca(as far as I know)
like image 10
Oleksandr Khryplyvenko Avatar answered Nov 06 '22 04:11

Oleksandr Khryplyvenko