Detailed component design
1. Node structure detail
A KV node machine contains below component:
- Node service
- Responsible to receive requests
- Manges data in memory, and hard disk
- Write and manage commit logs for merge conflict or data loss recovery
- KV data in Memory
- Cached KV data in memory to reduce latency and increase availability. Each data entry can have a TTL field so that old data without accessing will be evicted
- KV data persisted on hard disk
- The KV data is persisted in hard disk as SSTable (sorted string table) as key-value pair strings. The SSTable is commonly used data structure by popular noSQL database such as cassandra
- Commit logs for operation history
- Operation logs, it can be used to handle merge conflict and data loss recovery
2. Sharding strategy - consistent hashing
- KV nodes are structured as a consistent hashing ring in the hash range 2^64-1, to further make sure the data is evenly distributed to each node, we can map each physical node to 3 virtual node on the hash ring
- The coordinator node stores the hash key range data about each kv node, it also stores the mapping between physical node and virtual node so that when a request for a key comes, the coordinator knows which node should handle the request
3. Replication
Master / slave replication
- For each node, in order to achieve high availability we uses master / slave replication. All write requests, i.e. v1/set and v1/conditional_update, v1/delete are handled by master and all read requests are handled by slaves, there are multiple slaves to increase the availability of read
- The write operation of master will eventually propagate to slave to ensure eventual consistency
4. Support data replication across multiple nodes to ensure fault tolerance
- To ensure fault tolerance, we can support data replication across multiple nodes, we can choose the next 3 nodes on the hash ring as the replication node of the current node, 2 to be used as write replica and 2 to be used as read replicas
- As 2+2 > 3, we'll ensure eventually consistency on the node