Aman Goyal

LeetCode LeetCode

Sharded Services: Scaling Data Beyond a Single Machine

Core Concept


Sharding vs Replication

FeatureReplicationSharding
DataSame everywhereSplit across nodes
Use caseStateless servicesStateful / large data
GoalAvailability + scalingData size + scaling

Replication = copy

Sharding = divide


Why Sharding Is Needed

1. Scale beyond a single machine


2. Better resource utilization

Example:


3. Isolation (bonus use case)


Sharded Cache Insights

1. Improves performance


2. Cache is critical

Cache affects:


3. Warm-up problem

Deployments can temporarily reduce performance


Replicated Sharding (Best of Both Worlds)

Benefits:


Sharding Function (CRITICAL)

Shard = hash(request) % N

Key properties:


Choosing the Right Shard Key

Bad choice:

Better:

Best:

Wrong key = bad performance or incorrect results


Consistent Hashing (VERY IMPORTANT)

Problem:

Solution:

Critical for scaling systems smoothly


Hot Shards Problem

Solution:


Mental Model

[ Router ]
   ↓
[ Shard A ] [ Shard B ] [ Shard C ]
   (each handles different data)

Trade-offs

Pros

Cons


One-line Summary

Sharding distributes data across multiple machines so each handles a subset of requests, enabling systems to scale beyond single-node limits—but requires careful design of shard keys and hashing to work efficiently.

#Distributed Systems #System Design #Sharding #Consistent Hashing #Scaling