Skip to solution
hardSystem Design

What is database sharding?

654 views
01

Understand the problem

Explain sharding and trade-offs.

shardingpartitioning
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

What Is Database Sharding?

Target Audience: Junior & Senior Software Engineers preparing for System Design Interviews — no prior system design knowledge assumed. Difficulty: Medium

How to read this doc: Every concept is explained in plain language first. Right after, you'll see a callout like `📌 Inte

Solution ready — 2 min read

Classified // press E to declassify

04

Read the code

Routing a key to a shard
Run Playground
import hashlib

SHARDS = ["db-0", "db-1", "db-2", "db-3"]

def shard_for(key):
    h = int(hashlib.md5(key.encode()).hexdigest(), 16)
    return SHARDS[h % len(SHARDS)]

for k in ["user:1001", "user:1002", "order:77", "order:78"]:
    print(k, "->", shard_for(k))

# NOTE: plain modulo means adding a shard remaps most keys.
# Use consistent hashing to limit how much data moves on resize.
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 64 of 99 decoded in the System Design track. One more won't hurt.

Back to track