Database / Mnesia intermediate to advanced Interview questions
How does Mnesia's transaction manager serialize concurrent transactions touching the same records?
Mnesia uses pessimistic locking rather than optimistic concurrency control: when a transaction reads or
writes a record, mnesia_tm acquires the appropriate lock (read or write) on that record before
proceeding, and a conflicting lock request from another concurrent transaction simply has to wait until the
first transaction releases it at commit or abort.
sequenceDiagram
participant T1
participant T2
participant TM as mnesia_tm
T1->>TM: request write lock on Key
TM-->>T1: granted
T2->>TM: request write lock on Key
Note over TM: T2 blocks, waiting
T1->>TM: commit, release lock
TM-->>T2: lock granted, T2 proceeds
This guarantees serializability for conflicting operations without needing to detect and retry after the
fact the way optimistic approaches do — the cost is that a transaction can block waiting on a lock held
by another, which is exactly the scenario that can escalate into a deadlock if two transactions each hold a
lock the other is waiting for, something mnesia_tm detects and resolves by aborting one of them.
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...
