Database / Mnesia basics Interview questions
When should you use dirty operations instead of a transaction?
Dirty operations fit specifically when an operation genuinely stands alone — a single read or write that doesn't depend on any other operation succeeding alongside it, and where occasional inconsistency during a race or a node failure mid-write is acceptable for that particular piece of data.
Good candidates: a hit counter, a best-effort cache entry, telemetry data, or high-frequency writes to a table where losing or slightly misordering an entry under heavy concurrent load isn't a correctness problem. Poor candidates: anything involving multiple related writes (transferring a value between two records), anything where a stale read could cause a real bug (checking a balance before debiting it), or any table where replication consistency genuinely matters to correctness.
The deciding question is usually: "if this specific operation raced with another one, or half-completed on a crash, would that actually break something a user or another part of the system depends on?" If yes, use a transaction; if a shrug is the honest answer, dirty operations are a reasonable, faster choice.
More Related questions...