SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
  • Common Database Types
  • SQL vs NoSQL
  • ACID Transactions
  • B-Trees and B+ Trees
  • LSM Trees
  • Transaction Isolation Levels
  • Locking and MVCC
  • Normalization
  • OLTP vs OLAP
  • BASE and PACELC
  • Write-Ahead Log (WAL)
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Data and Storage/Database Basics

BASE and PACELC

The relaxed cousin of ACID, and a fuller rule than CAP that also counts latency.

⏱ 13 min readAdvancedInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

BASE and PACELC are two ways to think about what a big distributed database gives up to stay fast and available.

  • BASE is the relaxed cousin of ACID: Basically Available, Soft state, Eventually consistent. The system answers even when parts are broken, and copies agree later.
  • PACELC is a fuller version of the CAP theorem. If there is a Partition, choose Availability or Consistency. Else (when the network is fine), choose Latency or Consistency.
  • The second half is the big idea: even with no failure, strong consistency costs speed.

02Concept: What is it?

ACID databases promise strict rules: a transaction is all-or-nothing, and everyone sees correct data right away. That is hard to keep when data lives on many machines in many places. BASE is a different stance (it is a style of design, not a standard): accept some looseness in exchange for scale and uptime.

  • Basically Available: the system keeps answering most requests, even if some nodes are down. An answer might be slightly old, but you get one.
  • Soft state: the data can change even without new input, because copies are still catching up with each other in the background.
  • Eventually consistent: if no new writes arrive, all copies will end up the same, but not instantly.

The CAP theorem says that during a network partition a system must choose between consistency and availability. That is true, but partitions are rare. Most of the time the network works. PACELC (said "pass-elk") adds the missing question: when there is no partition, what do you trade? The answer is latency versus consistency. To be sure that every copy is up to date, a write must wait for the other copies to confirm, and that takes time.

PACELC as a decision tree
❓Is there a partition?
→↓yes: P
⚖️Choose A or Cstay available, or stay consistent
→↓no: E (else)
⏱️Choose L or Cstay fast, or stay consistent
Two questions. Each gives a letter. Together they give a label such as PA/EL.
🧠CAP is a small part of PACELC
CAP only speaks about the rare bad day. PACELC covers every day. Its "ELC" half explains why even a healthy system with several copies often answers a little stale, or a little slow.

03Real-Life Example

🍵Two Branches of a Bank
A bank has two branches with the same customer list. A customer changes their address at branch A. Option 1 (consistent, slower): the clerk phones branch B and waits for them to write it down before saying "done". Every branch always agrees, but each change takes longer. Option 2 (fast, eventually consistent): the clerk says "done" at once and posts a note to branch B. For an hour branch B still shows the old address, then it catches up. Now suppose the phone line is cut. With option 1, branch A must refuse the change (consistency over availability). With option 2, both branches keep working and may even record two different addresses to sort out later (availability over consistency).
Two bank branches
Distributed database
Branch A and branch B
Replica A and replica B
The phone line
The network between replicas
Phone line cut
A network partition (P)
Wait for B to confirm before saying done
Synchronous replication: consistent, slower
Say done now, post a note to B
Asynchronous replication: fast, eventually consistent
Branch B shows the old address for a while
A stale read (soft state)
Two different new addresses recorded
A write conflict to resolve

04Why Do We Need It?

🌍Scale across the world
Strict rules need constant coordination between machines, which gets slow and fragile over long distances.
🟢Stay up
A BASE system can keep serving users while some nodes or links are down.
⚡Low latency
Answering from the nearest copy, without waiting for far-away replicas, is much quicker.
🧭A clearer vocabulary
PACELC makes you say out loud what you give up in normal times, not only during failures.
📚Better comparisons
It helps you compare databases honestly: what is their default when the network breaks, and when it does not?
🎯Fit to the product
A like counter can be loose. A bank balance cannot. The model helps you decide for each case.
Consistency is never free. During a partition it costs availability, and the rest of the time it costs latency.

05Where Do We Use It?

🗄️Choosing a database
Dynamo-style and wide-column stores are usually described as leaning to availability and low latency. Strongly consistent stores lean the other way.
⚙️Tuning one database
Many databases let you choose per request: how many replicas must acknowledge a write or a read.
❤️Social features
Likes, view counts and follower numbers can be slightly out of date without harm.
🛒Shopping carts
Accepting an add-to-cart even during a failure is often better than refusing it.
💳Payments and stock
Money and the last item in stock need strong consistency, so you accept slower or refused requests.
🗣️Design interviews
A very common way to explain your database choice with real trade-offs.

06Types / Parts / How It Works

ACID and BASE side by side

ACIDBASE
Main goalCorrectnessAvailability and scale
ConsistencyStrong, right awayEventual
Typical homeSingle-node or tightly coordinated databasesLarge distributed NoSQL stores
TransactionsFull multi-row, all-or-nothingOften limited to one item or partition
On failureMay refuse requests to stay correctKeeps answering, may be stale
MindsetPrevent bad statesAllow them briefly, then repair

The four PACELC labels

LabelIn a partitionOtherwiseRough meaning
PA/ELAvailableLow latencyFast and always on, accepts stale reads. Dynamo-style stores are often described this way.
PC/ECConsistentConsistentAlways correct. Pays with refused requests in a partition and slower writes.
PA/ECAvailableConsistentKeeps working in a partition, but strict when all is well.
PC/ELConsistentLow latencyStrict in a partition, fast otherwise. A less common mix.
⚠️Labels are rough
Real products are often configurable, and the same product can behave differently with different settings or versions. Use the labels to start a conversation, not to end one.

Where the latency cost comes from

Synchronous or asynchronous copying
Wait for the replica (EC)
🗄️A
↔round trip
🗄️B
Write is slower, every read is fresh.
Reply first, copy later (EL)
🗄️A
⇢⇣in background
🗄️B
Write is fast, a read from B may be stale.
Consistent Low latency
Waiting for the far replica adds a whole round trip to every write.
VisualizerPACELC explorer: cut the network, then choose what to give upCut the network and flip between Consistency and Availability. Then heal it and flip between Consistency and Low latency. Slide the read time earlier to catch a stale read, and turn on the second write to see a conflict.
The network between A and B is
If there is a partition, favour
Otherwise, favour
A client writes x = 2 to replica A. Then a reader asks replica B. Both started with x = 1.
✍️Writerx = 2
→↓write
🗄️Replica Ax = 2 · write accepted
↔link cut ✂
🗄️Replica Bx = 1 · old copy
←read
👀Reader
Your label
PA/EL
PACELC
Write
Accepted
2 ms to say OK
Read from B
Stale
x as B sees it
The link is cut and you chose availability (PA). A accepted the write and B still answers reads, but B shows the old value until the link is back and the change is copied across. Everyone gets an answer, though some answers are stale.
PA/EL: Always available and fast, and accepts stale reads. Dynamo-style stores are often described like this. Real products are often configurable, so treat labels like these as rough descriptions.

A simplified model with made-up illustrative numbers: a write inside one data centre takes 2 ms, and a copy needs about half the round trip to reach the other side. Nothing here is random.

07How to Use It / Steps / Implementation

Using these ideas to choose

  1. 1
    List what must never be wrong
    Money, stock for the last item, unique usernames. These need strong consistency, and you accept the cost.
  2. 2
    List what can be a little old
    Counters, feeds, recommendations and 'last seen'. These can use eventual consistency.
  3. 3
    Decide the partition behaviour
    For each feature, ask: if the network breaks, should we refuse the request (PC) or answer and fix later (PA)?
  4. 4
    Decide the normal-time behaviour
    When all is well, do we wait for replicas (EC) or answer fast (EL)? Check how much latency you can afford.
  5. 5
    Tune per request if you can
    Many databases let you pick how many replicas must confirm. Use strong settings only where needed.
  6. 6
    Plan the repair
    If you allow conflicts, choose how to settle them: last write wins, merging, or asking the user.
  7. 7
    Tell the user the truth
    Show 'saving...' or 'may take a moment to update' where data can be briefly old.
💡Mix and match
One product can have both kinds of data. Keep the money in a strongly consistent store and the activity feed in an eventually consistent one.

08Key Terms to Know

TermMeaning in easy words
BASEBasically Available, Soft state, Eventually consistent: a relaxed style of design for big systems
Basically availableThe system keeps answering most requests even when parts have failed
Soft stateStored data may still be changing as copies catch up, even with no new writes
Eventual consistencyIf writes stop, all copies will agree after some time
PACELCIf Partition: Availability or Consistency. Else: Latency or Consistency
Network partitionA break in the network that splits machines into groups that cannot talk
Synchronous replicationThe write waits until the replicas confirm it
Asynchronous replicationThe write is confirmed first, and copied in the background
Stale readA read that returns an older value than the latest write
Write conflictTwo copies accepted different changes to the same item and now disagree
Last write winsA simple conflict rule that keeps the change with the latest timestamp

09Pros, Cons and Trade-offs

✅ Pros
  • Keeps the system up during failures
  • Fast writes and reads from the nearest copy
  • Scales to many machines and regions
  • Gives a clear way to talk about trade-offs
  • Lets you relax rules only where it is safe
⚠️ Cons
  • Users may see old data
  • Conflicts must be detected and settled
  • Harder to reason about and to test
  • Not suitable for money or unique constraints without extra care
  • Labels are rough and can mislead

Trade-offs

ChoiceWe gainWe lose
PC in a partitionNo wrong answersSome requests are refused
PA in a partitionEveryone is servedStale reads and possible conflicts
EC in normal timesFresh reads, simple thinkingSlower writes (a round trip to replicas)
EL in normal timesFast writes and readsBrief staleness after each write
Per-request tuningStrictness only where neededMore settings, and more room for mistakes
Last write winsSimple repairA concurrent update can be silently lost

10Common Problems and Mistakes

Common mistakes

  1. Thinking CAP is the whole story. It covers only the rare partition. Most trade-offs happen every day, in the ELC half.
  2. Treating labels as facts. Real databases are configurable, so "this database is AP" is a rough guide at best.
  3. Using eventual consistency for money. Two withdrawals against one balance can both succeed.
  4. Ignoring conflicts. If two sides can accept writes, you need a plan for what happens when they disagree.
  5. Forgetting read-your-own-writes. A user saves a change, reloads, and sees the old one. Keep their reads on a fresh copy for a while.
  6. Calling "eventually" a guarantee of speed. It says copies will agree, not when.

Things to watch

⏳Replication lag
Measure how stale reads can get, and alert when the lag is too long.
⚔️Conflicts
Count how often they happen and how they are resolved.
🌐Distance
The farther the replicas, the larger the latency cost of strong consistency.
🧪Failure tests
Cut the network on purpose in a test, and see what your system really does.

11Real-World Examples

🛒Shopping carts
The classic example for the Dynamo approach: always accept an add-to-cart, and merge carts later if they diverge.
❤️Likes and counters
A like count that is a few seconds old harms nobody, and it is far cheaper to serve.
🏦Bank transfers
Strongly consistent systems are chosen here, even though they refuse or slow down requests during problems.
🌍Global apps
Replicas in many regions make strong consistency expensive, because of the round trips between continents.
📝Collaborative docs
Edits are accepted locally and merged later, which is an availability-first design.
📦Inventory
A product page can show an approximate stock count. The checkout step checks the exact count.
📝Note
Which behaviour a database has depends on its settings and version. Always check the documentation for the exact guarantees.
Mini case: one product, two kinds of data
🛍️Product pagestock count: 'about 12'
→↓eventual, fast
🗄️Replicated storeEL
→↓then at checkout
🔒Strongly consistent storeEC: exact stock
Each part of the app gets the consistency it needs, and no more.

12Related Topics to Read Next

CAP Theorem→

The first half of the story: what happens during a partition.

Consistency Models→

The many levels between strong and eventual.

ACID Transactions→

The strict model that BASE relaxes.

Replication Models→

Leader-follower, multi-leader and leaderless choices.

Quorum (R + W > N)→

A dial for trading speed against freshness.

Replication Lag→

The delay that causes stale reads.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔BASE: basically available, soft state, eventually consistent.
  • ✔PACELC: if Partition → A or C. Else → L or C.
  • ✔Hidden cost: strong consistency means waiting for replicas, so higher latency.
  • ✔PA/EL: fast and always on, may be stale. PC/EC: always right, slower, may refuse.
  • ✔Money and unique rules: choose consistency. Counters and feeds: eventual is fine.
  • ✔Conflicts: plan the repair (last write wins, merge, ask).
  • ✔Labels are rough: products are configurable, so check the docs.
  • ✔One line: “Consistency always costs something: availability in a partition, and latency the rest of the time.”
← Previous
OLTP vs OLAP
Next →
Write-Ahead Log (WAL)