← Back to System Design, page 1

system-design-0005 · Hard senior

Compare strong, eventual, causal and read-your-writes consistency with examples of when each is acceptable.

Strong (linearizable) consistency makes replicas behave like one copy. Eventual consistency only promises replicas converge if writes stop. Causal consistency keeps cause-before-effect order visible to everyone. Read-your-writes is a session guarantee that a user always sees their own updates. Stronger models cost latency and availability, so pick the weakest one the feature can tolerate.

Full answer

The models, strongest to weakest

Linearizability (strong). Every operation appears to happen at one instant between its start and end, and all clients see the same order. After a write completes, every later read returns it. Needed for locks, leader election, unique usernames, and "decrement stock only if above zero".

Sequential consistency. All clients see the same order of operations, and each client's own operations keep their order, but that order need not match real time. Rarely exposed directly by databases; useful to know as the step below linearizability.

Causal consistency. If operation A could have influenced B (B read A's result, or the same client did A then B), everyone sees A before B. Concurrent, unrelated writes may appear in different orders on different replicas. Example: in a comment thread, a reply must never appear before the comment it answers.

Eventual consistency. If no new writes arrive, all replicas eventually return the same value. No promise about what you read in the meantime. Fine for like counts, view counts, "last seen" times, recommendations.

Session guarantees

These are cheaper guarantees given to one client:

  • Read-your-writes: after a teacher updates a student's marks, that teacher's next page load shows the new marks, even if other users see them a second later.
  • Monotonic reads: a user never sees time go backwards (new value, then old value on refresh).
  • Monotonic writes: a client's writes are applied in the order sent.

How they are implemented

  • Strong: single leader with synchronous majority replication or a consensus protocol (Raft, Paxos); reads go through the leader or use a quorum or lease.
  • Read-your-writes: route the user's reads to the leader for a short window after a write, or send the write's log position (a version or LSN) with later reads and only read from replicas that have caught up to it.
  • Monotonic reads: pin a user's session to one replica.
  • Causal: track dependencies with version vectors or hybrid logical clocks.

Choosing

Use the weakest model that keeps the product correct. A social feed can be eventual with read-your-writes for the author. A payments ledger write path needs linearizable operations. The cost of stronger models is extra round trips and reduced availability during partitions.

By level

Fresher: Explain strong versus eventual consistency with a simple example, such as a profile photo update that takes a moment to show for others. A fresher should also be able to say why the author of a post should see it at once.

Mid: Add causal and read-your-writes, explain anomalies users would notice with replicas, and describe how to implement read-your-writes and monotonic reads. Expect a concrete technique such as reading from the leader for a short window after a write.

Senior: Distinguish linearizability from serializability, explain version vectors or hybrid logical clocks, and design per-feature consistency for a multi-region product with clear latency and availability costs. The senior answer ties each model to a latency and availability cost.

Key points

  • Linearizable = behaves like one copy in real-time order
  • Causal keeps cause-before-effect; concurrent writes may differ in order
  • Eventual only promises convergence when writes stop
  • Session guarantees (read-your-writes, monotonic reads) are cheap and fix most user-visible anomalies
  • Pick the weakest model the feature can tolerate

Common mistakes

  • Saying eventual consistency means "data is lost" or "random"
  • Confusing linearizability with serializability (a transaction isolation property)
  • Ignoring session guarantees and jumping straight to strong consistency
  • Claiming causal ordering can be done with wall-clock timestamps alone

Follow-ups

  • How would you implement read-your-writes with asynchronous replicas?
  • What is the difference between linearizability and serializability?
  • How do version vectors detect concurrent writes?

Tips

  • Order the models from strongest to weakest before giving examples
  • Attach one product example to each model
  • Mention at least one implementation technique per guarantee

Evaluation rubric

  • Accurate definitions of each model
  • Distinguishes session guarantees from global models
  • Gives realistic examples of acceptable use
  • Discusses cost and implementation