Erlang / Erlang Basics Interview questions
When would you choose Mnesia over ETS?
Reach for Mnesia when data needs to survive beyond a single node, or beyond a single BEAM restart, or must be updated as part of a transaction spanning multiple tables. Reach for plain ETS when the data is node-local, disposable if the node restarts, and speed matters more than durability or cross-node consistency.
| ETS | Mnesia |
| In-memory only, single node. | Optional disk persistence, replicated across cluster nodes. |
| No built-in transactions across keys/tables. | ACID-style transactions across multiple tables. |
| Slightly lower overhead per operation. | Extra overhead for transaction coordination and replication. |
A common pattern is actually using both: ETS as a fast local cache in front of Mnesia's authoritative, replicated copy, refreshing the cache when the underlying data changes.
More Related questions...