00:00

Consistency in System Design: Models, Trade-offs and Examples

Last updated:

Consistency in system design describes whether everyone who reads a piece of data sees the same, up-to-date value. On a single database server this is easy. Once data is copied across several servers, caches or regions, copies can briefly disagree, and the system must decide what readers are allowed to see. That decision is captured by a consistency model.

This tutorial explains why consistency is hard in distributed systems, walks through the main consistency models from strongest to weakest, and shows the techniques databases use to provide them. It ends with common mistakes and best practices.

1. What Is Consistency?

Imagine a bank account shown in a mobile app, on the website and at an ATM. You withdraw ₹2,000 at the ATM. A consistent system shows the new balance everywhere immediately. An inconsistent system might still show the old balance in the app for a few seconds, which could let you spend the same money twice.

In distributed systems, consistency answers one question: after a write, what will later reads return?

  • With strong consistency, every read returns the latest successful write, no matter which server answers.
  • With weaker consistency, reads may return older values for a while, in exchange for speed and availability.

Note that the word appears in two different places. The "C" in CAP means the replica-agreement kind of consistency described here. The "C" in ACID means something else: that a transaction keeps data valid according to rules such as constraints. See ACID vs BASE for that meaning.

2. Why Consistency Is Hard in Distributed Systems

Large systems keep several copies of data: database replicas for read scaling and availability, caches for speed, and copies in multiple regions for low latency. Copying takes time, so for a moment after every write, some copies are newer than others.

A stale read caused by replication lag A user writes a new display name, Ravi Kumar, to the primary database. The change travels to a replica asynchronously and has not arrived yet. A moment later, a read is served from the replica and returns the old name, Ravi. User Primary name = "Ravi Kumar" 1. write Replica name = "Ravi" (old) 2. replicating,not arrived yet Reader 3. read returns "Ravi" the reader sees stale data until replication catches up
Figure 1: Replication lag: the write reached the primary, but the replica has not caught up yet, so a read from the replica returns the old value.

Several forces make perfect consistency expensive:

  • Network delay: confirming a write with replicas in another region can add tens or hundreds of milliseconds.
  • Failures and partitions: if replicas cannot talk to each other, the system must either stop accepting some requests or let copies diverge. This is the CAP theorem.
  • Concurrency: two users can update the same data at the same moment through different servers.
  • Caching: every cache is another copy that can go stale.

3. Consistency Models from Strongest to Weakest

A consistency model is a contract between a data system and its users: it promises which values reads may return. Stronger models are easier to program against; weaker models are faster and more available.

The spectrum of consistency models A horizontal arrow runs from strongest on the left to weakest on the right. Along it are linearizable, sequential, causal, session guarantees such as read-your-writes and monotonic reads, and eventual consistency. Above the arrow, stronger models are easier to reason about. Below it, weaker models give lower latency and higher availability. STRONGEST WEAKEST Linearizable Sequential Causal Sessionread-your-writes Eventual easier to reason about, behaves like one copy lower latency, higher availability pick per feature: the cost of stale data decides how far right you can go
Figure 2: Consistency models form a spectrum. Moving right trades simplicity of reasoning for lower latency and higher availability.
ModelGuaranteeEveryday example
Linearizable (strong)The system behaves as if there is one copy; once a write completes, every later read sees itBank balance, seat booking, unique usernames
SequentialAll clients see operations in the same order, though not necessarily in real-time orderA shared log that everyone replays identically
CausalOperations that are causally related are seen in the same order by everyone; unrelated ones may be seen in any orderA reply never appears before the message it answers
Read-your-writesA user always sees their own latest changesAfter editing your profile, you see the new photo
Monotonic readsOnce you have seen a value, you never see an older one laterA comment you saw does not vanish when you refresh
EventualIf writes stop, all copies converge to the same value eventuallyLike counts, view counts, DNS records

4. Strong Consistency Explained

With strong consistency (formally linearizability), the system acts as if there were a single copy of the data and every operation happened at one instant. If Alice's write finishes at 10:00:00.000, anyone who reads after that moment, from any server, sees Alice's value.

Systems provide strong consistency by making writes and reads coordinate:

  • All reads and writes go through a single leader, which always has the latest data.
  • Writes are confirmed only after a majority of replicas agree, using a consensus protocol such as Raft or Paxos.
  • Writes use synchronous replication, so replicas are updated before the client gets a success response.

Cost: every write waits for coordination, which adds latency, especially across regions. During network partitions, part of the system must refuse requests to avoid returning stale data.

5. Eventual Consistency Explained

With eventual consistency, a write is accepted by one or a few replicas and spread to the others in the background. For a short window, different readers may see different values. If no new writes arrive, all replicas eventually agree.

In a healthy system this window is usually milliseconds to a few seconds. Eventual consistency gives:

  • Low latency: writes and reads are answered by a nearby replica without waiting for others.
  • High availability: replicas keep working even when they cannot reach each other.
  • Easy scaling: adding replicas does not slow down writes.

The trade-off is that the application must cope with stale reads and concurrent conflicting writes, for example by using last-write-wins rules, merging changes or special data types called CRDTs. Eventual consistency is the "E" in BASE.

6. Session Guarantees: The Practical Middle Ground

Pure eventual consistency can confuse users, while strong consistency everywhere is expensive. Session guarantees fix the most visible problems for each user without paying for global strong consistency:

  • Read-your-writes: after you change something, your own reads always reflect it. Others may still see the old value briefly.
  • Monotonic reads: your view never goes backwards in time. Without it, refreshing a page could make a new comment disappear because you hit a lagging replica.
  • Monotonic writes: your writes are applied in the order you made them.
  • Writes follow reads (causal): if you reply to a comment, everyone who sees your reply can also see the comment.
Monotonic reads violated by switching replicas A user's first page load is served by Replica A, which is up to date and shows three comments. On refresh, the user is served by Replica B, which is lagging and shows only two comments, so a comment appears to vanish. The fix is to keep sending the user to the same replica or to one that is at least as up to date. User Replica A · up to date 3 comments Replica B · lagging 2 comments 1st load refresh "my comment vanished!" fix: same replica for the session
Figure 3: Without monotonic reads, a refresh can show older data than the previous page load. Routing each user to a consistent replica, or tracking the version they have seen, fixes it.

7. Techniques for Achieving Consistency

TechniqueHow it worksGives you
Single leader for reads and writesOne node handles all operations for a piece of dataStrong consistency; the leader can become a bottleneck
Synchronous replicationWrites wait until replicas confirmNo stale replicas; higher write latency
Quorum reads and writesWith N replicas, write to W and read from R where R + W > NReads overlap the latest write; tunable per request
Consensus (Raft, Paxos)A majority must agree on the order of operationsLinearizable, fault-tolerant logs and metadata
Version numbers and vector clocksEach value carries a version; clients and replicas compare versionsDetects stale data and concurrent writes; enables read-your-writes
Sticky routingA user's reads go to the same replica, or to the leader for a short time after a writeMonotonic reads and read-your-writes
CRDTsData types such as counters and sets that merge concurrent updates automaticallyEventual consistency without conflicts
Cache invalidationDelete or update cached entries when data changes; use short TTLsFewer stale reads from caches

Quorums are explained with a diagram in the CAP Theorem tutorial.

8. Consistency vs Availability vs Latency

Consistency always competes with two other goals:

  • Availability: the CAP theorem says that during a network partition you must choose between consistency and availability.
  • Latency: the PACELC theorem adds that even without failures, stronger consistency costs latency, because replicas must coordinate. A write that must be confirmed in Mumbai and Frankfurt cannot be faster than the round trip between them.

This is why large systems rarely use one consistency level for everything. They choose strong consistency for data where mistakes are costly, and weaker models where speed and availability matter more. See Availability and Latency.

9. Common Mistakes to Avoid

  • Reading just-written data from a replica, causing "my change disappeared" bug reports.
  • Assuming caches are always fresh; forgetting to invalidate them on writes, or setting very long TTLs on data that changes.
  • Using eventual consistency for money or inventory without a strongly consistent step for the critical decision.
  • Demanding strong consistency everywhere, which makes the system slow and less available for no business benefit.
  • Confusing ACID consistency with CAP consistency when discussing requirements.
  • Ignoring concurrent writes in eventually consistent systems, so updates silently overwrite each other.
  • Not monitoring replication lag, so stale reads grow unnoticed during heavy load.

10. Best Practices

  • Classify data by the cost of staleness, and choose the weakest model that is still correct for each feature.
  • Use strong consistency for decisions that cannot be undone, such as charging money or confirming the last seat.
  • Provide read-your-writes and monotonic reads for user-facing data, even in eventually consistent systems.
  • Use version numbers or timestamps so clients and services can detect stale or conflicting data.
  • Design conflict resolution up front: last-write-wins, merge rules or CRDTs.
  • Monitor replication lag and cache hit rates, and alert when lag grows.
  • Make the user experience honest about delays, for example "your changes may take a few seconds to appear everywhere".

11. Summary

  • Consistency defines what reads return after a write when data has multiple copies.
  • Models range from linearizable (behaves like one copy) through causal and session guarantees to eventual consistency.
  • Stronger models are easier to reason about but cost latency and availability; weaker models are faster but expose stale data.
  • Techniques include leaders, synchronous replication, quorums, consensus, versioning, sticky routing and CRDTs.
  • Choose consistency per feature, based on the cost of showing old data.

Good consistency design gives users correct answers where it matters and fast answers everywhere else. Open the FAQ tab for answers to common questions about consistency.