Question #3 of 60•Databases•Medium• ~3 min read

What is the difference between Database Sharding, Partitioning, and Indexing?

Executive Takeaway

Differentiate how sharding distributes tables across distinct database nodes, partitioning divides local data logical segments, and indexing accelerates lookups.

Architectural Breakdown & AnalysisFAANG Aligned

These are three core optimization strategies to handle large volumes of database reads and writes. They operate at different levels of database management:

StrategyLocationKey ObjectiveHow It Works
IndexingWithin a single tableAccelerates read queriesCreates lookup helpers (B-Tree or Hash index) mapping index keys to disk locations. Slightly slows down write operations.
PartitioningWithin a single database instanceManages table layoutSplits a large table into smaller physical chunks (e.g. partition by Month) on the same disk for pruning.
ShardingAcross multiple physical databasesScales write throughput & storageDistributes database rows across distinct server nodes using a shard key (e.g. hash(user_id) % N).
WARNING — Sharding Complexity

Sharding introduces significant overhead: JOIN queries across shards become extremely expensive, cross-shard transactions require distributed locks (2PC/Sagas), and re-balancing data when adding shards is complex.

Previous QuestionWhen should you choose Vertical Scaling (Scale Up) vs. Horizontal Scaling (Scale Out)?Next Question How do you scale WebSockets to support millions of concurrent, stateful connections?

Continue Learning on Being SDE

Explore deep-dive system architecture modules, low-level object-oriented designs, and interview cheat sheets.