Skip to content
Ameen Abozaid
SRC-007

Database scaling

  • 9 Lessons
  • 4.5 h practice (estimate)
On this page 9 topics

Overview

Topics

  • Read replicas
  • partitioning
  • sharding
  • hot partitions

Learn first

4.5 h of practice (estimate)

Learning outcomes

  1. Scale reads with replicas while handling replication lag in application design.
  2. Choose between vertical scaling, partitioning, and sharding with evidence.
  3. Choose a shard key, predict hot partitions, and plan resharding.
  4. Evaluate managed distributed SQL options against operating sharded PostgreSQL.

Lessons

  1. 01The scaling ladder
  2. 02Read replicas and lag-aware design
  3. 03Partitioning revisited
  4. 04Sharding and shard keys
  5. 05Hot partitions
  6. 06Resharding
  7. 07Distributed SQL and managed options
  8. 08Demo: choosing a shard key for orders
  9. 09Demo: read replicas and the stale-read bug they introduce

Lab and exercises

Lab

SRC-007-LAB1 · Order data at 10×

Outcomes: 1–4 · Time: ~2.5 h

  1. Quantify the 10× need from SRC-004 (reads, writes, size) against the current single-primary limits.
  2. Walk the scaling ladder with evidence; decide among replicas, partitioning, sharding, or managed distributed SQL.
  3. If sharding, choose the key from real distribution data and quantify hot-partition risk.
  4. Write the ADR and a migration outline with resharding and rollback.

Acceptance: hot-partition risk quantified.

Exercises (shard-key scenarios plus ADR; six exercises)

IDOutcomeTask
SRC-007-EX011A "my orders" page shows missing orders after checkout when using replicas. Diagnose and design a lag-aware fix.
SRC-007-EX022Given measurements (CPU 85%, 90% reads, write rate 40% of limit), decide the next rung of the ladder and justify.
SRC-007-EX033Evaluate customer id, order id hash, and region as shard keys for the three main order queries.
SRC-007-EX043Top 1% of customers produce 30% of orders across 8 shards. Estimate hot-shard load and propose a mitigation.
SRC-007-EX053Outline a resharding plan from 4 to 8 servers.
SRC-007-EX064Compare managed distributed SQL with sharded PostgreSQL for the order database and name the proof-of-concept tests.
Show solutions
  • EX01 Replica lag; route read-your-writes to the primary (or wait for LSN), monitor lag, fall back above a threshold, add a test.
  • EX02 Reads dominate, so read replicas plus caching; write headroom is fine; sharding is premature.
  • EX03 Customer id fits "my orders" and customer-scoped queries; order id hash spreads evenly but scatters customer queries; region is low cardinality. Choose customer id, with a lookup for order by id.
  • EX04 If the top 1% land in one shard that could mean 30% of load on a shard expected to take 12.5%, roughly 2.4x average; mitigate with salting, splitting large tenants, or extra capacity for that shard.
  • EX05 Use logical shards; create new servers, copy and replicate changes for moved logical shards, verify, cut over by updating the mapping, clean up; keep rollback until verified.
  • EX06 Test transaction latency, cross-shard joins, failover time, compatibility of queries and extensions, cost at 10x, migration effort; compare operating burden.

Workplace evidence: a database scaling change you designed or reviewed.

Quiz

Outcomes: O1 replicas and lag · O2 scaling options with evidence · O3 shard keys, hot partitions, resharding · O4 managed distributed SQL.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1Read replicas primarily scale:O1
  2. 2Read-your-writes after replication requires:O1
  3. 3The right response to growing replica lag is:O1
  4. 4Reads are 90% of load and CPU is high with write headroom. The best next step:O2
  5. 5Partitioning within one server mainly helps:O2
  6. 6A good shard key:O3
  7. 7A time-based shard key causes:O3
  8. 8Resharding is easier when you use:O3
  9. 9A fair evaluation of distributed SQL uses:O4
  10. 10Hot-partition risk should be:O3

Practical part

Six shard-key and scaling exercises SRC-007-EX01 to EX06 plus the lab ADR. Pass: quiz at least 8/10, at least five exercises correct, and an ADR with quantified hot-partition risk and a migration outline.

Common mistakes

Sharding before exhausting simpler options; shard keys that break the most common query.

Assessment

Shard-key scenarios plus ADR.

Workplace evidence

A database scaling change you designed or reviewed.

Career relevance

Distributed data (SRB-003) and database architecture (ARC-016).

Type to search levels, phases, modules and lessons.