Q22 · When would you use distributed transactions vs eventual consistency?

Back to 24 Architecture Questions.

The question is not a technology pick. The axis it turns on: whether the business can operate on a state that is briefly inconsistent. Two-phase commit and eventual consistency are two answers to the same failure: a step fails after another committed. One refuses the intermediate state outright; the other accepts it and cleans up by policy.

All-or-nothing, or converge by policy In two-phase commit a coordinator holds locks on both services until commit. With eventual consistency the owner commits alone and the copies converge by applying events, accepting a briefly inconsistent window. FIGURE 22 ALL-OR-NOTHING, OR CONVERGE Two-Phase Commit Coordinator prepare then commit Service A locked Service B locked all-or-nothing; locks held across the wait Eventual Consistency Orders commits alone Billing Copy applies events Search Copy applies events commit now, converge by policy the business decides: can it sell a seat that is briefly double-held?

What the answer should contain

Know what a distributed transaction actually costs. Two-phase commit holds locks on every participant across network round-trips, makes the coordinator a failure domain, and turns one participant’s crash into everyone’s waiting. Throughput falls to the speed of the slowest, most locked participant. It is atomic, and the price is a system-wide pause on every failure.

Eventual consistency is not “no consistency”. It is a policy: the service that owns the fact commits alone, consumers converge, and the window of inconsistency is measured, bounded, and cleaned up by compensation where money is involved. The cost is designing cleanup instead of preventing the window: compensations, tokens that make a user’s next read see their own write, and a stated staleness tolerance per class.

The decision is the business’s, per invariant, not per system. “Can the order show before the charge confirms?” is a product question with a recorded answer. Most invariants tolerate seconds of ambiguity; the few that do not are usually money and stock, and they deserve a different pattern entirely.

For the invariants that cannot be briefly inconsistent, move the invariant, do not distribute it. The strongest pattern: give the fact one owner inside one service, where a plain local transaction holds it. Sell the seat atomically in one place, then converge everything else by events. Distributed transactions are usually the answer to an invariant that was allowed to span two services by accident, when it belonged to one owner.

The reservation pattern is the middle road. Reserve locally and atomically (one owner), confirm the rest asynchronously, release on timeout. The user-facing answer is correct at every instant; the distributed part is convergence, not correctness.

Ideas worth mentioning out loud

Follow-ups to expect

Red flags in an answer

Sources