Bird
Raised Fist0
DBMS Theoryknowledge~10 mins

CAP theorem in DBMS Theory - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Concept Flow - CAP Theorem
Start: Distributed database system
CAP Theorem: Pick 2 of 3 guarantees
Consistency
Network partition occurs
Choose: Consistency OR Availability?
CP System
End
This flow shows how the CAP theorem forces a choice between consistency and availability when a network partition happens in a distributed database.
Execution Sample
DBMS Theory
Distributed database has 3 nodes: Node_A, Node_B, Node_C
Client writes value X=10 to Node_A
Node_A replicates to Node_B and Node_C
Network partition splits: {Node_A, Node_B} | {Node_C}
Client reads X from Node_C
CP system: Reject read (Node_C may have stale data)
AP system: Return last known X value (may be stale)
This sequence shows how a network partition forces a distributed database to choose between consistency and availability.
Analysis Table
StepActionCondition/CheckResult/DecisionNext Step
1Client writes X=10 to Node_AN/AWrite accepted at Node_AReplicate to other nodes
2Node_A replicates to Node_B, Node_CNetwork healthy?Yes, all nodes updatedSystem fully consistent
3Network partition occursNode_C cannot reach Node_A or Node_BPartition detectedChoose CP or AP
4Client sends read request to Node_CCan Node_C confirm latest value?No (partitioned from Node_A)Apply CAP trade-off
5CP system responseConsistency prioritizedReject read with errorWait for partition to heal
6AP system responseAvailability prioritizedReturn last known value of XAccept possible staleness
7Partition healsNodes reconnectSync data across all nodesEnd
💡 After partition heals, all nodes synchronize to reach eventual consistency. The CAP trade-off only applies during the partition.
State Tracker
VariableStartAfter Step 2After Step 3After Step 5 (CP)After Step 6 (AP)
X at Node_Aundefined10101010
X at Node_Bundefined10101010
X at Node_Cundefined1010 (stale?)Read rejectedReturns 10 (may be stale)
system_statusHealthyConsistentPartitionedUnavailable to Node_CAvailable but inconsistent
Key Insights - 3 Insights
Why can't a distributed system guarantee all three of C, A, and P simultaneously?
When a network partition (P) occurs, the system must choose: either reject requests to stay consistent (CP) or serve possibly stale data to stay available (AP). You cannot have both C and A during a partition, as shown in steps 5 and 6.
What does Partition Tolerance mean and why is it non-negotiable?
Partition tolerance means the system continues operating despite network splits between nodes. In real distributed systems, network failures are inevitable, so P is always required — making the real choice between C and A.
How do real databases handle the CAP trade-off?
CP systems like HBase and MongoDB (in strict mode) reject operations during partitions to maintain consistency. AP systems like Cassandra and DynamoDB continue serving requests and reconcile data after the partition heals.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 5. What does a CP system do when a client reads from a partitioned node?
AReturns the latest value from the primary node
BRejects the read request with an error
CReturns a cached value from the partitioned node
DRedirects the client to another node
💡 Hint
Check the 'Result/Decision' column in step 5 where consistency is prioritized.
According to the variable_tracker, what happens to X at Node_C after an AP system responds during a partition?
AIt is deleted
BIt returns the confirmed latest value
CIt returns a value that may be stale
DIt blocks until the partition heals
💡 Hint
Look at the 'After Step 6 (AP)' column for Node_C.
Why is partition tolerance considered non-negotiable in distributed systems?
AIt is the easiest guarantee to implement
BNetwork failures are inevitable in distributed systems
CClients always prefer partition tolerance over consistency
DDatabases cannot function without partitions
💡 Hint
Think about what happens in real networks spanning multiple data centers.
Concept Snapshot
CAP theorem: distributed systems can guarantee only 2 of 3 properties.
Consistency: all nodes see the same data at the same time.
Availability: every request gets a non-error response.
Partition Tolerance: system works despite network splits.
Since partitions are inevitable, the real choice is C vs A.
Full Transcript
This visual execution shows the CAP theorem in action. A distributed database with three nodes accepts a write and replicates it across all nodes. When a network partition splits Node_C from the others, the system faces a choice. A CP system rejects reads from Node_C to maintain consistency, while an AP system returns the last known value to stay available, accepting possible staleness. Once the partition heals, nodes synchronize to restore consistency. The key insight is that since network partitions are inevitable in distributed systems, the real trade-off is always between consistency and availability.

Practice

(1/5)
1. What does the CAP theorem state about distributed systems?
easy
A. A distributed system can only guarantee two out of Consistency, Availability, and Partition tolerance at the same time.
B. A distributed system can guarantee all three: Consistency, Availability, and Partition tolerance simultaneously.
C. CAP theorem applies only to single-node databases.
D. CAP theorem states that Consistency is always more important than Availability.

Solution

  1. Step 1: Understand the CAP theorem basics

    The CAP theorem says a distributed system cannot guarantee Consistency, Availability, and Partition tolerance all at once.
  2. Step 2: Identify the correct statement

    Only two of these three properties can be guaranteed simultaneously in a distributed system.
  3. Final Answer:

    A distributed system can only guarantee two out of Consistency, Availability, and Partition tolerance at the same time. -> Option A
  4. Quick Check:

    CAP theorem = Two guarantees only [OK]
Hint: Remember CAP means pick any two out of three [OK]
Common Mistakes:
  • Thinking all three guarantees are possible simultaneously
  • Confusing CAP theorem with ACID properties
  • Assuming CAP applies to single-node systems
2. Which of the following is a correct example of a system prioritizing Availability over Consistency according to CAP theorem?
easy
A. A DNS system that always responds to queries even if some data is outdated.
B. A system that never allows network partitions.
C. A system that stops responding during network partitions to avoid inconsistent data.
D. A banking system that locks accounts during transactions to ensure exact balances.

Solution

  1. Step 1: Identify Availability over Consistency example

    Availability means the system always responds, even if data might be stale or inconsistent.
  2. Step 2: Match example to definition

    DNS systems prioritize Availability by responding to queries despite possible outdated data during partitions.
  3. Final Answer:

    A DNS system that always responds to queries even if some data is outdated. -> Option A
  4. Quick Check:

    Availability > Consistency example = DNS [OK]
Hint: Availability means always respond, even if data is stale [OK]
Common Mistakes:
  • Confusing locking with Availability
  • Thinking systems can avoid network partitions
  • Assuming consistency means always available
3. Consider a distributed database that chooses Consistency and Partition tolerance but sacrifices Availability during network failures. What happens when a network partition occurs?
medium
A. The system automatically heals the network partition.
B. The system continues to serve all requests with possibly stale data.
C. The system ignores partitions and may return inconsistent data.
D. The system refuses to respond to some requests to maintain data consistency.

Solution

  1. Step 1: Analyze system choice of Consistency and Partition tolerance

    Choosing Consistency and Partition tolerance means the system must maintain data correctness and handle network splits.
  2. Step 2: Understand impact on Availability

    To keep Consistency during partitions, the system sacrifices Availability by refusing some requests.
  3. Final Answer:

    The system refuses to respond to some requests to maintain data consistency. -> Option D
  4. Quick Check:

    Consistency + Partition tolerance = sacrifice Availability [OK]
Hint: Consistency + Partition tolerance means some requests denied [OK]
Common Mistakes:
  • Assuming system serves stale data when consistency chosen
  • Thinking partitions are automatically fixed
  • Confusing availability with consistency guarantees
4. A developer claims their distributed system guarantees Consistency, Availability, and Partition tolerance simultaneously. What is the most likely issue?
medium
A. The system uses eventual consistency correctly.
B. The system is ignoring network partitions or not truly distributed.
C. The system is using a single-node database.
D. The system is using a caching layer to improve performance.

Solution

  1. Step 1: Recall CAP theorem limitation

    CAP theorem states all three guarantees cannot be met simultaneously in a distributed system.
  2. Step 2: Identify why claim is incorrect

    If a system claims all three, it likely ignores partitions or is not truly distributed.
  3. Final Answer:

    The system is ignoring network partitions or not truly distributed. -> Option B
  4. Quick Check:

    All three guarantees impossible in distributed system [OK]
Hint: All three guarantees mean system is not truly distributed [OK]
Common Mistakes:
  • Believing eventual consistency means full consistency
  • Confusing caching with consistency guarantees
  • Ignoring network partitions in design
5. You are designing a global e-commerce platform that must remain available during network partitions but can tolerate some temporary inconsistency. According to CAP theorem, which two properties should you prioritize?
hard
A. Consistency and Partition tolerance
B. Consistency and Availability
C. Availability and Partition tolerance
D. Only Availability

Solution

  1. Step 1: Understand system requirements

    The platform must remain available during network partitions and can tolerate temporary inconsistency.
  2. Step 2: Match requirements to CAP properties

    Availability and Partition tolerance must be prioritized, sacrificing strict Consistency temporarily.
  3. Final Answer:

    Availability and Partition tolerance -> Option C
  4. Quick Check:

    Available + Partition tolerant = temporary inconsistency allowed [OK]
Hint: Availability + Partition tolerance means accept temporary inconsistency [OK]
Common Mistakes:
  • Choosing Consistency when availability is required
  • Ignoring partition tolerance in global systems
  • Assuming all three properties can be guaranteed