Interview questions
What a consistency model is
1What is a consistency model, in one sentence?
A rule over histories: it says which sequences of observed reads and writes the system promises never to produce. It is a promise, not a mechanism.
Read moreNothing to point at
2How is snapshot isolation different from MVCC?
Snapshot isolation is a promise about what a transaction sees: a consistent snapshot, with conflicting writes rejected. MVCC, keeping several versions of each row, is one mechanism that can keep that promise.
Read moreNothing to point at
3Consistency is described by two separate hierarchies. What are they, and why must they not be merged?
Isolation levels describe many objects on one logical copy (how transactions interleave). Distributed consistency models describe one object on many copies (how recent a read is). They answer different questions: serializability promises nothing about recency, and linearizability promises nothing about atomic multi-object updates.
4A database is serializable, yet users see stale balances right after a transfer. How?
Serializability says nothing about real-time order: a transaction may be placed earlier in the serial order than it actually ran. And reads served from a lagging replica are stale on the other axis, recency, which serializability does not cover.
5Why does the cost of consistency not depend on data volume?
It depends on how many places can observe the data and how far apart they are. Adding one replica or one cache turns ordering, which was free locally, into a round trip.
Read moreThree things change completely
6Why can a node not detect consistency violations from the inside?
A violation is a property of the global history; every node's local view is legal on its own. Checking a history for linearizability is NP-complete in general, so tools such as Elle record histories from outside, infer a dependency graph and look for cycles.
Read moreThree things change completely
7What does it mean for a consistency model to compose, and which models do?
A model composes if, whenever each part satisfies it, the whole system does too. Linearizability composes. Serializability and sequential consistency do not: two serializable systems put together need not be serializable.
Read moreComposability decides architecture
8How do you estimate how often a consistency anomaly occurs?
By Little's Law: the number of operations exposed at any moment ≈ rate of conflicting operations × length of the window. With 667 conflicting operations per second and 20 ms of replication lag, about 13 are exposed at once. Shrink the window first.
Transactional isolation
9What are the three kinds of dependency between transactions, and which one is special?
Write–write (one overwrites the other's write), write–read (one reads the other's write) and read–write, or anti-dependency (one reads a value the other then overwrites). The read–write edge records data that did not flow between them, so to see it the engine must track reads, which is expensive.
Read moreThe three edge types
10In the dependency-graph view, what is an isolation level?
A set of forbidden cycle shapes in the graph of dependencies. Read Committed forbids cycles with no read–write edges; snapshot isolation forbids cycles with at most one; Repeatable Read forbids read–write cycles on single items; serializable forbids every cycle.
Read moreCounting gives the levels
11Is snapshot isolation stronger or weaker than Repeatable Read?
Neither: they are not ordered. Snapshot isolation forbids some predicate-based anomalies (phantoms) that Repeatable Read allows, and Repeatable Read forbids write skew, which snapshot isolation allows.
Read moreCounting gives the levels
12Why does Read Committed allow lost updates, and why is the problem worse when the logic is in application code?
Each statement sees a fresh snapshot, so a read, then a modify, then a write can overwrite a change made in between. The window is how long that sequence takes: 10–100 µs inside one SQL statement, but 1–100 ms when the read and write are separate calls from application code.
13Name three fixes for a lost update, cheapest first.
Make the operation commute (SET x = x - 1); check a version before writing (compare-and-swap); or lock the row while you work (SELECT … FOR UPDATE).
14What does Repeatable Read mean in PostgreSQL, in MySQL, and in the ANSI standard?
In PostgreSQL it is snapshot isolation. In MySQL's InnoDB it is a hybrid: plain reads use a snapshot, but writes and locking reads see the latest version. In the ANSI standard it allows phantoms. Same name, three different promises.
15What is write skew, and what is its general shape?
A transaction reads a set of rows, checks a rule over the set, then writes into it, while another does the same. Each writes a different row, so neither sees a conflict, and together they break the rule. It is a mismatch between conflict detection per row and an invariant over a set.
Read moreWrite skew: one generative shape
16How do you prevent write skew under snapshot isolation without switching to serializable?
Make the conflict concrete: have both transactions write one shared row, such as a counter or a guard row, so the write–write check catches it.
Read moreWrite skew: one generative shape
17What is the 'pivot', or dangerous structure, in serializable snapshot isolation?
A transaction with both an incoming and an outgoing read–write dependency. Every cycle that snapshot isolation allows contains two such edges in a row, so this pattern is necessary, though not sufficient, for a non-serializable history; aborting one transaction in it prevents all of them.
18Is Oracle's SERIALIZABLE level truly serializable?
No. It is snapshot isolation, which allows write skew.
Read moreSnapshot isolation
19Are read-only transactions always safe under snapshot isolation?
No. A read-only transaction can see a state no serial order would produce, and can complete a cycle that makes other transactions non-serializable. PostgreSQL offers READ ONLY DEFERRABLE, which waits for a snapshot that is safe.
Read moreSnapshot isolation
20Why is the ANSI scale of isolation levels considered broken?
Its wording is ambiguous, it omits dirty writes, it cannot express snapshot isolation, and its levels are not totally ordered. It was written with locking in mind, and then had to name multiversion products.
Distributed consistency
21What is the difference between a safety property and a liveness property, and which is eventual consistency?
A safety property ("nothing bad happens") is violated by some finite history, so a test can catch it. A liveness property ("something good eventually happens") is violated only by an infinite history, so no finite observation can refute it. Eventual consistency is a liveness property.
Read moreSafety and liveness
22Why is 'eventual consistency' nearly meaningless under continuous writes?
It promises convergence only if updates stop arriving, and under continuous load they never do. Ask for a bound instead: bounded staleness.
Read moreSafety and liveness
23What does r + w ≥ d say, and which consistency model does it apply to?
For sequential consistency, the time for a read plus the time for a write must be at least the one-way delay d between copies. You cannot have both local reads and local writes.
24What do the Attiya–Welch bounds say about linearizability, and what is the key intuition?
A linearizable read takes at least u / 4 and a write at least u / 2, where u is the spread (uncertainty) in message delay. You pay for not knowing how long a message will take, not for the delay itself.
25Given that read time plus write time is fixed, what are the four ways to spend it?
Read from the leader; read from followers that hold a lease or confirm the leader's position (read-index); read from a quorum and write back what you read (the ABD algorithm); or read and write locally, giving up the model.
Read moreFour ways to buy a fixed total
26Why does linearizability compose when sequential consistency does not?
Linearizability ties every object's order to the same real time, so the orders of different objects cannot disagree. Sequential consistency has no such anchor, so two per-object orders that are each valid can be impossible together.
27What is the strongest consistency model a system can offer while staying fully available?
Causal consistency, with convergent conflict handling (causal+). For transactions, causal consistency plus read atomicity is the ceiling.
28What weakness of causal consistency can no implementation fix?
It can order only the causality that passed through the system. A phone call between two users, or a second service, carries cause and effect the system never sees.
Read moreThe assumption it cannot verify
29Why is metadata the price of causal consistency?
Version vectors grow with the number of writers, and dependency lists grow with reads. Tracking coarsely creates false dependencies, which delay visibility; truncating the metadata creates false concurrency, which loses ordering.
Read moreThe price is metadata
Sessions, convergence and quorums
30How are session guarantees such as read-your-writes implemented, and why are they fragile?
By giving the client a token that only moves forward: a log position, a transaction ID, a session token or an ETag. The server serves a read only from a copy at least that recent. Any infrastructure change that drops the token, such as a load balancer or a retry path, voids the guarantee silently.
Read moreGive the client a tokenWhy session guarantees are uniquely dangerous
31What is consistent prefix reading, and what bug appears without it?
A reader only ever sees a prefix of the write order, never a later write without the earlier ones. Without it, a reply can appear before the message it answers.
Read moreConsistent prefix reads
32When is last-write-wins conflict resolution acceptable?
For snapshots of state whose real authority lives elsewhere, where any recent value will do. It is wrong for anything that accumulates, because clock skew decides which write survives, and the losing write disappears without an error.
Read moreArbitrate: pick a winner
33Why do CRDT merge functions have to be commutative, associative and idempotent?
Without coordination, nothing controls the order in which updates arrive or how many times each is delivered, so the result must not depend on either.
34What is the catch with tombstones in CRDTs?
Removing a tombstone safely requires knowing that every replica has seen the removal, which is global knowledge. Coordination leaves the write path, only to return in the garbage collector.
35In a quorum store, does R + W > N give strong consistency?
No. It gives only overlap: every read touches at least one replica that saw the latest write. You also need a way to pick the newest version and a write-back round; failed writes may still surface later; and sloppy quorums remove the overlap exactly when nodes fail.
Read moreTunable consistencySloppy quorums
CAP, availability and coordination
36State the CAP theorem precisely, in two sentences.
During a network partition, a system cannot provide both linearizability and total availability for a register. It says nothing about latency, or about normal operation.
Read moreCAP, stated precisely
37What does PACELC add to CAP?
The "else" branch: even without a partition, you still trade latency against consistency. That branch is the one running all the time.
38Why can snapshot isolation not be offered with high availability?
It must prevent lost updates, which means detecting two writers of the same item (first committer wins), and that needs communication between the places the writes happen.
Read moreHighly available transactions
39What is invariant confluence? Give two examples of invariants that have it and two that do not.
An invariant is invariant-confluent if merging any two valid states that diverged from a common one always gives a valid state; such invariants can be kept without coordination. Per-row checks and foreign keys under inserts only are confluent. Uniqueness and upper bounds such as "at most n" are not.
Read moreInvariant confluence
40What does the CALM theorem say, in one sentence?
A program has a consistent, coordination-free implementation if and only if it is monotone, so coordination is needed exactly at the steps that are not monotone, such as negation, deletion or "only if none".
Read moreCALM
41Why would a product need external consistency?
Because a second channel, such as a person, a queue or another service, can carry information faster than replication does. Real time is the only frame of reference that all channels share.