PACELC and Consistency Models
Overview
CAP only talks about failures, but systems spend almost all their time healthy. PACELC extends CAP to cover that normal time, where the trade-off is speed versus freshness.
You will also learn the two consistency levels you will use most: strong and eventual.
Detailed Notes
What is PACELC
PACELC reads like a sentence:
If there is a Partition, choose Availability or Consistency; Else (no partition), choose Latency or Consistency.
The first half is CAP. The second half (the "ELC" part) is new: even with a perfectly healthy network, there is a trade-off between latency (how fast you respond, from the Latency and Performance chapter) and consistency.
The problem it solves
CAP says nothing about everyday behaviour, yet that is what users feel. Replicas are often in different cities, and a message between them takes real time. Keeping every copy perfectly in sync before answering is slow. CAP cannot explain why some databases are slower but always exact, while others are fast but sometimes stale. PACELC can.
How it works
When you write data to a system with replicas, you have two options:
- Wait for all replicas to confirm before replying. Every reader then sees the latest value (strong consistency), but the write is slower because it waits for the farthest replica.
- Reply after one copy has it and copy to the others in the background. This is fast, but a reader hitting another replica may briefly see old data. This is eventual consistency: if no new writes come, all replicas will eventually agree.
Between them sit middle options, for example waiting for a quorum (a majority) of replicas, which is a tunable balance.
Systems are often labelled with both halves:
- PA/EL: available during partitions, fast otherwise (accepts stale reads). Typical for Cassandra-style and Dynamo-style stores in their default settings.
- PC/EC: consistent in both situations, paying with errors during partitions and extra latency normally. Typical for strongly consistent distributed databases such as Google Spanner.
Many databases let you choose per request. For example, DynamoDB offers eventually consistent reads by default and strongly consistent reads as an option.
A simple example
You post a photo, then immediately refresh your own profile. With strong consistency you always see the photo. With eventual consistency your refresh might hit a replica that has not received it yet, and the photo appears a second later. Your friends will not notice a one-second delay, but you might.
System design example
A social app with a primary database and read replicas (Leader and Follower chapter):
- Profile edits and payments: read from the leader or use strongly consistent reads. Slightly slower, always correct.
- Feeds and like counts: read from nearby replicas or a cache. Very fast, possibly a little stale, which is fine.
- "Read your own writes" trick: right after a user writes something, serve that user's reads from the leader for a short time, while everyone else uses replicas.
The question to ask in an interview: "How stale can this data be before the user is harmed?"
Summary
- PACELC = CAP during a Partition, plus Latency-versus-Consistency Else (when healthy).
- Strong consistency means always fresh but slower; eventual consistency means fast but briefly stale.
- Quorum reads and writes give a tunable middle ground.
- Choose the level per feature based on how harmful stale data would be.
Architecture Diagram
Waiting for more replicas gives fresher data but slower responses.
- 1The client writes to the primary.
- 2Strong: the primary waits for replicas to confirm, then replies (slower, always fresh).
- 3Eventual: the primary replies at once and copies in the background (faster, briefly stale).
Common Interview Questions
Chapter quiz
CAP and PACELC · 5 questions
1.What does CAP say happens during a network partition?
2.A CP system during a partition typically:
3.Which feature best suits an AP design?
4.What does the "ELC" part of PACELC describe?
5.Why is eventual consistency often faster?
0 of 5 answered
Finished this lesson?
0 of 91 lessons done · 0% of the course

