Interactive CAP Theorem Simulator: Consistency vs. Availability
Understand why Distributed Architectures must choose between Strong Consistency and High Availability during network partitions.
The Core Trade-off
The CAP Theorem (Brewer's Theorem) states that a distributed data store can only provide two of the following three guarantees simultaneously:
- Consistency (C): Every read receives the most recent write or an error.
- Availability (A): Every request receives a (non-error) response, without the guarantee that it contains the most recent write.
- Partition Tolerance (P): The system continues to operate despite an arbitrary number of messages being dropped or delayed by the network between nodes.
How the Simulator Works
In a real-world Distributed Database, network partitions (P) are inevitable. Therefore, you must choose between C and A:
CP Mode (Consistency Preferred)
Examples: HBase, MongoDB, Redis (default).
If the system detects a partition (e.g., Node A cannot reach Node B), it stops accepting writes to preserve data accuracy. It sacrifices Availability to ensure no user sees stale data.
AP Mode (Availability Preferred)
Examples: Cassandra, DynamoDB, CouchDB.
The system always accepts writes, even if nodes are disconnected. Node A will update its local data, but B will remain old. This creates Eventual Consistency, where nodes sync up only after the network heals.

