The interview problem

Practice prompt

Two operators can independently disable service replicas, but at least one replica must remain enabled. Show how snapshot reads can violate that rule.

Original practice, not a reported company interview. Scenarios and numbers are illustrative. Interview date: not applicable. Sources retrieved October 1, 2026.

1. Scope and worked approach

Assume two replica rows start enabled and transactions update different rows. Each transaction reads both, sees another enabled replica and disables its own. Under snapshot isolation, disjoint writes may both commit. Protect the invariant with a shared guard-row lock, a database-supported constraint representation, or serializable transactions with whole-transaction retry. All write paths must participate.

2. Trace the design or derivation

Read invariant under protection
  → decide
  → update
  → commit or retry decision

Keep external side effects outside a transaction that may retry, or make them idempotent through an outbox. Otherwise a failed serialization attempt can still notify an operator that a replica was disabled. Test the invariant at every committed state rather than relying on the absence of lost updates.

3. Calculate the example

Starting states are A=1 and B=1. Transaction T1 sees B=1 and writes A=0; T2 sees A=1 and writes B=0. The final sum is zero even though neither overwrote the other's row. A serial execution would reject the second disable.

4. Failure cases and trade-offs

Row version checks on only the modified row do not protect the read predicate. Serializable failures require retrying the decision, not merely the last update. A guard row is easy to reason about but can serialize unrelated work unless its scope matches the invariant.

5. Validation, follow-ups and self-review

Reproduce concurrent disjoint updates with a barrier after reads. Follow-up: what changes when replicas are inserted or deleted? Self-review: show the anomalous history and name the common coordination point.

Sources and related practice

Technical reference: www.postgresql.org — Snapshot isolation anomalies and serializable transaction retries.

Source publication/update: Not established. Retrieved October 1, 2026. The workflow, calculations and review exercises are original; this reference is not evidence that a company asked this question.

Continue with Design a cross-shard transaction coordinator; Prevent lost edits with conditional HTTP updates.

Continue your preparation

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