Consistency Patterns

Understanding consistency models is critical for system design interviews. Know the spectrum from eventual to linearizable.

CAP Theorem — The Foundation

C
Consistency
Every read gets the latest write
A
Availability
Every request gets a response
P
Partition Tolerance
System works despite network splits
CP Systems (Consistency + Partition)
Reject writes during partition. Examples: ZooKeeper, HBase, MongoDB (default).
Use for: banking, inventory, leader election.
AP Systems (Availability + Partition)
Allow writes during partition, resolve conflicts later. Examples: Cassandra, DynamoDB, CouchDB.
Use for: social media, CDN, DNS, shopping carts.

Consistency Spectrum

Weakest (Fastest)Strongest (Slowest)
High AvailabilityHigh Consistency

Guarantee

All replicas will eventually be the same. During convergence, reads may return stale data.

Example

You 'like' a post. The count shows 99 on your screen but 98 on your friend's screen. Eventually both show 100.

Use Cases

Like/view counters (close enough is fine)DNS propagationSearch index updatesRecommendation engine dataCDN cache invalidation

Trade-off

Fastest and most available. Works during partitions (AP choice). Good enough for 90% of use cases.

Interview Cheat Sheet

1."For this system, I'd choose eventual consistency because users can tolerate a few seconds of stale data for likes/views, and it gives us higher availability."
2."For the payment service, we need strong consistency. We can't have two charges for the same order. We'll use a CP database with quorum writes."
3."We use read-your-writes so that after a user updates their profile, they see their own changes immediately. Other users can see eventual consistency."
4."For conflict resolution in our distributed cache, we use LWW with vector clocks to detect conflicts and merge concurrent updates."