0
0
HLDsystem_design~12 mins

The CAP theorem in HLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - The CAP theorem

The CAP theorem explains the trade-offs in distributed systems between Consistency, Availability, and Partition tolerance. It states that a system can only guarantee two of these three properties at the same time. This helps architects decide which properties to prioritize based on system needs.

Architecture Diagram
          +-------------------+          +-------------------+
          |    Client A       |          |    Client B       |
          +---------+---------+          +---------+---------+
                    |                              |
                    |                              |
          +---------v---------+          +---------v---------+
          |   Load Balancer   |          |   Load Balancer   |
          +---------+---------+          +---------+---------+
                    |                              |
                    +--------------+---------------+
                                   |
                         +---------v---------+
                         |   Distributed     |
                         |   Database Cluster|
                         +---------+---------+
                                   |
                  +----------------+----------------+
                  |                                 |
          +-------v-------+                 +-------v-------+
          | Partition 1   |                 | Partition 2   |
          | (Subset of DB)|                 | (Subset of DB)|
          +---------------+                 +---------------+
Components
Client A
client
User or application sending requests to the system
Client B
client
Another user or application sending requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly to database nodes
Distributed Database Cluster
database_cluster
Stores data across multiple nodes to provide redundancy and scalability
Partition 1
database_node
One part of the database cluster holding a subset of data
Partition 2
database_node
Another part of the database cluster holding a subset of data
Request Flow - 6 Hops
Client ALoad Balancer
Load BalancerDistributed Database Cluster
Distributed Database ClusterPartition 1 or Partition 2
Partition 1 or Partition 2Distributed Database Cluster
Distributed Database ClusterLoad Balancer
Load BalancerClient A
Failure Scenario
Component Fails:Network Partition between Partition 1 and Partition 2
Impact:Partitions cannot communicate, causing potential inconsistency or unavailability depending on system choice
Mitigation:System must choose to prioritize either Consistency (reject some requests) or Availability (serve stale data) during partition
Architecture Quiz - 3 Questions
Test your understanding
According to the CAP theorem, which of the following is impossible for a distributed system to guarantee simultaneously?
AAll three: Consistency, Availability, and Partition tolerance
BConsistency and Availability
CConsistency and Partition tolerance
DAvailability and Partition tolerance
Design Principle
The CAP theorem guides system architects to understand that in distributed systems, network failures force a choice between consistency and availability. Designing systems requires prioritizing which two properties best fit the application's needs.