System Design line, station 3 of 8
Databases at Scale
Keep a growing Postgres database fast, safe and recoverable with partitioning, replicas, sharding, backups, daily operations and the right extra data stores.
- 6lessons
- 3.5 hto read and do
- Intermediatelevel
- 6podcast episodes
- 10checked exercises
- 2simulators
Tools you'll use in this course
The lessons open these with a template ready. They work for your own job too, no course needed.
About this course
Most apps start with one Postgres database, and for a long time that is the right choice. Then the sales table passes a billion rows, the evening dashboard slows down the checkout tills, somebody runs a DELETE on the wrong server, and the team starts asking about sharding. This course shows you what to do at each of those moments, in the order a careful team would do it.
You will partition a big table so queries read only the months they need, move reads to replicas without the classic stale-read bug, learn when sharding is really needed and how consistent hashing routes keys, set recovery targets and restore a database to the minute before a mistake, run the daily health checks a database administrator relies on, and use JSONB, full-text search and materialized views before you add another database.
Every lesson follows Mangrove Market, a fictional grocery chain with 320 stores, an app and 1,800 partner shops, so the numbers stay concrete. Each one has checkpoints, practice tasks that run in your browser on a real PostgreSQL engine or in JavaScript, flashcards and a podcast episode. The course ends with a capstone design for the Partner app's order database and a final exam.
What you will be able to do
- Partition a large table by month so queries prune to the months they need and old data leaves with DETACH and DROP
- Route reads between a primary and its replicas, measure replication lag and plan a failover that cannot cause split brain
- Decide whether sharding is really needed, choose a shard key, and explain consistent hashing with virtual nodes
- Agree RPO and RTO targets and meet them with WAL archiving, point-in-time recovery and timed restore drills
- Run a daily Postgres health check covering connections, long transactions, vacuum, transaction ID age and roles
- Use JSONB, full-text search and materialized views first, and add another data store only for a measured need
Syllabus
6 stops, about 3.5 h in total. Each stop fills in when you complete the lesson.
Partitioning big tables
When one table holds years of sales, every query, vacuum and clean-up gets slower. Partitioning splits that table into smaller tables behind one name, so Postgres reads only the months a query needs and you can remove an old month in about a second.
Table partitioningPartition pruningData retention
Replication and read replicas
A replica is a second Postgres server that keeps a live copy of your database. It can take heavy reads off the primary and stand ready to take over if the primary dies. It is always a little behind, though, and this lesson shows you how to design for that.
Read replicasReplication lagFailover
Sharding and consistent hashing
Sharding splits one database across several servers, so each server holds part of the rows and takes part of the writes. It is the most powerful scaling tool in this course, and the most expensive one to live with. This lesson shows when you really need it and how the routing works.
ShardingConsistent hashingShard key design
Backups and disaster recovery
A backup is only worth something on the day you restore it. This lesson shows you how to set targets for how much data you may lose and how long you may be down, which backups meet those targets, and how to bring a database back to the minute before someone's mistake.
Backup and recoveryRPO and RTOPoint-in-time recovery
Running Postgres in production
Most Postgres outages come from a few everyday things: too many connections, a transaction left open, vacuum falling behind, or one role with far too much power. This lesson gives you the daily habits and the exact settings and queries a DBA uses to keep a busy database healthy.
Postgres operationsConnection poolingVacuum and MVCCLeast privilege
Beyond SQL: choosing the right data store
Postgres can do far more than most teams use it for, and a second database brings a second set of backups, failures and skills to learn. This lesson helps you tell when Postgres is enough, when another kind of store really earns its place, and how to move data into analytics without slowing down the store tills.
Choosing data storesJSONB and full-text searchOLTP and OLAPChange data capture
Capstone: Scale and protect the Partner app's order database
A realistic project with a rubric and a model answer.
Final exam and certificate
10 questions drawn at random, 70% to pass.
Capstone project
Scale and protect the Partner app's order database
Mangrove Market's order database serves the Partner app, where about 1,800 partner shops order stock wholesale, and the Mangrove app. Together they add about 1.4 million order_line rows a day, three years of history sits in one table, the morning reports slow down the 7 to 11 am ordering rush, there is one streaming replica, and nobody has ever tested a restore. Ken, the engineering manager, asks you for a short design and working SQL that keep this database fast and recoverable for the next two years. Imran, the product manager, needs to understand the trade-offs, and the team will only consider sharding if you can show with numbers that it is needed.
You will hand in
- A design document of 2 to 3 pages: partitioning, read routing, the sharding decision with a write-rate estimate, backups and recovery, and monitoring
- A SQL file that creates order and order_line as monthly range-partitioned tables with keys, indexes, a default partition and a function that creates future months, plus EXPLAIN output showing a report that prunes; run it on PostgreSQL 16 or newer (PGlite in the browser is fine)
- A table of the ten most important reads, each marked primary or replica with a one-line reason
- An RPO and RTO table for three disasters (a dead server, a bad DELETE, a lost cloud region) and a one-page restore drill checklist
- Daily health-check SQL with an alert threshold and an owner for each query
Check what you know
Already know some of this? Answer 6 quick questions, one from each lesson, and we will mark the lessons you can skim. It takes about 3 minutes and nothing is graded.
Questions
How long does the course take?
About 3.5 to 4 hours for the six lessons, including the checkpoints and practice tasks. The podcast episodes add about 80 minutes if you listen to all of them. Allow 2 to 6 hours more for the capstone project.
What do I need to know before I start?
You should be comfortable with SELECT, JOIN and GROUP BY, and know what an index and a transaction are. The SQL & Data Modeling course covers all of that. When a lesson builds on another Kolom lesson, such as query plans, safe migrations or caching, it links to it so you can read it when you need it.
Do I need to install Postgres?
Not for the practice tasks. The SQL exercises run in your browser on PGlite, a real PostgreSQL engine compiled to WebAssembly, and the JavaScript exercises run in a sandbox on the page. To follow the Build-it sections yourself, install PostgreSQL 16 or newer, for example with Docker. Replication, PgBouncer and backups need a real server, and the replication lesson needs two of them, or two local clusters on different ports.
Is the certificate free, and how does the final exam work?
Yes, the course, the exam and the certificate are free. Each attempt gives you 15 questions picked at random from the course's question bank, and you pass with 70% or more. If you do not pass, you can try again after 24 hours.
I use MySQL or a managed database. Is this course still useful?
Yes. The commands are PostgreSQL, but the ideas carry over: partition pruning, replica lag, shard keys, RPO and RTO, connection pooling and choosing data stores work the same way on MySQL and on managed services such as Amazon RDS or Cloud SQL. The lessons point out where a managed service does a step for you, such as backups and failover.
Is it really free?
Yes. Every lesson, podcast episode, exercise, quiz, final exam and certificate is free. The labs and their templates for real work are free too. Plus and Premium add every lab challenge, weekly extras and a mentor on top, and they never lock the tools or the courses.