
Postgres Sharding Hands-On: Docker, Python, PgBouncer, Citus
Udemy ยท English
About this course
- Language
- English
- Category
- Provider
- Udemy
- Data updated
Most sharding explanations stop at a diagram. In this course you build the whole thing on your own laptop and watch the numbers change. We start with one PostgreSQL database for a made-up grocery delivery company called KiranaLoop. Sixty-four checkout servers place orders at the same time, and we measure it every second. With a million customers and 8.4 million orders, one second drops to 308 orders. That slow second is where the course really begins. Before we shard anything, we try the cheaper steps first: a read replica, then partitioning by month. You will see what each one fixes, and what it cannot fix. Then we choose a shard key from the queries the company actually runs, split the data across four PostgreSQL shards with a router we write ourselves, and measure again: 32,472 orders per second, about five times the single database. Then we break it on purpose, four different ways, and fix each one:a dashboard that has to ask every shard (from 660 ms down to 6.8 ms)a 9 pm flash sale where everyone wants the same row (50,000 sold, zero oversold)too many connections (28 of 128 servers turned away, then all 128 served through PgBouncer)adding a fifth shard (80% of customers move with the simple rule, about 20% with a ring or buckets)Finally, we do it the way many companies do, with Citus. One line replaces our router, and we watch Citus move shards onto a new machine while the database keeps running. Every line of code is typed live and explained line by line, with a diagram next to the code for the tricky parts. Every number you see was printed by a real terminal. On your machine the numbers will be different, but the shape will be the same. The full code is in the course resources, so you can run exactly what I run. Each lecture also comes with a PDF slide deck: the diagrams, the commands, the measured numbers and a recap.











