Steve Jenson's blog

Mnesia

Mnesia

This weekend I read a short paper on Mnesia; a relational database designed for telecom applications with soft realtime requirements. It features election-free replication (!!) and is linked into the application's address space for efficiency.

Mnesia is written entirely in Erlang and is only 20,000 lines of code. It's query and operational language are also Erlang meaning that there's no potentially absurd impedance mismatch like you see with various ORM tools such as Torque or Ruby on Rails. You won't be mysteriously executing 500 queries to route a single phone call.

You can reconfigure it dynamically. Since it's meant for a highly available telecom environment, the idea is that you never turn it off. Erlang's Actors model helps it acheive fault tolerance.

Queries are built using list comprehensions and a more powerful form of Views are built out of logic variables.

You are able to bypass the transaction manager and access any data using only a lightweight dirty lock interface to make sure your reads aren't garbled. The authors recognize that sometimes it just doesn't matter if a little of your data is wrong and that you should be able to control when that might happen.

In practice, data in Mnesia is not usually normalized as many of the current applications that use it want to be able to get as much data as needed in a single query. Even with it's query optimizer and ability to sidestep the lock manager, many telecom apps still need to be able to get all of their data in a single query. How long do you usually wait for a telephone call to start ringing? 100 milliseconds? That's as long as some RDBMS take to optimize a single query let alone execute it and return the results.

Apparently quite a few applications within Ericsson and Nortel use Mnesia. It's open source along with the rest of Erlang.

If I have time to play with it, I'll post some example code. I'd like to see how well this election-free replication works.

# — 17 February, 2005