KatInterview

Designing a Scalable Distributed Key-Value Store

System DesignModel answer
HardModel answerSystem Designsystem-designconsistent-hashingdistributed-systems

Last updated

Architect a fault-tolerant, horizontally scalable key-value storage system utilizing consistent hashing, tunable quorums, and automated data rebalancing.

Architect a distributed, highly available key-value database capable of serving high-throughput workloads across a cluster of nodes. Your architecture must address how key partitioning operates and how the cluster handles dynamic changes in topology without causing massive data reshuffling.

Specific Scope & Requirements

  1. System Operations & Scope:

    • Define basic data operations (get, put, delete).
    • Establish high-level scale assumptions (target capacity, read/write throughput, target latency targets, and availability constraints).
  2. Partitioning & Topology Management:

    • Detail the consistent hashing scheme used for key distribution.
    • Explain the usage of virtual nodes (vnodes) to mitigate hotspotting and handle non-uniform hardware.
    • Contrast key movement during node join/leave events under consistent hashing versus standard modulus partitioning.
  3. Routing Architecture:

    • Compare direct routing (smart clients) against proxy-based routing (gateways).
    • Detail how topology state (ring metadata) is stored, propagated, and synchronized across nodes, including handling stale ring state.
  4. Replication & Consistency:

    • Describe a multi-datacenter/rack-aware replication strategy (e.g., $N=3$).
    • Formulate tunable quorum mechanics ($R + W > N$) for consistency guarantees.
    • Outline the execution flow of read and write pipelines, explaining versioning (e.g., Hybrid Logical Clocks vs. Vector Clocks) and conflict resolution mechanisms (e.g., Last-Write-Wins or Read Repair).
  5. Fault Tolerance & Data Maintenance:

    • Specify node failure detection protocols.
    • Explain transient failure handling (e.g., hinted handoffs, sloppy quorums) versus permanent failure recovery (anti-entropy via Merkle trees).
    • Walk through the multi-stage operational lifecycle for safely adding or removing physical nodes without causing data corruption or latency spikes.
  6. Edge Cases & Alternatives:

    • Detail mechanisms to handle extreme key skew and read/write hotspots (e.g., key salting, local caching, bounded-load hashing).
    • Briefly contrast consistent hashing against central directory lookups and range-based partitioning, justifying your design choices.

Hints

Hint 1

Establish clear numerical bounds for data volume, write throughput, and read throughput before diving into design decisions.

Hint 2

Calculate the standard deviation reduction in load distribution when introducing virtual nodes.

Hint 3

Trace what happens to both incoming reads and ongoing writes during the exact transition phase when a node joins the ring.