Course contentsShow
← Computer Science
Lesson 1733 of 2,87239. NoSQL and Modern DatabasesFree lesson

Replication in Key-Value Stores

How key-value stores replicate data across multiple nodes for durability and availability.

Replication in Key-Value Stores

You'll learn how key-value stores copy data across multiple nodes to prevent data loss and keep the system running even when hardware fails.

Why Replicate?

In a key-value store, each piece of data (a key-value pair) lives on a server node. But what happens if that node crashes or the disk fails? The data would be lost. Replication solves this by maintaining multiple copies of each key-value pair across different nodes.

How Replication Works

When you execute a PUT operation to store user:123 → {"name": "Alice"}, the system doesn't just write to one node. Instead:

  1. Primary node receives the write
  2. The system forwards copies to two or more replica nodes
  3. Each replica stores an identical copy

Now if one node fails, the other replicas can still serve GET requests for user:123.

Consistent Hashing and Replicas

Remember consistent hashing from the previous lesson? It determines which node owns a key. With replication, the system typically stores copies on the next N nodes clockwise on the hash ring. For example, with replication factor 3, if user:123 hashes to Node A, copies also go to Nodes B and C.

Durability and Availability

  • Durability: Even if a node dies permanently, your data survives on replicas
  • Availability: If the primary node is down, replicas can handle GET and PUT operations

This is crucial for production systems where hardware failures are inevitable.

Key Takeaway: Replication in key-value stores creates multiple copies of each key-value pair across different nodes, ensuring data survives hardware failures and remains accessible even when nodes go down.