Nextgen Blog
HomeLearnAIQuantumRoboticsSecuritySpaceAbout
Nextgen Blog

By Anubhav — full stack engineer, IIT Mandi CSE. Deep dives into AI, software engineering, and the technologies shaping the next generation of tech.

Navigate

  • Home
  • Learn
  • Blog
  • Archive
  • About

Topics

  • Artificial Intelligence
  • Quantum Computing
  • Robotics
  • Cybersecurity
  • Space Tech

Connect

Built with ❤️ & By - Anubhav

© 2026 Nextgen Blog by Anubhav. All rights reserved.

Privacy PolicyTerms of Service
Phase 05 · Distributed Systems & ConsensusChapter 25 of 33
24.
Phase 05Read time ~21 minDifficulty advanced

CAP Theorem

In this chapter
  • 01Chapter Overview
  • 02Why CAP Exists
  • 03What Is Consistency?
  • 04Important distinction
  • 05Linearizability Intuition
  • 06What Is Availability?
  • 07What Is a Network Partition?
  • 08Why Partitions Matter
  • 09The CAP Scenario
  • 10CAP Theorem Precisely
  • 11What Does "Choose Two" Mean?
  • 12CP Systems
  • 13AP Systems
  • 14CP vs AP
  • 15A Simple Bank Example
  • 16An AP-Friendly Example
  • 17CAP and Quorum Systems
  • 18Read and Write Quorums
  • 19CAP vs Eventual Consistency
  • 20CAP
  • 21Eventual consistency
  • 22CAP vs ACID
  • 23ACID
  • 24CAP
  • 25CAP vs PACELC
  • 26Common CAP Misconception #1
  • 27Wrong
  • 28Better
  • 29Common CAP Misconception #2
  • 30Wrong
  • 31Better
  • 32Common CAP Misconception #3
  • 33Wrong
  • 34Common CAP Misconception #4
  • 35Wrong
  • 36Common CAP Misconception #5
  • 37Wrong
  • 38Real-World Architecture Decision
  • 39CAP Decision Framework
  • 40Question 1 — What happens during a partition?
  • 41Question 2 — Is stale data acceptable?
  • 42Question 3 — Are conflicting writes acceptable?
  • 43Question 4 — Can operations be retried?
  • 44Question 5 — Can the business tolerate temporary failure?
  • 45Failure Scenario Walkthrough
  • 46CAP in Multi-Region Systems
  • 47Option A — Stop some writes
  • 48Option B — Continue writes independently
  • 49Conflict Resolution
  • 50CAP and Idempotency
  • 51CAP and Timeouts
  • 52CAP and Failure Handling
  • 53Operation-Specific Consistency
  • 54CAP Is About Trade-offs, Not Product Labels
  • 55CAP Interview Example
  • 56Question
  • 57Answer
  • 58CAP Interview Question
  • 59Question
  • 60Answer
  • 61CAP Interview Question
  • 62Question
  • 63Answer
  • 64CAP Interview Question
  • 65Question
  • 66Answer
  • 67CAP Interview Question
  • 68Question
  • 69Answer
  • 70CAP Interview Question
  • 71Question
  • 72Answer
  • 73Practical System Design Checklist
  • 74Mini Design Exercise
  • 75Mental Model
  • 76Summary
  • 77Exercises
  • 78Exercise 1
  • 79Exercise 2
  • 80Exercise 3
  • 81Exercise 4
  • 82Exercise 5
  • 83Mini Project
  • 84Production Checklist
  • 85Interview Master Answer
  • 86Next Chapter
  • 87Chapter 24 — Consistency Models
In this chapter (87 sections)
01Chapter Overview02Why CAP Exists03What Is Consistency?04Important distinction05Linearizability Intuition06What Is Availability?07What Is a Network Partition?08Why Partitions Matter09The CAP Scenario10CAP Theorem Precisely11What Does "Choose Two" Mean?12CP Systems13AP Systems14CP vs AP15A Simple Bank Example16An AP-Friendly Example17CAP and Quorum Systems18Read and Write Quorums19CAP vs Eventual Consistency20CAP21Eventual consistency22CAP vs ACID23ACID24CAP25CAP vs PACELC26Common CAP Misconception #127Wrong28Better29Common CAP Misconception #230Wrong31Better32Common CAP Misconception #333Wrong34Common CAP Misconception #435Wrong36Common CAP Misconception #537Wrong38Real-World Architecture Decision39CAP Decision Framework40Question 1 — What happens during a partition?41Question 2 — Is stale data acceptable?42Question 3 — Are conflicting writes acceptable?43Question 4 — Can operations be retried?44Question 5 — Can the business tolerate temporary failure?45Failure Scenario Walkthrough46CAP in Multi-Region Systems47Option A — Stop some writes48Option B — Continue writes independently49Conflict Resolution50CAP and Idempotency51CAP and Timeouts52CAP and Failure Handling53Operation-Specific Consistency54CAP Is About Trade-offs, Not Product Labels55CAP Interview Example56Question57Answer58CAP Interview Question59Question60Answer61CAP Interview Question62Question63Answer64CAP Interview Question65Question66Answer67CAP Interview Question68Question69Answer70CAP Interview Question71Question72Answer73Practical System Design Checklist74Mini Design Exercise75Mental Model76Summary77Exercises78Exercise 179Exercise 280Exercise 381Exercise 482Exercise 583Mini Project84Production Checklist85Interview Master Answer86Next Chapter87Chapter 24 — Consistency Models

1. Chapter Overview#

The CAP Theorem is one of the most important ideas in distributed system design.

It helps us reason about what happens when a distributed system experiences a network partition and multiple nodes can no longer reliably communicate with each other.

CAP stands for:

  • C — Consistency
  • A — Availability
  • P — Partition Tolerance

The central idea is:

In a distributed system, when a network partition occurs, you cannot simultaneously guarantee both strong consistency and availability.

This chapter builds CAP from first principles instead of treating it as a memorized acronym.


2. Why CAP Exists#

Imagine a database with two replicas:

              ┌──────────────┐
              │ Application  │
              └──────┬───────┘
                     │
              ┌──────┴───────┐
              │ Load Balancer│
              └──────┬───────┘
                     │
             ┌───────┴────────┐
             │                │
        ┌────▼────┐      ┌────▼────┐
        │ Node A  │      │ Node B  │
        │ balance │      │ balance │
        │  ₹100   │      │  ₹100   │
        └─────────┘      └─────────┘

Normally:

  1. A request updates Node A.
  2. Node A communicates with Node B.
  3. Both replicas eventually or immediately contain the new value.

Now suppose the network between A and B breaks:

        Node A       X       Node B
       balance=100  / \     balance=100
 
              NETWORK PARTITION

The system now has a difficult choice.

Should Node A:

  • continue accepting requests independently?

Or should it:

  • stop accepting requests until it can communicate with Node B?

If it continues accepting requests, availability improves, but replicas may disagree.

If it stops accepting requests, consistency can be protected, but availability decreases.

This is the core problem CAP describes.


3. What Is Consistency?#

In CAP, consistency has a specific distributed-systems meaning.

A useful intuition is:

Every successful read should see the most recent successful write according to a single valid ordering.

For example:

Initial:
balance = 100
 
Write:
balance = 50
 
Immediately after successful write:
 
Read → 50

A strongly consistent system should not successfully return:

Read → 100

after the system has acknowledged the write of 50, assuming the read is required to observe the latest committed value.

This idea is closely related to linearizability.

Important distinction#

CAP consistency is often simplified as:

"All nodes have the same data."

That is not precise enough.

The important issue is what clients are allowed to observe during concurrent distributed operations.

Two replicas can temporarily contain different internal states without necessarily violating every possible consistency model.


4. Linearizability Intuition#

To understand CAP consistency better, learn the idea of linearizability.

Suppose:

Client A:
write X = 20
 
Client B:
read X

If the write completes before the read begins, a linearizable system should make the read observe:

X = 20

The system behaves as though operations happened atomically in a single valid order.

Think of it as:

           Real-time order
                ↓
 
Write X=20 ──────────────► Read X
 
                         returns 20

This is stronger than merely saying that replicas will eventually converge.


5. What Is Availability?#

In CAP, availability means that:

Every request to a non-failing node receives a response.

That response does not necessarily have to contain the newest possible data under every interpretation.

The important point is that the system continues responding.

For example:

Node A ─────── Network Partition ─────── Node B
  │                                      │
  │                                      │
Request                                Request
  │                                      │
Response                                Response

If both sides continue responding, the system is maintaining availability.

If one side refuses requests because it cannot coordinate safely, availability is reduced.


6. What Is a Network Partition?#

A network partition occurs when nodes that should communicate cannot reliably communicate.

For example:

Cluster
 
A ───── B
 
C ───── D

Suppose the network splits:

A ─── B        C ─── D
       X
       X
       X

The nodes may still be alive.

The problem is communication.

This distinction is extremely important:

A network partition is not necessarily a server crash.

The machines can be healthy while the network between them is broken.


7. Why Partitions Matter#

Distributed systems depend on communication.

Suppose:

Replica A
balance = ₹100
 
Replica B
balance = ₹100

A user sends:

Withdraw ₹80

The system needs to determine whether the operation is allowed.

Normally:

A checks balance
        ↓
A updates balance
        ↓
B learns about update

During a partition:

A              X              B
│                             │
│   cannot communicate        │
│                             │

Now both sides may receive requests.

If both accept independently, conflicting states can occur.


8. The CAP Scenario#

Consider two replicas:

        ┌─────────┐
        │ Node A  │
        └────┬────┘
             │
             X
             │
        ┌────┴────┐
        │ Node B  │
        └─────────┘

The network between them is partitioned.

A client sends:

Write X = 10

to Node A.

Another client sends:

Write X = 20

to Node B.

If both nodes continue accepting writes:

Node A → X = 10
Node B → X = 20

The replicas disagree.

If the system instead prevents one or both sides from accepting operations until coordination is restored, consistency can be preserved at the expense of availability.

That is the CAP trade-off.


9. CAP Theorem Precisely#

A practical formulation is:

When a network partition occurs, a distributed data system must choose between preserving strong consistency and preserving availability.

Therefore:

During partition:
 
        Consistency
             │
             │
             │
             └────────────── Availability

You cannot guarantee both strong consistency and availability during the partition.


10. What Does "Choose Two" Mean?#

You may have seen:

CAP = choose any two of C, A, P.

This is a useful beginner mnemonic, but it can be misleading.

The more accurate interpretation is:

  • Partition tolerance is generally necessary in a genuinely distributed system where network failures are possible.
  • When a partition occurs, the practical choice is usually between:
    • stronger consistency
    • continued availability

So instead of thinking:

Pick 2 out of 3

think:

A partition happens
        ↓
Can we still serve requests?
        │
    ┌───┴────┐
    │        │
   Yes       No
    │        │
Availability Consistency-oriented

11. CP Systems#

A CP system chooses:

  • Consistency
  • Partition tolerance

during a partition.

It sacrifices some availability.

Conceptually:

Partition
    ↓
Cannot safely coordinate
    ↓
Reject / delay some requests
    ↓
Protect consistency

Example:

Client
  │
  ▼
Node A ───── X ───── Node B
 
Node A cannot safely confirm
the required distributed state.
 
Request → reject / wait

This is useful when returning stale or conflicting data is unacceptable.

Examples of workloads that may favor this approach include:

  • distributed locking
  • leader-based coordination
  • strongly consistent metadata
  • financial state where correctness requirements are strict

The exact CAP classification of a real database depends on its configuration, operation type, failure mode, and consistency guarantees.


12. AP Systems#

An AP system chooses:

  • Availability
  • Partition tolerance

during a partition.

It continues serving requests even when nodes cannot communicate.

Conceptually:

Partition
    ↓
Nodes continue operating
    ↓
Clients receive responses
    ↓
Replicas may temporarily diverge
    ↓
Reconciliation later

For example:

Node A → value = 10
 
Node B → value = 20

After communication is restored:

       reconciliation
             ↓
       common state

This approach can be useful when:

  • temporary staleness is acceptable
  • the system must continue operating across failures
  • eventual convergence is acceptable

Again, real systems often expose configurable consistency levels rather than fitting perfectly into a single permanent CAP label.


13. CP vs AP#

Property CP Approach AP Approach
Partition tolerance Yes Yes
Strong consistency during partition Prioritized Sacrificed
Availability during partition May decrease Prioritized
Stale data Minimized May occur
Conflicting writes Avoided/restricted May require reconciliation
Typical use Coordination, strict state Highly available distributed data

Neither category is universally correct.

The appropriate design depends on business requirements.


14. A Simple Bank Example#

Suppose:

Account balance = ₹1,000

Two replicas:

Replica A = ₹1,000
Replica B = ₹1,000

Network partition occurs.

Two withdrawals arrive:

User 1 → withdraw ₹800 → Replica A
User 2 → withdraw ₹800 → Replica B

If both replicas independently approve:

A → balance = ₹200
B → balance = ₹200

The combined system has approved:

₹1,600

from an account containing:

₹1,000

This illustrates why some operations cannot simply favor availability without additional coordination or business-specific conflict handling.


15. An AP-Friendly Example#

Consider a social media "like" counter.

Suppose:

Post likes = 10,000

A network partition occurs.

One region sees:

10,010

Another sees:

10,015

For many systems, temporarily showing:

10,010

instead of:

10,015

is acceptable.

The system can continue serving users and reconcile updates later.

The business requirement is very different from preventing duplicate financial withdrawals.


16. CAP and Quorum Systems#

Quorums provide an important mechanism for reasoning about distributed replicas.

Suppose there are:

N = 3 replicas

A system may require:

Write quorum = 2
Read quorum = 2

Because:

W + R > N

we have:

2 + 2 > 3

Therefore the read and write quorums overlap.

Conceptually:

Replica 1 ──┐
Replica 2 ──┼── Write quorum
Replica 3 ──┘
 
Replica 2 ──┐
Replica 3 ──┼── Read quorum
             ┘

At least one replica overlaps.

However, quorum arithmetic alone does not automatically make a system fully linearizable.

The actual semantics depend on:

  • quorum rules
  • versioning
  • conflict resolution
  • read/write protocols
  • failure handling
  • clocks or logical versions
  • leader/consensus mechanisms

17. Read and Write Quorums#

For:

N = 5

Possible settings:

W = 3
R = 3

Then:

W + R = 6 > 5

This provides overlap.

But if:

W = 1
R = 1

then:

W + R = 2

There is no guaranteed overlap.

This can increase availability and reduce latency but may increase the chance of stale reads.


18. CAP vs Eventual Consistency#

These concepts are related but not identical.

CAP#

Describes a fundamental trade-off during a network partition between:

  • strong consistency
  • availability

Eventual consistency#

Describes a consistency model in which:

If no new updates occur and communication continues, replicas eventually converge.

Example:

t1:
A = 10
B = 10
 
t2:
A = 20
B = 10
 
t3:
A = 20
B = 20

The system was temporarily inconsistent but eventually converged.


19. CAP vs ACID#

CAP and ACID answer different questions.

ACID#

ACID describes transactional properties:

  • Atomicity
  • Consistency
  • Isolation
  • Durability

CAP#

CAP describes distributed-system behavior under network partition.

A useful distinction:

ACID
 ↓
Transaction semantics
 
CAP
 ↓
Distributed failure trade-offs

Do not confuse CAP's Consistency with ACID's Consistency.

They refer to different concepts.


20. CAP vs PACELC#

CAP focuses on what happens during a partition.

PACELC extends this reasoning.

A simplified form is:

If there is a Partition, choose between Availability and Consistency; Else, choose between Latency and Consistency.

Therefore:

                    System
                       │
              ┌────────┴────────┐
              │                 │
          Partition?        No Partition
              │                 │
           A or C            L or C

Where:

  • P = Partition
  • A = Availability
  • C = Consistency
  • E = Else
  • L = Latency

This explains why even when the network is healthy, systems still make consistency-vs-latency trade-offs.


21. Common CAP Misconception #1#

Wrong#

"CAP means a system can only ever have two of the three properties."

Better#

Partition tolerance is not usually a feature you simply turn off in a real distributed system.

The practical question is:

What does the system do when a partition actually happens?


22. Common CAP Misconception #2#

Wrong#

"AP means the system has no consistency."

Better#

AP systems can provide meaningful consistency guarantees.

They may sacrifice strong consistency during partitions while still providing weaker models such as eventual consistency or other session guarantees.


23. Common CAP Misconception #3#

Wrong#

"CP means the system is never available."

No.

CP means availability may be sacrificed during a partition in order to preserve the chosen consistency guarantee.

When there is no partition, the system can still be highly available.


24. Common CAP Misconception #4#

Wrong#

"CAP is only about databases."

No.

The underlying trade-off applies to distributed systems more broadly.

It is particularly useful for reasoning about:

  • distributed databases
  • coordination systems
  • replicated state
  • distributed metadata
  • service architectures

25. Common CAP Misconception #5#

Wrong#

"A server being down is a network partition."

Not necessarily.

A server crash is different from a communication failure.

A partition means:

Nodes cannot reliably communicate.

The nodes themselves may still be running.


26. Real-World Architecture Decision#

Suppose you are designing an inventory system.

Requirement:

Never sell more units than are actually available.

You might prioritize:

Strong consistency
        +
Coordination
        +
Partition-aware failure handling

Now consider a product-view counter.

Requirement:

It is okay if the count is temporarily slightly stale.

You can prioritize:

Availability
        +
Partition tolerance
        +
Eventual convergence

The key skill in system design is not memorizing "CP vs AP."

The key skill is translating business requirements into consistency requirements.


27. CAP Decision Framework#

When designing a system, ask:

Question 1 — What happens during a partition?#

Can the system continue operating?

Question 2 — Is stale data acceptable?#

If yes, availability-oriented designs become possible.

Question 3 — Are conflicting writes acceptable?#

If no, stronger coordination may be required.

Question 4 — Can operations be retried?#

If yes, idempotency becomes important.

Question 5 — Can the business tolerate temporary failure?#

Some systems should fail closed rather than return potentially incorrect state.


28. Failure Scenario Walkthrough#

Consider three replicas:

        A
       / \
      /   \
     B-----C

Suppose:

A ↔ B     works
B ↔ C     fails
A ↔ C     fails

Now imagine a write request reaches A.

A may not be able to establish the required coordination with B and C.

A consistency-oriented design might:

reject request

An availability-oriented design might:

accept request locally

These choices have different consequences.


29. CAP in Multi-Region Systems#

Consider:

        Region US
        ┌────────┐
        │Replica │
        └────────┘
             X
             X
        WAN failure
             X
             X
        ┌────────┐
        │Replica │
        └────────┘
        Region EU

During a cross-region network failure, you must decide:

Option A — Stop some writes#

Protect stronger consistency.

Option B — Continue writes independently#

Protect availability but potentially create divergent state.

This is one reason global distributed systems require careful consistency design.


30. Conflict Resolution#

Availability-oriented systems may need conflict resolution.

Possible approaches include:

  • last-write-wins
  • version vectors
  • logical timestamps
  • application-specific merge rules
  • CRDT-based merging

Example:

Region A:
name = "Anubhav"
 
Region B:
name = "Anubhav Chaudhary"

A generic timestamp rule may choose one value.

But for important business data, application-specific conflict resolution may be safer.


31. CAP and Idempotency#

CAP decisions do not eliminate the need for idempotency.

Suppose a client sends:

POST /payment

The server processes it but the response is lost.

The client retries.

Without idempotency:

Payment 1
Payment 2

With an idempotency key:

request_id = abc123
 
First request → process
Retry         → return existing result

This is especially important in distributed systems because network failures make retries normal.


32. CAP and Timeouts#

A common misconception is:

"If we wait long enough, consistency is guaranteed."

Not necessarily.

In distributed systems:

Network may be slow
Network may be broken
Node may be overloaded
Response may be lost

Therefore systems use:

Timeout
   ↓
Retry / fail / fallback

The timeout policy itself becomes part of system behavior.


33. CAP and Failure Handling#

A production distributed system needs to define:

Partition detected
       ↓
What should happen?
       ↓
Reject?
Retry?
Read stale data?
Serve cached data?
Route elsewhere?
Degrade functionality?

There is no universal answer.

It depends on the business operation.


34. Operation-Specific Consistency#

A very important system-design insight:

One system does not necessarily need the same consistency level for every operation.

For example:

Payment authorization
→ strong consistency
 
Product recommendations
→ eventual consistency
 
Like count
→ eventual consistency
 
User profile
→ moderate/strong consistency depending on requirements
 
Search index
→ eventually consistent

This allows systems to optimize different workloads independently.


35. CAP Is About Trade-offs, Not Product Labels#

Avoid saying:

"Database X is always AP."

A more accurate approach is:

"Under this configuration and failure scenario, this system provides these consistency and availability characteristics."

Modern distributed databases often provide configurable consistency levels.

Therefore system-design answers should discuss:

  • operation
  • consistency level
  • failure mode
  • quorum
  • replication
  • region
  • latency
  • recovery behavior

rather than relying only on a simplistic CAP label.


36. CAP Interview Example#

Question#

You have 3 replicas:

A
B
C

A network partition isolates:

A
 
B
C

Can A continue accepting writes while preserving strong consistency with B and C?

Answer#

Not if A cannot coordinate with the other replicas and still provide the required strong consistency guarantee.

It must either:

  • restrict/reject operations, or
  • weaken the consistency guarantee.

That is the core CAP trade-off.


37. CAP Interview Question#

Question#

Why can't we simply choose all three?

Answer#

Because during a network partition, independently serving requests can cause replicas to disagree.

If the system continues serving requests, it may sacrifice strong consistency.

If it refuses or delays operations to preserve strong consistency, it sacrifices availability.


38. CAP Interview Question#

Question#

Is partition tolerance optional?

Answer#

In a distributed system deployed across machines or networks, communication failures are realistic.

Designing a system that assumes partitions cannot happen is unsafe.

Therefore practical distributed systems generally need to tolerate network partitions in some form.


39. CAP Interview Question#

Question#

What is the difference between CP and AP?

Answer#

During a network partition:

CP-oriented behavior

Protect consistency
       ↓
Some requests may fail or wait

AP-oriented behavior

Keep serving requests
       ↓
Temporary divergence may occur

40. CAP Interview Question#

Question#

Does AP mean "no consistency"?

Answer#

No.

AP does not mean the system has zero consistency guarantees.

It means the system prioritizes availability during a partition rather than guaranteeing strong consistency.

The system may still provide eventual consistency or other consistency guarantees.


41. CAP Interview Question#

Question#

What is PACELC?

Answer#

PACELC extends CAP:

If Partition:
    choose Availability or Consistency
 
Else:
    choose Latency or Consistency

It explains trade-offs even when there is no active partition.


42. Practical System Design Checklist#

When designing a distributed data system, document:

1. Number of replicas
2. Replication topology
3. Leader/follower or leaderless model
4. Read consistency
5. Write consistency
6. Quorum requirements
7. Partition behavior
8. Retry behavior
9. Conflict resolution
10. Recovery behavior
11. Failover strategy
12. User-visible degradation

This is much more useful than simply writing:

System = CP

43. Mini Design Exercise#

Design a distributed inventory system.

Requirements:

  • 1 million products
  • Multiple regions
  • High read traffic
  • Product availability must be correct
  • Temporary stale recommendations are acceptable
  • Checkout must not oversell inventory

Separate the workloads:

Product catalog
→ highly available reads
 
Recommendations
→ eventual consistency
 
Inventory reservation
→ stronger consistency
 
Checkout
→ transactional coordination

The architecture should not force every operation to use the same consistency strategy.


44. Mental Model#

Remember CAP using this picture:

                 NETWORK PARTITION
                        │
                        ▼
             ┌─────────────────────┐
             │ Communication fails │
             └──────────┬──────────┘
                        │
              ┌─────────┴─────────┐
              │                   │
       Keep serving         Stop/restrict
        requests              requests
              │                   │
              ▼                   ▼
       Availability          Consistency
       prioritized           prioritized

The important word is:

Partition

CAP becomes meaningful because distributed systems can lose communication.


45. Summary#

In this chapter you learned:

  • What CAP means
  • Why distributed systems face CAP trade-offs
  • What consistency means in the CAP context
  • Linearizability intuition
  • What availability means
  • What network partitions are
  • Why partitions matter
  • CP systems
  • AP systems
  • CAP's precise interpretation
  • Quorum systems
  • Read/write quorums
  • CAP vs eventual consistency
  • CAP vs ACID
  • CAP vs PACELC
  • Common CAP misconceptions
  • Conflict resolution
  • CAP and idempotency
  • CAP and timeouts
  • Multi-region partitions
  • Operation-specific consistency
  • How to reason about CAP in system-design interviews

The most important takeaway:

When a network partition occurs, a distributed system must make a deliberate trade-off between maintaining strong consistency and continuing to serve requests.


46. Exercises#

Exercise 1#

Explain CAP in your own words using two database replicas.

Exercise 2#

What happens if:

N = 5
W = 3
R = 3

Calculate whether the read and write quorums must overlap.

Exercise 3#

Classify these workloads by their likely consistency requirements:

  1. Payment processing
  2. Social-media like counter
  3. Product recommendation
  4. Inventory reservation
  5. Search index

Explain your reasoning.

Exercise 4#

Explain why:

"CAP means choose any two."

is an oversimplification.

Exercise 5#

Explain the difference between:

CAP Consistency
vs
ACID Consistency

47. Mini Project#

Design a multi-region shopping-cart system.

Requirements:

  • Users can access the cart from multiple regions.
  • Cart reads should be fast.
  • Temporary network failures should not make the entire application unusable.
  • Duplicate updates should be handled safely.
  • Cart conflicts should be resolvable.
  • Checkout must validate final inventory separately.

Document:

Architecture
     ↓
Replication
     ↓
Consistency model
     ↓
Partition behavior
     ↓
Conflict resolution
     ↓
Recovery

Do not simply label the whole system CP or AP.

Identify the consistency requirement for each operation.


48. Production Checklist#

Before shipping a distributed system, ask:

  • What happens when replicas cannot communicate?
  • Which operations require strong consistency?
  • Which operations can tolerate stale data?
  • What happens to writes during a partition?
  • How are conflicting writes resolved?
  • What happens when a response is lost?
  • Are retries idempotent?
  • What happens when a quorum cannot be reached?
  • How is recovery performed?
  • How does the user experience degraded operation?
  • Are consistency guarantees documented?
  • Are cross-region failure scenarios tested?

49. Interview Master Answer#

If an interviewer asks:

"Explain CAP theorem."

A strong answer can be:

CAP theorem describes a fundamental trade-off in distributed systems during a network partition. The three concepts are consistency, availability, and partition tolerance. In a real distributed system, network partitions can occur, so during a partition the system generally has to choose whether to preserve strong consistency or continue serving requests with availability. A CP-oriented system may reject or delay some operations to protect consistency, while an AP-oriented system continues serving requests and may allow temporary divergence. CAP should not be reduced to the phrase "choose any two"; the important question is how the system behaves under partition.

That answer demonstrates understanding rather than memorization.


50. Next Chapter#

Chapter 24 — Consistency Models#

In the next chapter, we will go deeper into consistency itself.

We will study:

  • Strong consistency
  • Linearizability
  • Sequential consistency
  • Causal consistency
  • Eventual consistency
  • Read-your-writes
  • Monotonic reads
  • Monotonic writes
  • Session consistency
  • Consistency in replicated databases
  • Quorum-based consistency
  • Leader-based consistency
  • Conflict resolution
  • Real-world examples
  • Choosing the right consistency model in system design
  • Interview questions

Finished this chapter?

Mark it as complete to track your mastery.

Previous ChapterChapter 22 — Distributed Systems FundamentalsNext ChapterChapter 24 — Consistency Models
PrevNext