Prev Next

Database / Mnesia intermediate to advanced Interview questions

Why can a "hot" record or table become a bottleneck under heavy Mnesia write load?

Because Mnesia uses per-record (or sometimes per-table) locking inside transactions, any record that many concurrent transactions all need to write to becomes a serialization point: every transaction touching it has to wait its turn for the write lock, no matter how many CPU cores or schedulers are otherwise free. A single shared counter or a global "last updated" timestamp record are classic examples of accidental hot spots.

%% classic hot-spot pattern: every request updates the same record
mnesia:transaction(fun() ->
    [C] = mnesia:read({counter, global_hits}),
    mnesia:write(C#counter{value = C#counter.value + 1})
end).

As concurrency increases, throughput on that specific record plateaus (and transactions start piling up waiting on its lock) well before the rest of the system's capacity is exhausted, since the bottleneck isn't CPU or I/O — it's contention for one specific lock. This shows up as rising transaction latency and retries concentrated on operations touching that one hot record, even while the node's overall load looks otherwise unremarkable.

Why does a single frequently-updated record become a bottleneck under concurrency?
What symptom would you see from a hot record bottleneck?

Invest now in Acorns!!! 🚀 Join Acorns and get your $5 bonus!
Acorns Logo

Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!

Earn passively and while sleeping

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.

Robinhood Logo

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 Logo

Webull! Receive free stock by signing up using the link: Webull signup.

More Related questions...

What is the difference between mnesia:transaction/1 and mnesia:sync_transaction/1? What is the difference between async_dirty and sync_dirty activity contexts? How does mnesia:activity/4 let you customize the access context of an operation? What is table fragmentation in Mnesia and why would you use it? How do you configure a fragmented Mnesia table? Why does fragmentation help Mnesia scale beyond what one table replica set can handle? What is the difference between mnesia:match_object/1 and mnesia:select/2? What is mnesia:all_keys/1 used for? How do you integrate Mnesia with QLC for complex queries? Why would you use qlc:q with mnesia:table/1 instead of mnesia:select/2? What is a sticky lock in Mnesia and why does it improve performance? When can sticky locks cause a problem in a distributed Mnesia cluster? How do you dynamically add a new node to a running Mnesia cluster? What is mnesia:change_config(extra_db_nodes, Nodes) used for? How do you remove a table replica from a node without dropping the whole table? What is mnesia:del_table_copy/2 used for? How do you move a table copy from one node to another while the system stays live? What is mnesia:move_table_copy/3 used for? What is the {majority, true} table option and what tradeoff does it introduce? Why would you enable the majority option on a table prone to network partitions? What is a local_content table in Mnesia? When would you use a local_content table instead of a normal replicated table? What is mnesia:set_master_nodes/2 used for? How does setting master nodes influence conflict resolution after a network partition? What is mnesia_tm and what role does it play internally? How does Mnesia's transaction manager serialize concurrent transactions touching the same records? Why can a "hot" record or table become a bottleneck under heavy Mnesia write load? How can you redesign a schema to reduce lock contention on a frequently-updated record? What is mnesia:subscribe/1 used for? How do you react to table events using Mnesia's subscription mechanism? What is a nested Mnesia transaction and how does it behave differently from a top-level one? Why should nested transactions generally be avoided or used carefully in Mnesia? What is the dc_dump_limit configuration parameter used for? Why does tuning the transaction log dump frequency matter for write-heavy Mnesia workloads? How do you merge two previously-separate Mnesia clusters into one? What complications arise when merging schemas from two independently-created Mnesia databases? How does Mnesia decide which node's data wins during schema merge conflicts? What is the difference between a global lock and a per-record lock in Mnesia transactions? When would you use mnesia:read_lock_table/1 instead of relying on per-record locks? How do you profile and optimize Mnesia transaction throughput in a write-heavy system? Why is batching multiple related writes into a single transaction usually better than many small transactions? How does Mnesia's schema interact with OTP release upgrades (appup/relup)? What is the difference between mnesia:dirty_all_keys/1 and mnesia:all_keys/1? Explain the internal working of how Mnesia chooses which replica to read from in a load-balanced cluster? What is the where_to_read table_info item used for? What is mnesia:dump_log/0 used for? How do you handle a transaction that needs to retry after being aborted due to a deadlock? What is the difference between mnesia:transaction/1's built-in behavior and manual retry logic you might add?
Show more question and Answers...

Integration

Comments & Discussions