In a network based data store, the chances of a “split brain” occurring always exists.
When designing a database, the challenge of how to make sure that the data is
- consistent - that is no matter from which part of the the networked data store you read from - you should get the same data, and,
- available - the system is available for writes and reads when accessed from any part of the networked datastore.
Replication Schemes
can be of the type
- Single Leader Replication — Single writer, and all the changes are propagated to all the followers. Followers offer read scalability. Good for consistency, but the single leader is a single-point-of-failure.
- Multileader Replication — more than one leader can exist and they can accept writes. This can result in higher write throughput and availability, but needs resolution mechanisms
- Leaderless Replication — Quorum reads and writes is a strategy to ensure consistency
(W + R > N)
, whereW
is the number of (Write) leaders,R
is the number of (Read) followers, andN
is the total number of nodes.
CA vs AP
In case of a network that has a single leader node, and the network is split in such a way that the leader is one part of the network, and it is unreachable from another part of the network, then the writes will not happen since the leader is not reachable and hence unable to acknowledge writes. This system is called Consistent when partitioned.
When the network has multiple leaders, the system can acknowledge writes and also provide read replicas making the system available, but it may not be consistent because there exists a possibility that nodes connected to different partitions may see different data. Such a system is called Available when partitioned