Database / Mnesia intermediate to advanced Interview questions
Explain the internal working of how Mnesia chooses which replica to read from in a load-balanced cluster?
For a table replicated across multiple nodes, Mnesia tracks a per-table where_to_read
preference — by default, favoring reading from the local node's own copy if it holds one, since a local
read avoids any network round-trip entirely.
flowchart TD
A[Read request for Table] --> B{Does this node hold a local copy?}
B -->|Yes| C[Read directly from local copy - no network round-trip]
B -->|No| D[Route read to another node's replica per where_to_read]
If the local node doesn't hold a copy of that table at all, Mnesia routes the read to whichever remote node
is currently designated to serve it, tracked internally and adjustable via
mnesia:table_info(Table, where_to_read) to inspect, or influenced by sticky lock behavior for
writes. This local-first preference is exactly why replicating a hot, read-heavy table onto every node that
actually queries it can meaningfully cut read latency, compared to a setup where most reads have to cross the
network to reach a node that holds a copy.
More Related questions...