ReviseAlgo Logo
Intermediate10 min readPerformance & Scaling

Sharding & Partitioning

Splitting massive database sets horizontally across independent physical hardware nodes — covers range partitioning, hash partitioning, directory-based routing, and hotspot prevention strategies.

What you'll learn

  • Shard Key
  • Horizontal Partitioning (Sharding)
  • Vertical Partitioning
  • Hash-Based Sharding
  • Range-Based Sharding

TL;DR

Splitting massive database sets horizontally across independent physical hardware nodes — covers range partitioning, hash partitioning, directory-based routing, and hotspot prevention strategies.

Visual System Topology

Horizontal Database Sharding

Shard Key Router user_id % 3
Shard 1 IDs: 0 - 999k
Shard 2 IDs: 1M - 1.99M
Shard 3 IDs: 2M+

Concept Overview

Sharding (horizontal partitioning) splits a database into smaller, more manageable pieces called shards. Each shard contains a subset of the data and can be on a different server.

This is essential for scaling beyond what a single database server can handle, but introduces significant complexity.

Key Architectural Pillars

1

Shard Key

The field used to determine which shard data belongs to. Common choices: user_id, geographic region, hash of ID.

2

Horizontal Partitioning (Sharding)

Splitting rows across multiple databases. User 1-1000 on Shard1, 1001-2000 on Shard2.

3

Vertical Partitioning

Splitting columns across tables. User profile in Table1, user preferences in Table2.

4

Hash-Based Sharding

Use hash function on shard key to determine shard. Good distribution but hard to rebalance.

5

Range-Based Sharding

Split by ranges (IDs 1-1M on Shard1, 1M-2M on Shard2). Easy to add shards but can create hotspots.

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In
Sharding & Partitioning - Module 4: Performance & Scaling | System Design | Revise Algo