Database Sharding Explained | Range vs Hash vs Directory Sharding
Key Takeaways
The video explains database sharding, its importance in large-scale system design, and discusses range-based, hash-based, and directory-based sharding strategies. It highlights the trade-offs of each approach and the importance of choosing the right shard key.
Full Transcript
Welcome to design. Today we're breaking [music] down one of the most important concepts in large scale system design, database chararda. At the simplest level, chararda is about survival. When a single monolithic database can no longer handle growing data size, read traffic, or write throughput, vertical scaling stops working. You can't keep adding CPU or memory forever. Sharding solves this by splitting data horizontally across multiple independent databases called shards. Each shard holds only a subset of the total data, but together they represent the complete system. Once data is distributed, reads and writes happen in parallel. Throughput scales almost linearly and failures are isolated instead of taking down the entire system. There are multiple ways to shard data and each comes with trade-offs. Rangebased sharding splits data by value ranges such as price, user ID ranges, or timestamps. This is simple and efficient for range queries, but has a major weakness. If traffic concentrates on a specific range, you end up with hot shards, uneven load, and degraded performance. Keybase sharding, also known as hashbased sharding, uses a hash function on the shard key to determine where data lives. This gives excellent load distribution and avoids hot spots. However, it breaks natural ordering, which makes range query slower and more complex. Directory-based sharding uses a lookup service that maps attributes like region or tenant to specific shards. This approach is highly flexible and allows dynamic rebalancing, but introduces an additional dependency. If the directory becomes slow or unavailable, the entire system is affected. In practice, large-scale systems often combine multiple sharding strategies to balance performance, flexibility, and operational complexity. The most critical decision in any shard system is choosing the shard key. A good shard key must have high cardality so data spreads evenly. It should have uniform access frequency to avoid hotspots and it should not be monotonically increasing. Keys like time stamps or auto increment IDs may seem convenient but they silently create unbalanced shards and bottlenecks over time. Once data is shard aid every request must be routed correctly. This can be done in three ways. Shardaware clients route requests directly but are tightly coupled to shard topology. A dedicated routing tier centralizes shard logic and offers clean abstraction at scale. Shardaware nodes sit in between providing a balance of flexibility and control. Most modern architectures prefer a routing tier for long-term evolvability. Finally, sharding is almost always combined with replication. Each shard has a leader that handles rights and multiple followers that serve reads. Leaders are distributed across nodes, so no single machine becomes a bottleneck. This design delivers high availability, fall tolerance, and horizontal scalability, but it also introduces coordination and consistency challenges. Sharding is not just a database optimization. It's a foundational architectural decision that impacts APIs, query design, consistency models, and operational complexity. Master it, and you're no longer just building applications. You're designing distributed systems.
Original Description
Database sharding is one of the most critical concepts in large-scale system design.
In this video, we break down database sharding in just 3 minutes—covering what sharding is, why monolithic databases fail at scale, and how modern distributed systems shard data efficiently.
You’ll learn:
What database sharding really means
Range-based, hash-based, and directory-based sharding
How to choose the right shard key
Request routing strategies in sharded systems
How replication works alongside sharding
Real-world trade-offs used by large-scale platforms
This walkthrough is perfect for:
Software engineers
Backend & platform engineers
System design interview prep
Architects building high-scale data systems
If you want more deep, practical system design content, subscribe to Bazai.
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Playlist UUOthur5d9OxdqEh08Swtirw · BazAI · 34 of 49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
▶
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
How LLM Agents Actually Do Deep Research (Planning, Tools & Citations Explained
BazAI
Kafka vs RabbitMQ Explained: Which One Should You Use?
BazAI
#NOVER Explained: How AI Learns to Judge Its Own Reasoning (No Reward Model Needed)
BazAI
The State of Enterprise AI 2025: How Workers Save 60 Minutes Daily & Adoption Explodes 9X
BazAI
NVIDIA Nemotron 3: 1M Context, Hybrid MoE Architecture, and Open Source AI Agents
BazAI
How Service Mesh Works: Data Plane, Control Plane & Observability
BazAI
How to Design Safe Retries in Microservices (No Duplicates, No Overload)
BazAI
Step-GUI: The Self-Evolving AI Agent for Android & PC (SOTA Performance!)
BazAI
NVIDIA's NitroGen: The First Generalist AI Trained to Play 1,000+ Games by Watching
BazAI
How AI Agents Remember: The Evolution of Agentic Memory (2025 Guide)
BazAI
Automate Your AI Data Pipelines: Introducing DataFlow & DataFlow-Agent
BazAI
Nemotron 3 Explained: Hybrid Mamba + MoE for 1M Token Agents
BazAI
Build Your Own AI Voice Agent (LangChain + OpenAI + AssemblyAI + Cartesia)
BazAI
Langflow 1.7 Explained: CUGA, ALTK, MCP & the Death of Prompt Engineering
BazAI
HuatuoGPT-o1: The First Medical AI That "Thinks" Before It Answers
BazAI
Molmo2: Open-Source Vision-Language Models with State-of-the-Art Video Grounding
BazAI
MAI-UI: Alibaba’s New Foundation GUI Agents Outperforming Gemini & GPT-4o
BazAI
Seamless AI Object Insertion: Bridging 4D Geometry and Diffusion Models
BazAI
5 AI Agentic Workflow Patterns-Reflection, Tools, ReAct, Planning, Multi‑Agent
BazAI
#NVIDIA's New #SurgWorld: How AI is Learning Autonomous Surgery
BazAI
CQRS Explained in 3 Minutes: How Modern Systems Scale Reads vs Writes
BazAI
Docker Explained in 3 Minutes: How Containers Actually Work
BazAI
6 Practical AWS Lambda Patterns in 3 Minutes (Real‑World Serverless Guide)
BazAI
Containerization Explained in 3 Minutes: From Dockerfile to Running Containers
BazAI
Science Context Protocol (SCP)- Global Web of Autonomous Scientific Agents
BazAI
Youtu-Agent: Scaling LLM Agent Productivity via Automated Generation and Hybrid RL
BazAI
#DeepSeek’s #mHC Breakthrough: Stabilizing Hyper-Connections for Large-Scale LLM Training
BazAI
Message Brokers 101 in 3 Minutes: Queues, Pub‑Sub & Competing Consumers Explained
BazAI
Must‑Know Message Broker Patterns: Outbox, CQRS, Saga & More
BazAI
Confucius Code Agent-Scalable Scaffolding for Large-Scale Repositories
BazAI
#nvidia Just Fixed #GRPO! Meet #GDPO: The New Standard for Multi-Reward RL
BazAI
NVIDIA Alpamayo-R1: Real-Time Reasoning for Level 4 Autonomy
BazAI
The Future of AI Memory: Meet #AtomMem’s Learnable CRUD System
BazAI
Database Sharding Explained | Range vs Hash vs Directory Sharding
BazAI
12 Architecture Concepts Every Developer Must Know | System Design Explained
BazAI
5 Rate Limiting Strategies Explained | Protect Your System at Scale
BazAI
How Live Streaming Works | System Design Explained
BazAI
5 Leader Election Algorithms Explained | Distributed Systems & Databases
BazAI
6 Prompting Techniques to Get Better Results from ChatGPT
BazAI
Complete Guide to Storage Systems: RAM, SSD, SAN, Cloud & Databases
BazAI
Top 4 Authentication Mechanisms Explained | SSH, OAuth, SSL & Passwords
BazAI
Common Network Protocols Explained | TCP, UDP, HTTP, DNS & More
BazAI
Microservices Best Practices | 9 Rules Every Architect Must Know
BazAI
8 Network Protocols Every Engineer Must Know | HTTP, TCP, UDP & More
BazAI
Distributed Systems in 3 Minutes: CDNs, APIs, TCP & Idempotency Explained
BazAI
Must‑Know Message Broker Patterns in 3 Minutes (Outbox, CQRS, Saga & More)
BazAI
Is OpenClaw Safe? The "Security Nightmare" Behind the Viral AI Agent
BazAI
JWT vs Sessions vs PASETO — Which Authentication Should You Use?
BazAI
Recursive LLMs vs Big Context Windows: Why RLM Wins
BazAI
More on: Systems Design Basics
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Your event store is already your audit log
Dev.to · Marc
Distributed Transactions in System Design: Why Data Consistency Becomes Hard Once Your Application…
Medium · Programming
Monolith vs Microservices: A Real-World Architectural Autopsy
Dev.to · Erwin Wilson Ceniza2
FOV in FPS Games: The Math Behind Field of View Settings
Dev.to · Alex Carter
🎓
Tutor Explanation
DeepCamp AI