Database / Mnesia basics Interview questions
Explain the lifecycle of a Mnesia transaction from start to commit?
Calling mnesia:transaction(Fun) kicks off a well-defined sequence: Mnesia runs your function,
tracking every read and write it performs, acquiring the appropriate locks as it goes, before deciding whether
the whole thing can be committed.
flowchart TD
A[mnesia:transaction Fun called] --> B[Fun executes: reads take read locks, writes take write locks]
B --> C{Fun completes without exception?}
C -->|Yes| D[Two-phase commit across all replicas of touched tables]
D --> E{All replicas prepared successfully?}
E -->|Yes| F["{atomic, Result} returned; locks released"]
E -->|No| G["{aborted, Reason} returned; no changes applied"]
C -->|No, exception raised| G
If the function runs to completion without an exception, Mnesia attempts to commit — for a replicated
table, this means the two-phase prepare/commit exchange across every node holding a copy. Only if every
involved replica confirms it can commit does the transaction actually take effect everywhere, returning
{atomic, Result}; any failure along the way aborts the whole thing, applying no changes and
returning {aborted, Reason} instead.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
