Design a protocol for distributed transactions
I was asked this
No reports yet. Sign in to say where you were asked it.
A system design interview question asked in Google's first round (coding), last asked Sep 2025. It tests distributed transactions, fault tolerance and consistency.
An update must change data owned by several independent services or databases, so that either every change happens or none does. Design the coordination protocol. Compare two-phase commit, three-phase commit and sagas; for your design, specify the message flows, how failures and timeouts are handled, how idempotency is guaranteed, and what you can honestly promise about exactly-once versus at-least-once delivery.
Requirements
- Functional: begin a transaction spanning several participants, apply each participant's change, and finish with all committed or all undone; query a transaction's status.
- Non-functional: correct under crashes of the coordinator or any participant and under lost or duplicated messages; bounded time that resources stay locked; recovery after restarts without manual work.
Clarifying questions
- Are participants databases we control (that can prepare and hold locks), or independent services with their own APIs?
- Is strict atomicity required (money moving between accounts), or is eventual consistency with compensation acceptable (booking a trip)?
- How many participants per transaction, and what latency budget?
- Can a participant's step be undone, and is the undo always possible?
What a strong answer covers
- Two-phase commit: prepare (participants write their intent durably and vote), then commit or abort; the coordinator's durable decision log; why a participant that voted yes is blocked if the coordinator dies, and how a replicated coordinator (Paxos or Raft) removes that.
- Three-phase commit: the extra pre-commit phase that avoids blocking under crash failures only, why it breaks under network partitions, and why it is rarely used.
- Sagas: a sequence of local transactions, each with a compensating action; orchestration (a central workflow) versus choreography (events); compensations that must be idempotent and retryable; the lack of isolation and how semantic locks or pending states handle it.
- Idempotency everywhere: transaction ids and step ids, participants that store processed ids, and retries with backoff.
- Delivery semantics: the network gives at-least-once; exactly-once effects come from idempotent handlers plus deduplication, and the outbox pattern ties a local write to its outgoing message.
- Timeouts and recovery: who decides after a timeout, how in-doubt transactions are resolved on restart, and alerting on transactions stuck in prepared.
- A clear choice: 2PC inside one trust domain with short transactions; sagas across services.
Follow-ups
- A compensation fails permanently (the refund API rejects). What now?
- How does a database like Spanner make distributed transactions fast?
- Walk through the exact messages when the coordinator crashes after sending commit to only one participant.
Where it's asked
- Google · First round: coding · Last asked Sep 202545 min · Coding in a Google Doc, no syntax highlighting or autocomplete · No AI
What it tests
distributed transactions · fault tolerance · consistency
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
