Choosing Consistency and Availability in Distributed System Interviews
Start consistency choices from user-visible invariants.
How to answer consistency and availability questions in a system design interview: start from what users must never see, choose per operation, and say what happens during a partition.
At a glance
- Start with the invariant ("a coupon is redeemed once", "a user sees their own update"), not with a label such as "CP" or "AP".
- CAP is about partitions: while the network is split, a system cannot guarantee that reads and writes of a shared, changing value are both linearizable and answered by every node that is still running.
- Choose per operation. A product page can serve stale data while stock reservation needs one authoritative decision.
- Name the model you mean: linearizable, serializable, read-your-writes, monotonic reads, bounded staleness or eventual.
R + W > Nis not a protocol. Overlapping quorums still need rules for ordering writes, finishing partial ones and changing leaders.- A timeout does not prove a write failed. Retries need idempotency and a way to look up the status.
Name the guarantee
| Guarantee | What it promises | Typical use |
|---|---|---|
| Linearizable | every operation takes effect at one instant between its start and its end; a read that starts after a write finished sees that write or a later one | locks, unique usernames, the last item in stock |
| Serializable | transactions behave as if run one at a time (not necessarily in real-time order) | multi-row business rules |
| Read-your-writes | a session sees its own writes | profile edits, shopping carts |
| Monotonic reads | a session never sees older data after newer | feeds, dashboards |
| Bounded staleness | reads lag by at most a stated time or number of versions | reports, prices with a known delay |
| Eventual | replicas converge once updates stop and get through | likes, view counts, caches |
Availability in CAP means every request to a running node completes its contract. That is not the same as an uptime target, a 250 ms deadline or a 99.9% success rate: say which one you mean.
Choose partition behavior per operation
| Operation | Invariant | During a partition |
|---|---|---|
| Reserve the last item in stock | never sell more than the stock | route to the item's single owner, or use stock pre-allocated per region; otherwise answer "retry" or "pending" |
| Read a product description | none critical | serve the local, possibly stale copy |
| Post to a timeline | an acknowledged post is kept | acknowledge after a durable write in the local region, replicate later; late or out-of-order display elsewhere is acceptable |
| Block another user | a protected read after the block must not be allowed | ask the authority, and fail closed if it cannot be reached |
| Add to a cart in two regions | both additions survive | merge per item, not "last write wins" on the whole cart |
Replication between regions is usually asynchronous, so a region lost before it replicates can take its newest writes with it. If no acknowledged write may ever be lost, wait for a second region before acknowledging, and accept the extra latency.
A quorum is not a protocol
Three replicas, writes acknowledged by two, reads that ask two and return the newest tag:
var replicas = new Dictionary<char, (int Tag, string Value)>
{
['A'] = (1, "blue"), ['B'] = (1, "blue"), ['C'] = (0, "white"), // write 1 acknowledged by A and B
};
replicas['B'] = (2, "green"); // write 2 reached B only, then its writer stalled
string Read(params char[] quorum) => quorum.Select(r => replicas[r]).MaxBy(v => v.Tag).Value;
Console.WriteLine($"N = 3, W = 2, R = 2, so R + W > N: {2 + 2 > 3}");
Console.WriteLine($"read X from B and C: {Read('B', 'C')}");
Console.WriteLine($"a later read Y from A and C: {Read('A', 'C')}");N = 3, W = 2, R = 2, so R + W > N: True read X from B and C: green a later read Y from A and C: blue
- Every read set overlaps every acknowledged write set, yet the second read went back in time. That is not linearizable.
- The fix is a protocol, not the arithmetic. In a classic atomic register, writers use unique, increasing tags and write to a quorum, and a read writes the newest value it saw back to a quorum before returning. A consensus-backed leader that orders all writes is another way.
- Changing the replica set safely needs its own rules too.
The last item in stock
- Even linearizable reads and writes do not stop two buyers from both reading "stock = 1". Make the check and the change one atomic operation: reserve-if-positive, as a conditional update or transaction.
- A client that times out retries with the same idempotency key. If the first attempt committed, the retry returns that reservation; if it did not, the retry makes it. Record the key in the same transaction as the reservation, so there is never a second one.
- With pre-allocated stock, East may sell its 3 units while West still has 2. Never hand West's units to East just because West timed out.
Eventual consistency still needs rules
- Decide how conflicts merge. Last-write-wins on a whole record can drop a valid update; clocks can be skewed.
- Expect duplicate and reordered delivery; make updates idempotent.
- Version vectors detect concurrent versions; they do not pick the business winner.
- Recovery is proven by applied positions and resolved conflicts, not by an empty queue.
Common mistakes
- "CP for money, AP for social": label operations and invariants instead of whole domains.
- "CAP means pick any two": a real network can partition, so the choice appears during partitions.
- "Eventual means no consistency": it promises convergence under stated conditions, and you still owe merge rules.
- "Quorums guarantee consistency": overlap is necessary but not enough; the protocol must order writes, finish partial ones and change membership safely.
- "Return success and reconcile later" when the harm cannot be taken back: a leaked private post cannot be unseen, and a refunded double charge was still a double charge.
- Treating a timeout as a failure: the write may have committed. Look up its status before retrying with a new request.
In an interview
What does CAP actually say? During a network partition, a system cannot guarantee that operations on shared, changing data are both linearizable and answered by every running node. Outside partitions, the trade-off is mostly between latency and consistency.
How do you choose a consistency level? Per operation, from what users must never observe: strong for decisions such as the last item in stock, weaker levels where stale data does no harm.
What is read-your-writes, and how is it provided? A session always sees its own writes. A session token or version travels with the client, and a replica that has not caught up waits, redirects or refuses.
Is R + W > N enough for strong consistency? No. The quorums overlap, but without rules for ordering writes and finishing partial ones, and for leader or membership changes, a later read can still return older data.
How do you avoid overselling during a partition? Give each item one authoritative owner, or pre-allocate stock per region, and make reserve-if-positive atomic. Without authority, answer "retry" instead of confirming.
What is wrong with last-write-wins? Concurrent updates can silently overwrite each other, and skewed clocks can pick the wrong winner. Use per-field or per-item merges, or domain rules.
Check yourself
During a partition, one region cannot reach the authority for stock reservations. What should a checkout there do?
Show answer
Correct answer: B
Confirming without authority can oversell; fixing that later means cancelling an order the customer was told is confirmed.
Option A: Reconciling later turns an oversold order into a cancellation and a refund: the promise is already broken.
Option C: The local copy may be stale or shared with other regions.
Option D: Neither the customer nor the retry logic learns what happened.
A system uses N = 3, W = 2 and R = 2, and a read simply returns the newest tag it sees, with no write-back. What is still possible?
Show answer
Correct answer: B
A write that reached only one replica can be seen by one read and missed by the next.
Option A: Overlap alone does not order partial writes.
Option C: An acknowledged write survives on the other replica in this model.
Option D: R = 2 means two replicas answer each read.
A user edits their profile in one region, is routed to another, and sees the old profile. Which promise is broken, if it was made across regions?
Show answer
Correct answer: A
The session did not see its own write.
Option B: The regions may still converge later; eventual consistency allows the stale read.
Option C: Serializability is about transactions, not a session's view.
Option D: The request was answered, so it was available.
Sources
- Consistency levels in Azure Cosmos DB: strong, bounded staleness, session, consistent prefix and eventual, with PACELC.
- Leader Election pattern: one coordinator to avoid conflicts.
- Compensating Transaction pattern: undoing steps of an eventually consistent operation, and its limits.
- Regions and availability zones: asynchronous replication between regions can lose recent data in a region-wide outage.
- The formal proof of the CAP theorem (2002): the precise meaning of consistent, available and partition-tolerant.
TechInterviewNotes Editorial Team · Updated 28 Nov 2026 ·