Skip to main content

Sequential Consistency

1. Executive Summary​

Sequential consistency (SC) is a correctness condition for shared-memory multiprocessors and replicated systems in which the result of any execution is the same as if all operations from all processes were executed in some single global sequential order, and the operations of each individual process appear in that sequence in the order specified by its program order (Lamport, 1979). Unlike linearizability, sequential consistency does not require that this global order respect real-time precedence across different processes—only that each process's own operations stay in program order.

Sequential consistency sits in the consistency spectrum between linearizability (strongest practical single-object order with real-time constraint) and weaker models such as causal consistency or processor consistency. It is a safety property: it constrains which histories are legal, but does not by itself guarantee liveness (progress, availability, or bounded latency). Hardware memory models (x86 Total Store Order is often described as providing SC for normal aligned accesses in the programmer's mental model, with documented exceptions), distributed databases, and formal verification all reference SC when defining "intuitive" ordering without full linearizability.

This chapter defines sequential consistency formally, contrasts it with linearizability and serializability, explains memory-model and replication implementations, catalogs failure modes and performance tradeoffs, and frames principal-level interview reasoning. Understanding SC is essential when evaluating whether a system's "strong" claims mean linearizability, sequential consistency, or something weaker—and when diagnosing counterintuitive reorderings that violate user mental models but satisfy SC.

2. Why This Topic Matters​

Principal architects encounter sequential consistency in three high-stakes contexts:

  1. Memory consistency models — C++, Java, Go, and hardware ISAs define what reorderings compilers and CPUs may perform. Misunderstanding SC vs relaxed models causes subtle concurrency bugs that pass tests and fail in production.
  2. Distributed replication — Some systems provide SC across replicas without real-time guarantees. Interviewers test whether you can explain why two clients may observe orders that seem to violate wall-clock intuition while still being sequentially consistent.
  3. Precision in ADRs — Teams say "strong consistency" when they mean linearizability, SC, or serializability. Conflating these leads to wrong failover design, incorrect quorum assumptions, and SLA breaches.

Interview signal: candidates who can draw a history that is sequentially consistent but not linearizable demonstrate depth beyond slogan-level CAP knowledge. Candidates who claim "SC is the same as linearizability" fail precision tests at principal level.

Production relevance: SC is often cheaper than linearizability because it does not tie visibility to real-time overlap at clients. Systems may exploit that gap for performance—architects must know whether the gap is acceptable for the product invariant.

3. Problems Being Solved​

ProblemWithout a defined orderWith sequential consistency
Reasoning about concurrent programsAd hoc; every interleaving seems possibleAll executions equivalent to one global sequence respecting per-process program order
Compiler and CPU optimizationsUnclear which reorderings are legalSC defines the programmer-visible contract (or a target model for verification)
Multi-replica readsInconsistent cross-client narrativesOne sequential story exists—though not necessarily real-time aligned
Formal verificationState explosion without constraintsSC reduces valid executions vs pure concurrency
Teaching and specificationAmbiguous "strong" claimsNamed model with decades of literature

Sequential consistency solves "is there a single sequential story for all processes' operations?" It does not solve "does that story match wall-clock order across clients?" (linearizability) or "are multi-key transactions atomic?" (serializability).

4. Assumptions and System Model​

Assume the standard shared-memory or replicated-register model unless stated otherwise:

  • Processes (or clients) each execute a program—a sequence of operations on shared objects.
  • Program order: Within one process, operations appear in the order they appear in the program text (invoke before invoke for successive ops on overlapping objects, per Lamport's formulation).
  • Global sequential order: There exists a total order of all operations from all processes such that each process's operations appear in program order in that sequence.
  • Object semantics: Each operation's response is consistent with the sequential specification of the object type when operations are applied in the global order.
  • Asynchronous network for distributed implementations; crash-stop processes unless discussing Byzantine variants.

Not assumed: Real-time precedence across processes (that is linearizability). Synchronized clocks. Multi-object atomic transactions unless a separate transactional layer provides them.

Scope: Sequential consistency is typically defined over a set of shared objects and all processes accessing them. A system may be SC for one namespace and weaker for another—document scope in ADRs.

5. Essential Terminology​

TermDefinition
Sequential consistency (SC)Exists a global sequential order of all ops; each process's ops appear in program order in that sequence.
Program orderOrder of operations as issued by a single process in its code.
Global orderTotal order combining operations from all processes.
LinearizabilitySC plus real-time constraint: if op₁ completes before op₂ starts, op₁ precedes op₂ in the order.
HistoryRecord of invocations and responses with timing intervals.
Sequentially consistent historyEquivalent to some sequential history respecting program order per process.
Coherence (cache coherence)Writes to same address become visible in same order to all—weaker than SC in general.
Processor consistencyWeaker than SC; relaxes ordering among writes from different processors in some definitions.
Causal consistencyPreserves happens-before; does not require a single global order of all ops.
Memory barrier / fenceInstruction forcing visibility ordering—implementation mechanism, not a consistency model.
TSO (Total Store Order)x86-like model: stores buffered; loads may see stale values briefly—not identical to SC in formal sense for all programs.

Mnemonic: Sequential = one global line where each player's moves stay in their script order—but the line need not match wall-clock across players.

6. Core Mechanism​

Formal definition (Lamport, 1979)​

A multiprocessor is sequentially consistent if the result of any execution is the same as if the operations of all processors were executed in some sequential order, and the operations of each individual processor appear in this sequence in the order specified by its program.

Equivalently for distributed histories: there exists a sequential history (S) equivalent to concurrent history (H) such that for every process (P), if operation (a) precedes (b) in (P)'s program order, then (a) precedes (b) in (S).

Relationship to linearizability​

Every linearizable history is sequentially consistent, but not vice versa. SC allows reordering across processes that violates real-time precedence.

Figure 1: A read that returns a stale value after another process's write completed can be sequentially consistent but not linearizable.

SC vs coherence​

Figure 2: Sequential consistency implies a single global order; cache coherence alone does not guarantee SC for multi-location programs.

Implementation sketch (distributed)​

Figure 3: Practical SC often uses a serialization point (leader, lock, or hardware bus) that assigns a global order while not necessarily exposing real-time visibility.

7. Step-by-Step Walkthrough​

Scenario: Two processes, shared register x initially 0.

StepProcessOperationWall-clock
1P1write(x, 1)t=10–20
2P2read(x) → 0t=25–30 (starts after P1 write completes)
3P2write(x, 2)t=35–45
4P1read(x) → 2t=50–55

Analysis:

  • Linearizability: Violated at step 2—P1's write completed before P2's read started; read must return 1.
  • Sequential consistency: Satisfied by global order: read_P2(0), write_P1(1), write_P2(2), read_P1(2). Check program order: P1 sees write before read ✓; P2 sees read before write ✓.

Walkthrough insight: SC preserves each process's narrative; it does not preserve cross-process real-time intuition. Users who expect "if I finished writing before you read, you see my write" are assuming linearizability, not SC.

Second scenario — SC violation: P1: write(x,1); read(y,0). P2: write(y,1); read(x,0). No sequential order satisfies both program orders and register semantics—not SC. This is the classic cross-process circular dependency that SC forbids but relaxed models may allow under careful conditions.

8. Invariants and Guarantees​

PropertyTypeStatement
Global sequential orderSafety∃ total order of all operations equivalent to the concurrent execution
Program order preservationSafetyPer-process operations appear in program order in the global order
Object sequential specSafetyResponses match applying ops in global order to sequential object spec
Real-time respectNot guaranteedSC does not require (op_1 \rightarrow_{rt} op_2 \Rightarrow op_1) before (op_2)
AvailabilityLivenessNot implied—implementation may block
ProgressLivenessNot implied

Safety vs liveness: SC is purely a safety condition on histories. A system that halts forever after a correct prefix does not violate SC; it violates liveness.

9. Failure Scenarios​

Scenario 1: Mislabeling SC as linearizability​

Setup: Product claims "strong consistency"; implementation provides SC via async replication with a single sequencer that batches reorderings.

Effect: Clients observe stale reads across processes after writes complete—support tickets, "impossible" screenshots, audit failures.

Mitigation: ADR with formal model name; client-facing docs; upgrade to linearizable reads where required.

Scenario 2: Compiler reordering under relaxed memory model​

Setup: C++ program uses std::atomic incorrectly; non-atomic data races; compiler reorders plain loads/stores.

Effect: Behavior not SC and not any well-defined model—undefined behavior.

Mitigation: Correct atomics, memory orders (memory_order_seq_cst for SC atomics), code review, ThreadSanitizer.

Scenario 3: SC violated by independent per-key ordering​

Setup: Sharded system orders operations per shard but not across shards; client performs multi-key sequence.

Effect: Global SC fails—no single order includes cross-shard program order correctly.

Mitigation: Cross-shard sequencer, transactions, or weaken advertised guarantee to per-shard SC.

Scenario 4: Performance tuning breaks SC​

Setup: Replica serves reads locally without contacting sequencer; writes go through leader.

Effect: Reads may violate global order relative to writes—SC broken unless reads are coordinated.

Mitigation: Route reads through sequencer or use versioned staleness bounds with explicit weaker model.

Scenario 5: Testing gap​

Setup: Single-threaded tests pass; multi-client integration tests use synchronized clocks assuming linearizability.

Effect: Production reveals SC-legal but user-hostile orderings.

Mitigation: Model-check histories; property-based concurrency tests; Jepsen with correct oracle selection.

10. Performance Characteristics​

FactorSC vs linearizabilityNotes
SerializationBoth need global order for strict SCSC may batch/reorder across processes within sequencer
Read latencySC may allow local reads in some designsLinearizability typically needs sync with order point
HardwareSC on bus was historical default targetModern CPUs use weaker models + fences for speed
DistributedSingle sequencer bottleneck similar to leaderSC without real-time check may skip some sync steps

Qualitative rule: SC is not free, but implementations may omit real-time visibility checks that linearizable systems pay for. Do not invent benchmark numbers—measure your sequencer throughput and cross-region RTT.

Memory model note: memory_order_seq_cst in C++ provides SC among seq_cst atomics—not for the entire program if plain accesses race.

11. Scalability Limits​

  • Global sequencer: Single ordering point caps throughput for strict SC across all objects.
  • Sharding: SC per shard scales; global SC does not without hierarchical ordering cost.
  • Geographic distribution: Propagating a total order globally adds latency—SC does not remove physics.
  • Hardware: SC across many sockets historically limited by bus/coherence protocol—industry moved to weaker models.

When SC does not scale: Planet-wide shared counter with strict SC on every op; all clients reading/writing one namespace through one orderer.

12. Operational Considerations​

  • Document the model: "Sequentially consistent per partition" vs "linearizable reads."
  • Monitor sequencer lag: Backlog implies visible order delay even under SC.
  • Client SDK behavior: Retries and timeouts may duplicate ops—idempotency interacts with ordering guarantees.
  • Upgrade paths: Moving from eventual → SC → linearizability has distinct engineering costs—phase migrations in runbooks.
  • Incident response: When users report "stale after write," check whether guarantee is SC (legal) or linearizable (bug).

13. Security Considerations​

  • Order manipulation: Attacker flooding sequencer delays others' visibility—DoS on ordering service.
  • Side channels: SC systems with shared buffers may leak ordering via timing—threat model dependent.
  • Authorization: SC does not imply access control—illegal ops must be rejected before entering the global order.
  • Split views: If SC violated due to misconfiguration, security policies based on "latest write wins" may fail.

SC is a safety property on operation ordering, not confidentiality or integrity alone.

14. Cost Considerations​

  • Latency: Global ordering adds RTT to sequencer vs local eventual reads.
  • Infrastructure: Dedicated ordering service (Kafka partition, Raft cluster, ZooKeeper).
  • Engineering: Concurrency bugs from misunderstanding SC vs relaxed models are expensive to diagnose.
  • Opportunity cost: Strict SC may block designs that need causal or eventual models for availability.

Decision criterion: Require SC when all processes must agree on a single narrative but real-time cross-client visibility is not mandatory. Prefer linearizability when user mental models assume wall-clock precedence.

15. Production Implementations​

Hardware (x86 TSO)​

Intel/AMD documentation describes TSO-like behavior for normal memory operations. Programmers often reason with SC-like intuition; formal SC requires careful use of atomics and fences. Implementation choice by CPU vendor—not a distributed guarantee.

ZooKeeper​

Often described as providing sequential consistency for updates visible to each client in order, while not guaranteeing linearizable reads in all API usages without sync calls. Verify exact API contract in current documentation.

Single-partition Kafka consumers​

Records within a partition have a total order; consumers see messages in offset order—analogous to SC for that partition's stream, scoped.

Spanner / external consistency​

Stronger than SC—external consistency includes real-time transaction ordering (Corbett et al., 2012).

Research and verification tools​

TLA+, Alloy, and memory model checkers (CDSChecker, herd) use SC as baseline or comparison point.

Distinction: Separate marketing "strong" from named model in each product's documentation.

16. Alternatives and Tradeoffs​

ModelRelative strengthCostUse when
LinearizabilityStrongest (real-time + SC)Highest coordinationLocks, coordination, user-visible "now"
Sequential consistencyGlobal order, program orderHighShared-memory reasoning, some replicated state
Causal consistencyHappens-before onlyMediumSocial graphs, collaborative editing
Processor consistencyWeaker than SCLowerSome parallel algorithms tolerate relaxations
Eventual consistencyConvergence onlyLowestHigh availability, caches

Tradeoff axis: SC buys a single story without buying real-time alignment—narrower than linearizability, broader than causal.

17. Common Misconceptions​

MisconceptionReality
"SC = linearizability"Linearizability adds real-time; SC is strictly weaker.
"SC means immediately visible"Visibility timing is implementation-dependent; order exists, not necessarily instant.
"Coherent caches imply SC"Coherence is per-location; SC is global across all locations and ops.
"SC solves database transactions"Serializability is the transactional analog—related but distinct.
"seq_cst fixes all bugs"Only applies to atomics marked seq_cst; data races on plain vars are UB.
"If each replica is consistent, the system is SC"Independent replica orders without coordination do not compose to global SC.

18. Principal Architect Perspective​

  1. Name the model in ADRs — Write "sequential consistency" not "strong" when that is the actual guarantee.
  2. Test cross-client expectations — Product may assume linearizability while engineering delivers SC.
  3. Scope ordering — Per-shard SC is a common, scalable compromise.
  4. Memory models matter — Services in Go/Java still run on relaxed hardware; know your fences.
  5. Verification investment — SC properties are model-checkable; use that for critical paths.

Interview signal: producing a concrete history separating SC from linearizability demonstrates principal-level precision.

19. Architecture Review Exercise​

Scenario: Global configuration service: writes go to Raft leader; reads served from any follower without read_index or lease check. Marketing claims "strong consistency."

Review prompts:

  1. Is follower read linearizable? Sequentially consistent?
  2. Draw a history where write completes, another client's read returns old value—which model allows it?
  3. Cost of linearizable reads on this architecture?
  4. Can you offer SC with lower read latency? How?
  5. What does the configuration use case actually require?

Expected findings: Follower reads likely violate linearizability; may violate SC depending on apply lag; align product language with Raft read APIs.

20. Whiteboard Explanation​

90-second version:

"Sequential consistency means you can line up every operation from every process into one global sequence, and each process's operations appear in that sequence in the same order they wrote them in code. Lamport defined this in 1979 for multiprocessors. It's weaker than linearizability, which also requires that if my operation finishes before yours starts in real time, mine comes first in the global order. SC allows your read to return stale data even after my write completed—that's legal for SC but illegal for linearizability. Hardware moved to weaker models for performance; we use fences and atomics where SC-like reasoning is needed. In distributed systems, SC often means a single sequencer orders ops. Always ask: do we need SC or linearizability for the user story?"

21. Interview Questions​

  1. Define sequential consistency.

    • Signals: Global order, program order per process, Lamport 1979.
    • Red flags: "Everyone sees the same value" without ordering formalism.
  2. SC vs linearizability?

    • Signals: Real-time precedence; every linearizable history is SC.
  3. Give a history SC but not linearizable.

    • Signals: Cross-process stale read after write completed.
  4. Is SC a safety or liveness property?

    • Signals: Safety only.
  5. SC vs cache coherence?

    • Signals: Coherence per address; SC global across program.
  6. SC vs serializability?

    • Signals: Register/op level vs transaction equivalence.
  7. Does SC imply causal consistency?

    • Signals: SC is stronger—global order implies happens-before preserved.
  8. How does x86 relate to SC?

    • Signals: TSO, not formal SC for all programs; atomics/fences.
  9. Single leader assigning order—SC or linearizable?

    • Signals: Depends on read path and real-time visibility—not automatic.
  10. Can SC be violated under partition?

    • Signals: If both sides accept conflicting orders—depends on implementation; pure SC doesn't dictate partition behavior.
  11. Why did industry weaken memory models?

    • Signals: Performance—store buffers, reordering, fence costs.
  12. How to test for SC violations?

    • Signals: Litmus tests, model checkers, Jepsen with SC oracle.
  13. ZooKeeper—SC or linearizable?

    • Signals: Nuanced—sync API, read modes; check documentation.
  14. When accept SC instead of linearizability?

    • Signals: Don't need cross-client real-time; need global narrative; cost savings.

22. Interview Follow-Ups​

  1. Design SC register with three replicas.

    • Signals: Sequencer, total order broadcast, ordered apply.
  2. Client requires linearizability but system offers SC—bridge?

    • Signals: Sticky routing, sync reads, version checks, scope reduction.
  3. Map SC to Kafka partition ordering.

    • Signals: Per-partition total order; cross-partition not SC globally.
  4. Formal methods ROI for SC claims?

    • Signals: TLA+ spec, model checking critical paths, audit evidence.
  5. Executive wants "strongest" consistency—recommendation?

    • Signals: Decompose by use case; linearizable for locks, SC or weaker for feeds.

22A. Production Low-Level Design (Interview + Game Day)​

Total-order broadcast + ordered apply for SC register; document read path. Production LLD and Game Day Standard.

SC implementation sketch​

ComponentRole
SequencerAssign global sequence
ReplicasApply ops in sequence order
Read APIMust go through ordered path for SC claim

Step-by-step flow:

StepSC property
1–3Global total order exists
4–5Per-process program order preserved in that order
Stale replica readMay break SC in practice—verify path

SLO​

Document which APIs are SC vs eventual; SC canary for program-order tests.


22B. Game Day Playbooks​

#DrillInjectDetectMitigateVerify
GD-1Stale read pathRead from lagging replicaSC canary failRoute via sequencerProgram order holds
GD-2SC vs linearizabilityReal-time constraint testHistory analysisClarify product needCorrect model chosen
GD-3Kafka cross-partitionMulti-partition writesNo global SCPer-partition order onlyADR updated

GD-1 — Program order vs stale read​

23. Strong Answer Example​

Question: "Our replicated cache is sequentially consistent. Can a user see their friend's post before their own post appears?"

Answer this as a 45-minute design discussion using the PRACTICE framework. Below is how a strong student sounds aloud—program order on same process, not "everyone sees same data instantly."


Student interview script (PRACTICE)​

P — Problem framing​

"Under sequential consistency, there exists a global total order consistent with each process's program order.

If same client: write(myPost) then read(feed) in program order—the global order must place my write before that read → must see own post.

Different clients or stale read path can still surprise: SC does not add real-time constraint (that's linearizability). Friend might see your post before you if your read hits a lagging replica unless read path preserves SC.

Non-goals: claiming SC = instantaneous global visibility."

R — Requirements​

TypeRequirement
FRPost; read feed
ConsistencySC as marketed—or clarify weaker
UXAuthor sees own post after write
OpsVerify read API path matches claim

A — Assumptions​

AssumptionWhy
Write then read same sessionProgram order case
Replicated cache with multiple replicasStale read risk
"SC" may be design intent vs implementationAudit path

C — Capacity​

Sequencer throughput → SC cost vs eventual
Per-partition Kafka order → SC within partition only
Read-your-writes → Often sufficient for author UX

T — Topology​

I — Invariants​

"Global order respects program order per process. Not real-time across clients."

C — Constraints​

ConstraintResponse
Need cross-client real-timeLinearizability or session guarantees
Lagging replica readsBreaks SC/RYW—fix routing
vs linearizabilitySC weaker—no real-time

E — Evolution​

Audit read path; add RYW/session if SC too costly; ADR naming actual guarantee.

Closing line​

"Same-client write-then-read: SC requires own post visible if read path participates in SC. Friend-before-you can happen without linearizability or with stale reads. Audit the read API—marketing 'SC' must match routing."

Scoring signals​

StrongWeak
Program order vs cross-client"Everyone sees same data at once"
Read path auditConflates SC with linearizability
RYW as targeted fixHand-wave "SC cache"

Compact outline (2 minutes)​

"SC = global order + program order. Same process write-then-read: must see own write if SC holds on read path. Not real-time across clients—that's linearizability. Verify replicas/routing. Consider read-your-writes for author UX."

24. Weak Answer Example​

Question: "Our replicated cache is sequentially consistent. Can a user see their friend's post before their own post appears?"

"No, sequential consistency means everyone sees the same data at the same time."

Why weak: Conflates SC with linearizability and instantaneous global visibility; ignores program order rules and read-path implementation.

25. Hands-On Exercise​

Exercise: SC history construction

  1. Write two processes: P1 does write(x,1); read(y); P2 does write(y,1); read(x). Initial x=0, y=0.
  2. Attempt to build a global order satisfying program order and register semantics.
  3. Repeat with P2's read returning 1—valid SC?
  4. Add real-time: P1's write completes before P2's read starts—does SC still allow read(x)=0 on P2?
  5. Document: for your team's cache, which read API paths are SC, linearizable, or eventual.

Success criteria: Correct SC vs linearizability classification for at least three histories; ADR snippet with named model.

26. Knowledge Check​

  1. Who formalized sequential consistency? (Lamport, 1979.)
  2. What two orders does SC combine? (Global total order + per-process program order.)
  3. Is every linearizable execution SC? (Yes.)
  4. Is every SC execution linearizable? (No.)
  5. Does SC respect real-time across processes? (No.)
  6. SC vs coherence? (SC global; coherence typically per-memory-location.)

27. Flashcards​

#FrontBack
1Sequential consistency (informal)One global op order; each process's ops keep program order.
2Lamport (1979)Original SC definition for multiprocessors.
3vs linearizabilitySC lacks cross-process real-time constraint.
4Program orderOrder of ops as issued by one process.
5Global orderTotal order over all processes' operations.
6Safety propertySC constrains legal histories, not progress.
7SC violation exampleNo sequential order satisfies all program orders (SB+SB litmus).
8Hardware TSOx86-like model; not identical to SC for all programs.
9memory_order_seq_cstC++ atomic order requesting SC among seq_cst ops.
10vs serializabilityOp-level vs transaction serial equivalence.
11vs causal consistencySC stronger—single total order vs happens-before.
12Implementation patternSequencer / leader assigns global order.

28. Cheat Sheet​

SEQUENTIAL CONSISTENCY
- ∃ global total order of ALL ops
- Each process: program order preserved in that order
- SAFETY not liveness
- WEAKER than linearizability (no real-time)

LINEARIZABILITY ⇒ SC
SC ⇏ LINEARIZABLE (stale cross-process reads OK)

DISTRIBUTED
- Often: single sequencer / Raft order
- Read path determines actual observed guarantee

HARDWARE
- Relaxed models + fences
- seq_cst atomics for SC fragment

INTERVIEW
- Draw SC-but-not-linearizable history
- vs coherence, vs serializability

30. References​

Primary sources​

Textbooks and engineering​

  • Herlihy, M., & Shavit, N. (2020). The Art of Multiprocessor Programming (2nd ed.) — SC, linearizability, memory models.
  • Martin Kleppmann, Designing Data-Intensive Applications (O'Reilly) — consistency spectrum in distributed systems.
  • Boehm, H. J., & Adve, S. V. (2008). "Foundations of the C++ Concurrency Memory Model." — practical memory orders.

Distinction​

Claim typeSource
SC formal definitionLamport (1979)
SC vs linearizabilityHerlihy & Wing (1990)
x86 TSO behaviorVendor ISA manuals—verify current revision
ZooKeeper consistency claimsApache ZooKeeper documentation—implementation evolves