System designby Learnastra

Concept lesson · Foundations

Consistency models

By Anup Rai

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.

The visual modelLinearizability, read-your-writes, and eventual consistency

Consistency models constrain observations. Compare a real-time guarantee, a session guarantee, and eventual convergence.

Linearizability, read-your-writes, and eventual consistencyConsistency models constrain observations. Compare a real-time guarantee, a session guarantee, and eventual convergence. 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.Write v11 completes before the read beginsClient A: write v11; ACKlater read beginsLINEARIZABLEAny user: v11 or laterv10 is forbiddenREAD YOUR WRITESClient A session: v11 or laterClient B may see v10EVENTUALv10 may appear while replicas lagConverges; no deadline impliedThese models differ in whose reads and which ordering constraints they guarantee.
Read the diagram step by step
  1. Client A writes v11 and receives an acknowledgement before the shown read begins.
  2. A linearizable read must return v11 or a later write in the agreed order.
  3. 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.
  4. 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 practice

Useful foundations: Replication and durability · CAP theorem: consistency, availability, and partition tolerance

Workload and timing examples are interview assumptions.

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.

  1. 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.
  2. 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.

Worked example diagramA session carries a minimum applied-position token of 11. A replica at 10 must wait, redirect, or fail that read; the token does not establish global freshness for other sessions.
Consistency models: architecture diagram1. Client A writes title v11 to 2. East stores v11: commit; 2. East stores v11 to 3. Client A receives token 11: reply; 3. Client A receives token 11 to 4. West has v10: read with minimum 11; 4. West has v10 to 5. Wait or route to v11: 10 is too old; 5. Wait or route to v11 to 6. Client A reads v11: satisfy session1 → 2: commit2 → 3: reply3 → 4: read with minimum 114 → 5: 10 is too old5 → 6: satisfy session01Client A writestitle v1102East stores v1103Client A receivestoken 1104West has v1005Wait or route to v1106Client A reads v11
  1. 1 → 2commitClient A writes title v11 → East stores v11
  2. 2 → 3replyEast stores v11 → Client A receives token 11
  3. 3 → 4read with minimum 11Client A receives token 11 → West has v10
  4. 4 → 510 is too oldWest has v10 → Wait or route to v11
  5. 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:

  1. 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.
  2. 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:

  1. 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.
  2. 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:

  1. Create the parent. Client A writes comment C41, “Train at six.”
  2. Observe and reply. Client B reads C41 and writes C42, “I will be there.”
  3. 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:

  1. 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.
  2. Merge by maximum. Take the maximum per component: A=(2,0) and B=(0,3) merge to (2,3).
  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.

Foundation · Question 1

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.

What the answer must demonstrate: Define permitted observations and the object or transaction scope.

Foundation · Question 2

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.

What the answer must demonstrate: Connect the familiar current-value explanation to the formal model, and keep ACID validity separate.

Applied · Question 3

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.”

What the answer must demonstrate: Do not replace the definition with a vague latest-value rule.

Foundation · Question 4

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.”

What the answer must demonstrate: Keep process order separate from wall-clock order.

Applied · Question 5

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.”

What the answer must demonstrate: Dependencies do not imply a total order for independent writes.

Applied · Question 6

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.”

What the answer must demonstrate: Describe failover as well as the normal request path.

Follow-up · Question 7

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.”

What the answer must demonstrate: Cache age and source age differ.

Follow-up · Question 8

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.”

What the answer must demonstrate: Separate causal ordering, convergence, and application semantics.

Applied · Question 9

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.”

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 lesson
Consistency 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 lesson
Consistency 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 lesson
Consistency 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 lesson
Consistency 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 lesson

Final 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

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

Practice marks stay in this browser.