Database Sharding and Replication
Scale a single PostgreSQL database beyond one machine — set up streaming replication for read scaling and high availability, and understand when and how sharding becomes necessary beyond that.
Prerequisites: Database Schema Design; comfort with Docker Compose; the schema and data from that earlier project.
Targeted versions: PostgreSQL 18 streaming replication; Citus as a reference sharding extension; verified against postgresql.org documentation, mid-2026.
It's easy to conflate these two, but they answer different questions. Replication copies the same full dataset onto multiple machines, mainly for read scaling and failover — every replica has everything. Sharding splits one dataset across multiple machines so no single machine holds all of it, which is what you reach for once a single primary can no longer hold or serve your data volume even with replicas helping on reads. You'll set up the first before touching the second, because most teams need it much sooner.
Set up streaming replication
Split reads from writes
Partition before you shard
Sharding: distributing across servers
Secret Mission: fail over to the replica
Before You Go
Test what you just learned
Self-testing is one of the best ways to retain new skills. Unlock project quizzes to check your understanding.
Log in to unlock0 / 7 complete
