Concept lesson · Foundations
Consistency models
Start here
Definition
A consistency model defines when a write becomes visible to readers and which order of operations they may observe. CAP consistency is one specific model, linearizability: after a write completes, a read that starts later must return it or a newer write. Other models, such as causal and eventual consistency, make different promises. ACID consistency instead concerns preserving database and application rules.
Why it matters: Replicas and caches may receive an update at different times. The application needs a precise rule for which old or reordered results are acceptable.
Consistency models constrain observations. Compare a real-time guarantee, a session guarantee, and eventual convergence.
Read the diagram step by step
- Client A writes v11 and receives an acknowledgement before the shown read begins.
- A linearizable read must return v11 or a later write in the agreed order.
- Read-your-writes requires later reads in client A’s session to see v11 or a later version, but client B may still read v10.
- Eventual consistency permits stale reads during propagation and promises convergence under its stated conditions, not a fixed delay.
Worked example
Notebook N7 starts at version 10. Client A saves version 11, then client B reads. Linearizability requires version 11 or a later write; eventual consistency can temporarily return version 10.
Key takeaways
- Linearizability respects the real-time order of completed operations.
- Causal and session guarantees preserve dependencies or one client’s history.
- Eventual convergence does not provide a freshness deadline.
You will learn to
- Distinguish real-time order, process order, causal order, and eventual convergence using concrete traces.
- Design read-your-writes and monotonic reads across replicas without promising global freshness.
- Choose separate consistency contracts for an authoritative update and a replicated user interface.
Practice in this chapter
9 interview questions with model answers and follow-ups.
Go to interview practiceUseful foundations: Replication and durability · CAP theorem: consistency, availability, and partition tolerance
Workload and timing examples are interview assumptions.
Dotted concept links open the relevant explanation in a new tab.
01Consistency model: definition and example
Consistency has different meanings in different contexts. The familiar CAP definition is that clients observe one up-to-date copy: after a write completes, a later read must return it or a newer write. This is linearizability. A consistency model is the broader term for the rules governing when writes become visible and how operations may be ordered.
| Term | Standard meaning | Quick test |
|---|---|---|
| CAP consistency | Linearizability: operations behave as if there were one copy, respecting real-time order | Write v11 succeeds; a read starting afterward must return v11 or a newer write |
| Consistency model | The rules governing visibility and ordering; linearizable, sequential, causal and eventual consistency are different models | Which old values or orderings may this read observe? |
| ACID consistency | A correct transaction preserves database and application rules, taking valid state to valid state | Does the purchase preserve the rule that stock cannot become negative? |
One example, two models: a record contains v10. Client A writes v11 and receives success. Client B then reads through another server, with no further writes.
- Linearizability: a successful read must return v11. If the server cannot establish the current value, it must coordinate, wait or refuse rather than return stale v10.
- Eventual consistency: the read may temporarily return v10. Once updates stop and propagation and reconciliation succeed under the system’s assumptions, reads converge on the settled value; the model alone gives no freshness deadline.
“Strong consistency” commonly refers to linearizability in interviews, but ask for the exact model and operation scope. “All clients see the same data” is shorthand for the observable single-copy behavior, not a requirement that every physical replica update simultaneously. The linearizability section explains overlapping operations.
Interview memory aid: CAP consistency asks “Do readers see the current value?”; a consistency model asks “What may readers observe?”; ACID consistency asks “Do the rules still hold?”
Define the scope before choosing a guarantee: one object, one session, or a multi-object operation. The bounded histories below use record N7, version 10 (“Trip”), followed by version 11 (“Autumn trip”). Client A writes the update; client B can read through a different replica in East or West. A history is the sequence of observed reads and writes. The timestamps and versions are illustrative, not measurements.
With a single process, an ordinary write followed by a read can access the same in-memory value. Replicas, caches, and concurrent clients break that intuition: the write can finish at East while West still has version 10. Before drawing servers, finish this sentence: “After this operation succeeds, these readers must be able to observe this state.” Specify whether the promise concerns one key, a session, or several keys together.
- 1 → 2commitClient A writes title v11 → East stores v11
- 2 → 3replyEast stores v11 → Client A receives token 11
- 3 → 4read with minimum 11Client A receives token 11 → West has v10
- 4 → 510 is too oldWest has v10 → Wait or route to v11
- 5 → 6satisfy sessionWait or route to v11 → Client A reads v11
02Linearizability: real-time operation order
Plain-language definition: after a write completes, any read that starts later must return that write or a newer write. Clients observe one up-to-date copy of the object. This is the consistency guarantee used by CAP.
Formal definition: operations can be placed in one valid order, respecting real time, as though each took effect at one instant between its start and finish. This also defines what is allowed when operations overlap; the simple completed-write/later-read example below is one consequence. Herlihy and Wing’s original definition is the source of this formulation.
Apply these tests:
- Respect completed operations. If client A’s title write finishes before client B starts a title read, client B must see that write or a later write in the object’s valid history.
- Use the actual history. There are no intervening writes in this example, so the answer must be version 11.
| Time | Notebook operation | Required result under linearizability |
|---|---|---|
| 10:00:00–10:00:01 | client A writes title v11 at East | Success at 10:00:01 |
| 10:00:02 | client B begins reading at West | Return v11; do not return v10 |
| 10:00:03 | West still lacks v11 | Coordinate, route, or fail to complete successfully |
Two limits to remember:
- Overlapping operations can have either valid order. A read beginning at 10:00:00.5 can legally return v10 if its conceptual instant precedes the write’s instant. “Latest” is ambiguous during overlap; use the operation intervals.
- Separate calls do not become one atomic action. A linearizable title register does not make a read-title/write-title pair atomic. Use conditional updates or transactions to prevent that race.
Do not confuse ordering individual operations with grouping several operations atomically:
| Contract | Unit being ordered | What it does not add by itself |
|---|---|---|
| Linearizability | One object operation, respecting real time | A separate read-then-write pair is not one atomic operation |
| Serializability | Whole transactions, equivalent to a serial execution | Real-time order is not required by the definition alone |
| Strict serializability | Whole transactions, also respecting real time | External API calls are not automatically participants |
03Sequential consistency: one order preserving each client
Now let client A write v11 and then read v10, with no other title write. This cannot be explained while preserving client A’s own operation order, so it violates sequential consistency too. The distinction is not “some replicas are usually slow”; it is a precise restriction on the histories clients may observe.
A consistent total order can be useful for reasoning, but sequential consistency alone gives client B no wall-clock freshness bound. Application messages outside the modeled interface also need careful treatment: if client A tells client B that the save finished through a separate channel, that real-world expectation is not automatically enforced by a model that only orders notebook operations.
04Causal consistency: dependent writes stay ordered
The preceding models ask whether operations fit one common order. Causal consistency instead preserves the order of operations that depend on one another, while allowing unrelated writes to be seen in different orders. In a discussion thread, the useful relationship is that a reply depends on the comment its author read.
Rule: A cause precedes its dependent effect. Program order, reading a value and acting on it, and chains of these relationships create causal dependencies.
Trace the dependency:
- Create the parent. Client A writes comment C41, “Train at six.”
- Observe and reply. Client B reads C41 and writes C42, “I will be there.”
- Enforce visibility. A causal view exposing C42 must include its dependency C41. Otherwise the reply arrives without the information that explains it.
An implementation can attach dependency identifiers to C42 and delay its visibility at West until C41 is available. A timestamp alone does not fetch a missing dependency. The service must track and enforce the relevant relationships, including dependencies carried when a client changes servers.
Two independent comments, C43 from client A and C44 from client B, can be concurrent: neither author saw the other. Causal consistency does not require every reader to see those independent writes in the same order. If concurrent updates change the same title, conflict handling remains necessary. A deterministic winner converges, but may discard an edit; preserving alternatives or merging application operations gives a different product behavior.
Causal visibility describes applied history, not a requirement to display every earlier value forever. A later authorized deletion can replace a parent comment with a tombstone; the replica must still account for the dependency. Nor does causality make a multi-object update atomic: exposing half a transfer requires a transaction or an additional atomic-visibility protocol to prevent it.
05Session guarantees: read-your-writes and monotonic reads
A session is the scope over which the service remembers one client’s observations. Read-your-writes means client A’s later reads incorporate its completed writes. Monotonic reads mean that after it has observed a version, later reads do not retreat to an earlier state along that history. Neither alone requires every other user to see the globally newest value.
One implementation carries a session token describing the minimum history the next server must include. A replica’s applied position records how far it has incorporated that history into readable state. If its position is behind the token, the service waits, routes to a sufficiently current replica, or refuses the read; merely sending the token does not make the replica catch up.
| Guarantee | Notebook trace it prevents | Possible mechanism |
|---|---|---|
| Read-your-writes | client A saves v11, reloads and sees v10 | Carry a minimum applied-position token |
| Monotonic reads | client A sees client B’s v12, then sees v11 | Advance its token after reads too |
| Monotonic writes | client A’s second edit is applied before its first | Preserve client A’s write order |
| Writes-follow-reads | client B’s reply becomes visible without C41 | Record and enforce the read dependency |
The diagram follows a single ordered title history, where one number can identify how far the replica has applied that history. Multiple independently written objects may need a richer dependency representation. Pinning client A to East is simple but failover breaks the guarantee unless the new replica catches up or the request waits. A token must represent a real storage guarantee, not an arbitrary browser counter.
06Eventual consistency and bounded staleness
Eventual consistency promises convergence once updates stop and the system can exchange the necessary information under its recovery assumptions. East and West may temporarily disagree about N7. This does not promise that every replica converges within two seconds, nor does it by itself prevent client A from seeing v11 and then v10.
Bounded staleness adds a limit
These choices are not one universal ranking. Session guarantees concern a client’s continuity, causal consistency concerns dependencies, and a staleness bound concerns distance from a defined reference. State which promises are combined. For notebook search results we may tolerate delayed convergence, while the edit screen combines read-your-writes with monotonic reads. Both can coexist with a stricter ownership service.
Convergence is a promise about the eventual result; an implementation still needs a rule for reconciling updates accepted independently. Some data types can merge both contributions, while other designs choose one winning value and discard the alternative. CRDTs and last-write-wins illustrate these different conflict-handling choices.
CRDT: merge the same state without double counting
Conflict-free replicated data types (CRDTs) use defined update/merge rules so replicas that receive the same updates converge. For a state-based grow-only counter:
- Keep local components. Each replica increments only its own counter entry. In the pair (A-count, B-count), A changes the first entry and B changes the second.
- Merge by maximum. Take the maximum per component: A=(2,0) and B=(0,3) merge to (2,3).
- Read by addition. Sum the components: 2 + 3 = 5. Repeating the merge does not count the increments twice.
For state-based CRDTs, merge must be associative (grouping merges differently gives the same result), commutative (merging A with B gives the same result as B with A), and idempotent (merging the same state again changes nothing). Updates must also obey the type’s rules. Operation-based variants have their own delivery requirements.
Last-write-wins chooses a winner
Interview check: Does a converged counter prove inventory was never oversold? No. Convergence of replicas and preservation of a business invariant are separate properties.
07Consistency-model comparison and failure behavior
| Model | What it requires in this example | Useful when | Limit or cost |
|---|---|---|---|
| Linearizable | client B's read after the save cannot return v10 | Current ownership or conditional updates | Coordination or refusal when current authority is unreachable |
| Sequential | All operations fit one order preserving each client's order | A shared logical order is sufficient | Independent clients get no real-time freshness bound |
| Causal | Reply C42 cannot appear without parent C41 | Comments and dependent updates | Independent writes may have different orders |
| Session guarantees | a session does not fall behind its saved or already observed state | An editing session moves between replicas | Other users can still see older state |
| Eventual | Replicas converge after updates stop and communication recovers | Delayed search or derived views | No deadline or read-your-writes guarantee by itself |
| Bounded staleness | Every answer meets a specified time/version lag | Reads can tolerate a measured amount of old data | Wait, route, or fail when the bound cannot be met |
For this hypothetical notebook, I choose session guarantees for the editing screen and causal visibility for threaded comments. These preserve understandable interaction without requiring every read to coordinate across regions. I use an authoritative, ordered ownership update and authorization path because a revoked collaborator must not gain access through a stale permissive replica. The security contract must explicitly address cached permissions and already-issued access, too.
Suppose East fails after client A receives token 11, while West has only version 10. The interface may keep the submitted text and show “reconnecting”; it must not present West’s older result as the saved current version. Wait for a replica that includes token 11 or return a retryable failure. If the storage policy allowed version 11 to be lost, routing cannot recover it. Consistency controls what reads may show; durability controls what saved data survives.
In an interview I would say: “I will define consistency per operation. A session’s reload must include its acknowledged save; replies require their parent; ownership checks use authoritative state. I will show the token or dependency mechanism, and I will specify what the service does when no reachable replica meets that promise.”
Practise the interview questions
Say your answer aloud before opening the model answer. Then answer the follow-up and compare the reasoning.
What is a consistency model? Explain it using a write of version 11 followed by a read.
Reveal a model answer
A consistency model defines the read results and operation orders a system allows. If client A completes a write of version 11 and client B then reads, linearizability forbids the old version 10 when no other write intervened. Eventual consistency may temporarily allow version 10. The choice describes a visible contract, not whether the title text is factually correct.
Interviewer follow-up
What must you clarify when an interviewer asks for strong consistency?
Reveal the follow-up answer
I ask which operation and scope need the guarantee. A title read after a completed save suggests linearizability for that object. Updating title and ownership together also requires a transaction contract. I describe one forbidden history before selecting a database.
What the answer must demonstrate: Define permitted observations and the object or transaction scope.
An interviewer says “the system must be consistent.” Which meaning should you clarify?
Reveal a model answer
I ask whether the requirement concerns read visibility or a business invariant. For CAP consistency, a write that completes before a read starts must be visible to that read, or superseded by a newer write. More generally, I name the required consistency model, such as linearizable or causal. ACID consistency means transactions preserve rules such as nonnegative stock. I would state the operation and show a concrete forbidden result.
Interviewer follow-up
If a replica is behind, does that automatically violate linearizability?
Reveal the follow-up answer
No. The service may route a read to an authoritative copy or wait until it can satisfy the guarantee. A stale successful read after a completed write violates linearizability when no later write explains it; a lagging physical copy alone does not. Refusing or indefinitely waiting for an affected operation sacrifices CAP availability.
What the answer must demonstrate: Connect the familiar current-value explanation to the formal model, and keep ACID validity separate.
A write from v10 to v11 overlaps a read on another client. Must a linearizable read return v11?
Reveal a model answer
“Not necessarily. Under linearizability the read may take effect before or after the concurrent write. I would inspect invocation and response intervals; a read beginning after the write completed is the clearer test.”
Interviewer follow-up
Can the server always return the old value while calling every write concurrent?
Reveal the follow-up answer
“No. The recorded operation intervals constrain that explanation, and completed earlier writes must be respected.”
What the answer must demonstrate: Do not replace the definition with a vague latest-value rule.
Give a history allowed by sequential consistency but not linearizability.
Reveal a model answer
“Client A completes writing v11, then an independent client B starts a read and gets v10. With no other operations, a total order can put client B’s read first, preserving each client’s order. Real-time completion forbids that placement under linearizability.”
Interviewer follow-up
What if the writer performs that later read in the same session?
Reveal the follow-up answer
“With no intervening writer, returning v10 would violate its own write-then-read order, so that history is not sequentially consistent either.”
What the answer must demonstrate: Keep process order separate from wall-clock order.
How do you stop replies appearing before their comments?
Reveal a model answer
“I attach the parent or a sufficient dependency context to client B’s reply. A replica cannot expose the reply until it can expose that history. That is a visibility rule, not just sorting by arrival timestamp.”
Interviewer follow-up
Must two unrelated comments have the same order everywhere?
Reveal the follow-up answer
“Causal consistency does not require that. If the product needs one conversation sequence, I add an ordering mechanism and accept its cost.”
What the answer must demonstrate: Dependencies do not imply a total order for independent writes.
How can a session preserve read-your-writes when failing over from a replica at v11 to one at v10?
Reveal a model answer
“The save response carries a storage position or version context. The next server must prove it has applied that context before answering. If it cannot, it routes or waits; silently returning v10 violates the session promise.”
Interviewer follow-up
Is sticky routing enough?
Reveal the follow-up answer
“It helps during normal operation, but cannot preserve the promise when the pinned server fails and the replacement is behind.”
What the answer must demonstrate: Describe failover as well as the normal request path.
Does a five-second TTL guarantee data no older than five seconds?
Reveal a model answer
“Only under additional assumptions. If a cache fills from a replica already thirty seconds behind, a fresh cache entry is still stale. I need an authoritative reference, propagation limits, and behavior when the bound cannot be met.”
Interviewer follow-up
What would you measure?
Reveal the follow-up answer
“I would measure source-version age or replication lag along the entire read path, with clock assumptions made explicit for time-based bounds.”
What the answer must demonstrate: Cache age and source age differ.
Does causal consistency merge concurrent title edits?
Reveal a model answer
“No. It tells us which edits depend on which earlier edits. Independent edits still need a conflict policy, such as preserving both versions for the user or a domain-specific merge. A last-writer rule chooses a winner but can lose intent.”
Interviewer follow-up
Would a timestamp winner always identify the last human edit?
Reveal the follow-up answer
“No. Clock error and concurrent work make that claim unsafe; a timestamp can define an arbitration rule without representing human intent.”
What the answer must demonstrate: Separate causal ordering, convergence, and application semantics.
Why not require linearizability for every read in a collaborative application?
Reveal a model answer
“It may be acceptable, especially at modest scale, but I would compare the added coordination latency and the operations that may become unavailable with what the product requires. The editing session and comment dependencies can often have clear weaker contracts, while ownership still needs stricter enforcement.”
Interviewer follow-up
What must you avoid when mixing guarantees?
What the answer must demonstrate: Make the choice per operation, not per marketing category.
Blank-page exercise · 15 minutes
Build the answer yourself
Specify three consistency contracts: a session must read its acknowledged writes, a reply must not appear without its parent, and an ownership read must reflect completed changes. Give an allowed and forbidden history, then explain routing, dependencies, and failure behavior for each.
- Name each operation’s object and required guarantee.
- Draw one allowed and one forbidden history.
- Explain replica routing or dependency enforcement.
- Describe behavior when no reachable replica satisfies the requested guarantee.
Check that each component and design decision follows from your requirements and workload.
Recall the key ideas
Answer from memory before opening each card. Explain why the choice works and what it costs. Revisit missed cards tomorrow.
Consistency modelsDo CAP consistency, a consistency model and ACID consistency mean the same thing?Recall first, then reveal
No. CAP consistency is linearizability: later reads see a completed write or a newer write. A consistency model defines the allowed visibility and ordering, including weaker models. ACID consistency means correct transactions preserve database and application rules.
CAP: current value. Model: allowed observations. ACID: valid state.
Return to lessonConsistency modelsDoes read-your-writes make all readers current?Recall first, then reveal
No. It preserves the writer’s session promise; client B may still see an older replica unless that reader’s contract requires more.
My save → my view
Return to lessonConsistency modelsWhat distinguishes linearizable from sequential?Recall first, then reveal
Both admit an ordered explanation, but linearizability also preserves real-time order of non-overlapping operations.
Linearizability also respects completed-before-started order.
Return to lessonConsistency modelsDoes eventual mean within a deadline?Recall first, then reveal
No. A deadline needs a separately defined and enforced staleness bound.
Eventually has no stopwatch
Return to lessonConsistency modelsWhat must accompany a dependent reply?Recall first, then reveal
The causal history it depends on must already be visible in the reader’s view.
Cause before consequence
Return to lessonFinal revision
Summary and interview notes
For each operation, specify which read results and orderings are allowed. Enforce those rules through replicas, caches and failover. When no reachable replica can answer correctly, wait or refuse instead of returning a forbidden result.
Remember these points
- CAP consistency is linearizability; a consistency model is the broader visibility/ordering contract; ACID consistency preserves database and application rules.
- Linearizability preserves real-time order of non-overlapping object operations; sequential consistency preserves each process’s order without that cross-process time constraint.
- Causal order preserves dependencies but does not impose one order on independent writes or make several writes atomic.
- Read-your-writes and monotonic reads require session context that survives routing changes.
- Eventual consistency has no freshness deadline; a bounded-staleness contract needs an explicit reference and failure behavior.
Interview tips
- When an interviewer says consistency, name the meaning before choosing a guarantee. Then give one allowed result and one forbidden result.
- Draw invocation and response intervals for one allowed and one forbidden history.
- Ask whether the requirement applies to an object operation, a session, or a multi-object transaction.
- Show the cache and failover paths, since a weaker alternate path can break a stronger API promise.
Important qualifications
- A scalar session token works for one ordered history; independent objects can require dependency vectors or equivalent context.
- Consistency does not recover a write lost under an inadequate durability policy.
Technical references
- Herlihy and Wing: LinearizabilityPrimary definition of operations taking effect between invocation and response.
- Lamport: How to Make a Multiprocessor Computer That Correctly Executes Multiprocess ProgramsPrimary definition of sequential consistency and preservation of each process’s order.
- Lloyd et al.: COPSPrimary research on tracking dependencies and causal visibility across replicated data.
- Terry et al.: Session Guarantees for Weakly Consistent Replicated DataPrimary reference for the four session guarantees. All notebook traces here are constructed examples.
- Preguiça, Baquero and Shapiro: Conflict-free Replicated Data TypesPrimary explanation of CRDT semantics, synchronization requirements and limitations. The two-component counter is a teaching calculation.
- Gilbert and Lynch: formal CAP definitionsCAP consistency is atomic/linearizable consistency. The completed-write/later-read rule is a consequence; it is distinct from ACID rule preservation.
Practice marks stay in this browser.