System Design10 lessons21 quiz questions

Database Scaling

Database scaling is a spectrum: start simple (read replicas), add complexity only as needed (sharding). The golden rule: sharding is a last resort because of the massive complexity it adds. Most systems can run on a well-tuned single primary with read replicas for years.

What You Will Learn

  • Why Single Databases Fail at Scale
  • Read Replicas: Scaling Reads
  • Master-Master Replication
  • Sharding: Horizontal Partitioning
  • Consistent Hashing
  • Shard Key Selection
  • Cross-Shard Queries
  • Database Partitioning Strategies
  • Data Migration and Resharding
  • Practice: Design a Sharding Strategy

Overview

Database scaling is a spectrum: start simple (read replicas), add complexity only as needed (sharding). The golden rule: sharding is a last resort because of the massive complexity it adds. Most systems can run on a well-tuned single primary with read replicas for years. Why Single Databases Fail at Scale Your startup is growing. You started with one PostgreSQL database handling everything. Then this happens: 100 users: Everything is fast. Life is good. 10,000 users: Queries start slowing down. You add indexes. 100,000 users: Writes are bottlenecked. One write per ms = 1000 writes/sec max. 1,000,000 users: Database is the bottleneck. Reads are slow, writes are queued. The Three Walls CPU wall: Complex queries eat CPU. More users = more queries. Memory wall: Hot data doesn't fit in RAM anymore. Disk reads are 100x slower. Storage wall: Disk is full. Can't store more data on one machine. The Solution Spectrum Always start simple and scale only when you have a measured problem. Premature optimization is the root of all evil. Python Implementation Java Implementation JavaScript/TypeScript Implementation

Sample Quiz Questions

1. What is the primary purpose of a read replica in a database setup?

Remember·Difficulty: 1/5

2. Which sharding strategy ensures that adding a new shard requires moving minimal data?

Understand·Difficulty: 2/5

3. In master-slave replication, replicas can accept write operations.

Remember·Difficulty: 1/5

+ 18 more questions available in the full app.

Related Topics

Master Database Scaling for Your Next Interview

Get access to full lessons, adaptive quizzes, cheat sheets, code playground, and progress tracking — completely free.