Database / Mnesia basics Interview questions
Why should Mnesia operations generally run inside a transaction?
Wrapping reads and writes in mnesia:transaction/1 gives you the same guarantee a relational
database transaction gives you: either every operation in the block succeeds, or none of them take effect, even
if the table is replicated across several nodes. Without that, a partial failure mid-sequence (a crash, a
conflict with another writer) could leave related data in an inconsistent state — one write applied,
another not.
Transactions also handle locking automatically: reads take read locks and writes take write locks as needed, so concurrent transactions touching overlapping data are serialized safely rather than racing each other. This is exactly why the transactional API is the default recommendation, reserving dirty operations for the narrower case where speed matters more than these guarantees and the operation genuinely stands alone.
More Related questions...