Beginner LevelSystem Design & Architecture
Explain the CAP Theorem and PACELC Theorem with real-world database examples.
β Interview Prompt: What are Consistency, Availability, and Partition Tolerance? How does PACELC expand CAP when no network partition exists?
The CAP Theorem states that a distributed system can only provide at most 2 out of 3 guarantees during a network partition:
β’
CP (Consistency + Partition Tolerance): Rejects writes/reads if data sync cannot be guaranteed across nodes (e.g. HBase, MongoDB with strict write concerns).
β’
AP (Availability + Partition Tolerance): Returns stale data rather than erroring (e.g. Cassandra, DynamoDB).
PACELC Theorem:
Extends CAP:
β’
If Partition (P): Choose between Availability (A) or Consistency (C);
β’
Else (E): Choose between Latency (L) or Consistency (C).
Example: DynamoDB defaults to PA/EL (prioritizes availability during partitions, low latency normally).
Code Implementation Example
markdown
PACELC Decision Matrix:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PACELC β
βββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββ€
β If Network Partition β Else (Normal) β
βββββββββββββββ¬ββββββββββββββΌβββββββββββββββ¬ββββββββββββββ€
β Availabilityβ Consistency β Low Latency β Consistency β
β (AP) β (CP) β (EL) β (EC) β
βββββββββββββββ΄ββββββββββββββ΄βββββββββββββββ΄ββββββββββββββπ‘PACELC database trade-off matrix.
π― Interview Key Takeaway
System design requires balancing consistency against availability and network latency depending on business SLAs.
#System Design#CAP Theorem#PACELC#Architecture#Beginner
Back to all System Design & Architecture Questionsβ