Databases & Transactions interview question · Most asked
How do you keep data consistent across services without distributed transactions?
Summary
Use the saga pattern: a sequence of local transactions where each step publishes an event or command, and failures trigger compensating actions (refund, release inventory). Combine with the transactional outbox to publish events reliably and idempotent consumers.
Longer Answer
Two-phase commit (2PC) across services is rarely used because it couples availability and blocks on coordinator failures. Sagas can be choreographed (events) or orchestrated (a coordinator such as Temporal or Step Functions).
Key Points
- Sagas with compensations
- Outbox for reliable events
- Idempotent consumers
- Avoid 2PC across services
More most-asked Databases & Transactions questions
- What does ACID mean?
- Explain transaction isolation levels and the anomalies they prevent.
- How do database indexes work and when do they help or hurt?
- What is the N+1 query problem and how do you fix it?
- How do you choose between SQL and NoSQL databases?
- What is connection pooling and how do you size a pool?
- How do you run schema migrations without downtime?