The interview problem

Practice prompt

A SaaS platform transfers ten capacity units from one project to another. Projects live on different database shards. Design a coordinator that commits both updates or aborts both, survives retries and coordinator crashes, and reports an honest result when a participant is unreachable. Explain the difference between atomic outcome and what concurrent readers can observe.

Original system-design practice, not a reported company interview. Workload numbers and failure timelines are hypothetical. Technical references retrieved September 27, 2026.

1. Separate three guarantees

Project A begins with 40 units and B with 20. A successful transfer produces 30 and 30; an aborted transfer leaves 40 and 20. The total remains 60, and no project may become negative. Retries of the same operation must not transfer another ten units.

Atomic outcome means participants cannot choose conflicting final decisions. Isolation governs interference with concurrent operations and reads. Durability specifies which failures may occur without losing acknowledged data. Two-phase commit addresses coordinated outcome; it does not automatically provide a globally consistent snapshot or protect every business invariant.

Assume all participating shards support durable preparation, controlled commit/abort and recovery. Their replication preserves prepared and committed state across supported failovers. External email, billing APIs and arbitrary HTTP callbacks are outside this transaction. Restrict the first version to a known participant set in one region and document quorum-loss unavailability.

2. Give every decision an authoritative home

Use an authenticated transfer API, a coordinator service backed by a replicated decision store, and a participant adapter on each shard. The API accepts a tenant-scoped operation key and payload hash. Reusing the key with different projects or units is an error; matching retries retrieve the existing transaction identity and status.

Before sending any prepare request, durably register the transaction ID, immutable participant set, payload hash and ownership epoch. Store a state machine with undecided, commit-decided and abort-decided states; the last two are terminal. An atomic, quorum-backed conditional transition chooses exactly one terminal decision. A process-local flag or asynchronously replicated cache is insufficient.

Participants persist their local transaction identity and state. Couple a committed outcome marker to the local data commit, and retain terminal outcomes so a duplicate decision returns the existing result. A missing prepared record alone cannot distinguish already committed from aborted or never prepared. Prepare and decision messages are authenticated and bound to the registered transaction. A stale coordinator cannot invent a decision: participants must verify an authoritative terminal decision, or a verifiable equivalent, before resolving prepared state. Fence coordinator ownership changes and serialize local prepare, commit and abort handling so reordered messages cannot resurrect an aborted transaction.

3. Trace the ordinary transfer

The coordinator asks A and B to execute their local updates and prepare. A locks its capacity row, checks at least ten units remain and stages subtraction. B locks its row and stages addition. Each participant records recoverable prepared state before voting yes. An inability to prepare is a no vote; local resources can be released on a definitive local abort before a yes vote.

Only after every registered participant votes yes does the coordinator attempt the durable commit decision. Any no vote causes an abort decision. A timeout while the decision remains undecided may also trigger a conditional abort transition; it cannot overwrite an existing commit. Once commit is recorded, failed delivery means retrying commit, never switching to abort.

The coordinator sends the chosen decision until every participant acknowledges resolution. For a simple API contract, return completed only after all acknowledgments. Before then, expose pending or commit-decided/applying as appropriate. A client timeout is not evidence of failure; querying or retrying the same operation key returns its evolving status.

4. Work through two different crashes

Crash before a decision: transaction T is registered with A and B. A durably prepares and votes yes. The coordinator crashes before receiving B's response. A remains prepared. A recovery worker obtains current ownership and performs an authoritative read: T is still undecided. It conditionally records abort and sends abort to both participants. Even if B had prepared while its response was lost, it can safely follow that abort.

The safety comes from recording one durable decision, not from guessing B's state. If a competing worker had already committed, the abort transition fails and recovery delivers commit instead. If the decision store cannot provide a current authoritative result, the worker cannot conclude that no commit exists.

Crash after a decision: both participants prepare, the decision store records commit, A commits, and the coordinator crashes before notifying B. B must eventually commit. Aborting B after a local timeout would leave A at 30 and B at 20, losing ten units. Recovery resends the durable commit and deduplicates acknowledgments.

A prepared participant therefore cannot unilaterally roll back merely because its timeout expired. Replicating the coordinator improves recovery from individual failures, but losing access to the relevant quorums can still stall progress. Safety during that outage comes with blocked work.

5. Specify visibility and concurrency separately

While A has applied commit and B has not, independent shard reads can return A = 30 and B = 20. Atomic final outcome alone does not prevent this mixed observation. Even after both apply, reads taken at unrelated times can span other transfers.

If clients require a consistent total, route such reads through a database or protocol offering an appropriate global snapshot, or design a coordinated read transaction with suitable locking and ordering. Merely waiting for T to finish does not synchronize arbitrary future reads. If the product instead exposes transfer status plus independently refreshed balances, state that weaker read contract explicitly.

Acquire project locks in a global order to reduce distributed deadlocks, including across shard boundaries. A central ordering rule must govern actual acquisition, not just the order of IDs in a payload. Before preparation, cancellation can unwind a transaction; after preparation, release requires its coordinated decision. Keep unrelated remote calls and user interaction out of lock-holding work; the necessary prepare and decision exchanges still occur while locks are retained.

6. Calculate coordination and outage costs

Assume 5,000 transfers per second and two participants each. Ignoring retries, registration, replication traffic and transaction execution, prepare request/reply plus decision request/ack uses four participant messages each, or eight per transfer: 40,000 messages per second.

If each participant remains prepared for a mean of 40 milliseconds in a stable system, Little's law gives 10,000 participant preparations/s × 0.040 s = 400 prepared participant records on average. If both participants' prepared intervals coincide, that corresponds to 200 transactions; otherwise use the actual per-transaction interval to count distinct unresolved transactions. This is an average, not a safe capacity limit; skewed hot projects can block at far lower aggregate load.

For a conservative outage thought experiment, suppose all new transactions continue preparing but none can resolve for 30 seconds. That adds 150,000 transactions and 300,000 participant records. At 2 KB of coordinator metadata per transaction, the new metadata alone is 300 MB before replication; locked application rows, logs and indexes add separate costs.

Apply admission control when unresolved count, oldest prepared age or lock waits exceed budgets. Stop new cross-shard work rather than allowing an unbounded queue. Reserve recovery capacity so retries can drain existing work even while new requests are rejected. Load-test long-tail preparation duration and hot-key contention, not only average throughput.

7. Make recovery and retention part of the design

Run a reconciler that compares coordinator decisions with participant prepared records and retries unresolved outcomes. An absent transaction in a stale replica is not proof of abort. Preserve decision and idempotency records until every participant is resolved and the documented retry/replay horizon has passed; expired operation keys must not silently become new transfers.

Restore coordinator and shard backups with a recovery plan that preserves decision history. Independently rewinding one participant can erase a committed update or revive prepared work. Keep affected operations unavailable until authoritative outcomes and participant state are reconciled; manual heuristic resolution is an exceptional integrity event, not ordinary timeout handling.

Prefer co-locating related projects when practical, or use an established database with the required distributed transaction and isolation contract. A saga can be appropriate when temporary intermediate states and compensating actions are acceptable, but compensation is a new business action and can itself fail. It does not supply this prompt's atomic-outcome contract.

8. Failure tests and self-review

Inject lost yes votes, duplicate commit messages, a coordinator crash before and after its decision, participant restart while prepared, an old leader returning, and a retry with changed payload. Verify one final decision, no duplicate transfer and no negative source capacity. Separately test cross-shard reads; outcome tests do not prove snapshot isolation.

Follow-ups: Can an undecided transaction be aborted even if everyone already prepared? What proves an old coordinator cannot commit afterward? When may decision records be collected? Why does a participant quorum outage still matter with a healthy coordinator?

Score 0–2 each for the transaction identity and state machine, durable prepare/decision ordering, crash recovery, visibility/isolation contract, and bounded operational recovery. Full marks require explaining what blocks and why.

Sources and next steps

The capacity-transfer protocol, API contract, crash traces and workload calculations are original design exercises. See payment ledger for domain-specific accounting invariants and distributed locks for fencing.

Continue your preparation

Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.