Database Scaling
A single database server has limits on connections, disk I/O, and CPU. Three techniques push past those limits: read replicas, vertical sharding, and horizontal sharding.
Read replicas copy data from the primary asynchronously. Reads go to replicas; writes go to the primary. This works when reads outnumber writes — which describes most web applications. Vertical sharding splits different tables across different databases: users in one, orders in another. Horizontal sharding splits one table across multiple database servers by a shard key. It is powerful but complex — cross-shard joins are impossible, and a bad shard key creates hot spots that defeat the purpose.
Check your understanding
What do read replicas buy you?Show answerHide answer
Answer
Extra read capacity and a failover candidate, with async lag on replicas.When do you still read the primary?Show answerHide answer
Answer
Writes and any read that must see the latest committed state.What makes horizontal sharding hard?Show answerHide answer
Answer
Cross-shard joins, rebalancing, and hot shard keys that defeat the split.