Databases Basics In System Designing
Pre-requisite: CAP theorem which states that it is not possible to guarantee all three of the desirable properties – consistency, availability, and partition tolerance at the same time in a distributed system with data replication.
- Consistency: All nodes in the system should be responding with the most recent data.
- Availability: Any node can send a response.
- Partial Tolerance: Systems will keep on working even if communication is dropped between 2 nodes.
Now we are good to go to discuss the above database sets as depicted below:
CP database
In this database when partitioning between any two nodes is happening a;; other non-consistent nodes are shut down hence making them unavailable. This database delivers consistency and partition tolerance at expense of availability.
AP database
As the name suggests consistency is getting lost in this database during partitioning all nodes at the wrong end of partition are made to deliver older version of data. In this way in this database, all nodes are available but not consistent.
Note: Now you must be wondering about CA database which sounds misleading as there is no partitioning carried on. So always remember partitioning is a property of a system which is telling CP or AP, which one to choose .
Interesting fact: We see RDBMS databases at CA sides of triangle in above media which is only possible at single node setup as even in case of master(write)-slave(read).
Note: Sometimes when it is only referred to as CA to lower degree of extent for some reasons where it can’t recover from network partitions than there split-bran scenario.(new master is elected for partitioning)
Complete Reference to Databases in Designing Systems – Learn System Design
Previous Parts of this System Design Tutorial