System Design/
Lesson

Consistency is a dial, not a switch. Picking the right level for each feature is one of the most important decisions you will make.

The consistency spectrum

Consistency LevelGuaranteeLatencyCostExample Use Case
Strong (Linearizability)Every read returns the latest writeHighVery highBank transfers, inventory counts
SequentialAll operations appear in some total order consistent with each client's orderMedium-highHighDistributed locks, leader election
CausalOperations that are causally related are seen in order; concurrent operations may appear in any orderMediumMediumChat messages, comment threads
Read-your-writesA client always sees its own writesLow-mediumLow-mediumUser profile updates, form submissions
EventualAll replicas converge to the same value, eventuallyLowLowLike counts, view counters, DNS
02

Strong consistency (linearizability)

The system behaves as if there is a single copy of the data. Every read returns the value of the most recent completed write.

Claude Code
Timeline:
  Client A: Write(balance = 100)  --completes-->
  Client B:                        Read(balance) --> 100  (guaranteed)

Never this:
  Client A: Write(balance = 100)  --completes-->
  Client B:                        Read(balance) --> 50   (impossible with strong consistency)

Systems achieve this through consensus protocols like Paxos or Raft. Every write must be acknowledged by a majority of nodes before it is committed. The cost is real: Google Spanner uses synchronized atomic clocks (TrueTime) and still has write latencies of 10-15ms within a region.

When to use it: Financial transactions, inventory management, booking systems, anything where stale data causes real harm.

03

Eventual consistencyWhat is eventual consistency?A guarantee that all copies of data will converge to the same value given enough time, rather than being instantly synchronized after every write.

The most relaxed guarantee: if you stop writing, all replicas converge to the same value. In practice, convergence usually takes milliseconds to seconds.

Claude Code
Timeline:
  Client A: Write(likes = 42) to Replica 1
  Client B: Read(likes) from Replica 2 --> 41  (stale, but OK for likes)
  ... 200ms later ...
  Client B: Read(likes) from Replica 2 --> 42  (caught up)

Writes go to one node and replicate asynchronously. During the replication window, different clients may see different values.

When it is fine: Like counts, analytics data, DNSWhat is dns?The system that translates human-readable domain names like google.com into the numerical IP addresses computers use to find each other. propagation, CDNWhat is cdn?Content Delivery Network - a network of servers around the world that caches your files and serves them from the location closest to the user, making pages load faster. content delivery, search indexes.

When it is dangerous: Bank balances, limited inventory, seat reservations, unique username registration, security permission revocation.

04

Causal consistency

Preserves cause-and-effect: if operation A influenced operation B, everyone sees A before B. Concurrent (unrelated) operations can appear in any order.

Claude Code
Causal relationship:
  Alice posts: "Anyone want to grab lunch?"     (Message 1)
  Bob replies: "Sure, where?"                    (Message 2, caused by Message 1)

Guarantee: Everyone sees Message 1 before Message 2.

Concurrent (no causal link):
  Alice posts: "Anyone want to grab lunch?"
  Carol posts: "Check out this article"

No guarantee on ordering - they're unrelated, and that's fine.

This is the sweet spot for collaborative applications: chat, social feeds, document editors. You preserve logical ordering without paying the full cost of strong consistency. MongoDB (since 3.6) supports causal consistency sessions.

05

Read-your-writes consistency

A client always sees its own writes. You update your profile picture, refresh the page, and see the new picture, even if other users briefly see the old one.

Claude Code
You: Update(avatar = new_photo.jpg) --> OK
You: Read(avatar) --> new_photo.jpg    (guaranteed, you see your own write)
Others: Read(avatar) --> old_photo.jpg  (may be stale briefly)

Cheap to implement: route reads from a client to the replica that received their write, or track write timestamps and only return reads at least that fresh. This eliminates the most confusing UX, making a change that seems like it did not work.

06

Mixing consistency levels in practice

Real systems choose per feature. Here is how an e-commerce platform might break it down:

FeatureConsistency LevelWhy
Product inventoryStrongOverselling is expensive and damages trust
Order processingStrongDouble-charging or lost orders are unacceptable
Product reviewsEventualA review appearing a few seconds late is fine
Shopping cartRead-your-writesUser must see items they just added, others don't need to
Chat with supportCausalMessages must appear in conversation order
Payment processingStrongMoney must be handled with the strongest guarantees
Search resultsEventualIndex lag of a few seconds is acceptable
07

The cost of strong consistency

Claude Code
Eventual    --> 1-5ms   reads (read from nearest replica)
Causal      --> 5-20ms  reads (may need to check ordering)
Strong      --> 20-100ms reads (must confirm with majority)

These numbers are hand-wavy but directionally correct for
a multi-region deployment.

At 100,000 reads per second, the difference between 2ms and 50ms per read is the difference between 10 servers and 250 servers. Default to the weakest consistency level that is safe for each feature.

08

How to choose

  1. What happens if a user sees stale data for 1 second? If "nothing bad," use eventual consistencyWhat is eventual consistency?A guarantee that all copies of data will converge to the same value given enough time, rather than being instantly synchronized after every write..
  2. Does the operation involve money, inventory, or security? If yes, use strong consistency.
  3. Does ordering between related operations matter? If yes, use causal consistency. If only the writer's experience matters, read-your-writes is enough.
AI pitfall
AI loves to recommend strong consistency everywhere "to be safe." What it gets wrong is the cost: strong consistency across regions adds 100-200ms to every operation. For a social feed or product listing, that latency is unacceptable and unnecessary. Let AI draft your consistency choices, then downgrade every feature where stale data is harmless.
Good to know
"Eventual" does not mean "slow." In most systems, eventual consistency converges in milliseconds, not seconds. The replication lag between DynamoDB nodes is typically under 50ms. "Eventually consistent" sounds scary, but for the vast majority of read operations, the data is already up to date by the time someone reads it.
Edge case
Read-your-writes consistency can break in unexpected ways with CDN caching. If a user updates their profile and the next page load is served from a CDN cache, they see the old data. The fix: either bypass the CDN for authenticated pages or use cache-busting headers after writes.