Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
All topics/Replication & Partitioning (Sharding)
STORAGE, CACHING & SEARCH · SUBTOPIC

Sharding Strategies & Celebrity Hot Spots

Hash vs. range sharding, cross-shard JOINs, and handling viral hot partitions.

IntermediatePart of Replication & Partitioning (Sharding)
Practice in AI HLD
Subtopics in Replication & Partitioning (Sharding) (2)
OverviewReplication ModesSharding & Hot Spots

In plain words

Splitting a giant library into 10 buildings by book number keeps each building manageable - unless one famous book has a million people crowding into Building #4.

Think of it like…

Splitting checkout lines by last name A–Z: almost equal, except "S" and "M" get longer lines unless you hash names randomly.

Loading interactive diagram
Loading interactive exercise

Theory & how it works

Range Sharding vs. Hash Sharding

Range sharding (e.g., IDs 1–1M on Shard 1) makes range queries fast, but risks hot spots if new IDs always increase. Hash sharding (hash(key) % N or consistent hashing) spreads writes evenly, but range queries must scatter-gather across every shard.

Remember: once you shard, cross-shard JOINs and multi-shard ACID transactions become slow and fragile - co-locate related rows by choosing a smart shard key like tenant_id or user_id.

Key points & practical guide

Summary checklist

  • Exhaust vertical scaling + caching + read replicas BEFORE sharding
  • Pick a high-cardinality shard key aligned with main queries
  • Use key salting or caching for celebrity hot spots

When to use it

  • Data exceeds ~5–10 TB or writes exceed a single primary’s capacity

Watch out for

  • Sharding by timestamp - puts 100% of live inserts onto one active shard

Quick check

Loading quiz
Previous subtopic
Leader-Follower, Multi-Leader & Leaderless Replication
Back to overview
Full Replication & Partitioning (Sharding) Lesson