Database / Mnesia intermediate to advanced Interview questions
What is the difference between mnesia:transaction/1's built-in behavior and manual retry logic you might add?
mnesia:transaction/1 itself already retries internally in one specific, narrow case: if the
transaction is aborted purely because of a lock conflict that Mnesia's own internal deadlock resolution
detected as safely retryable, it can re-run the transaction function automatically without the caller seeing
an intermediate failure at all.
%% This may silently re-run Fun internally one or more times %% before returning a final {atomic, Result} or {aborted, Reason} mnesia:transaction(fun() -> mnesia:write(#counter{id = x, value = V + 1}) end).
What it does not do is retry for reasons outside its own lock-conflict handling — a node going
down mid-transaction, a majority-option write failing due to a partition, or a genuine application-level
exception inside your function all surface as a final {aborted, Reason} that your own code must
decide how to handle. The practical implication: don't assume every transient failure is already retried for
you; only the internal lock-conflict case is, and everything else needs your own retry strategy layered on
top if that's the behavior you want.
More Related questions...