Scaling the database - using multiple databases with Django
summary
Django is run against a single primary + replicas setup where writes go to the primary and reads go through a load balancer (pgbouncer or pgdog) across three replicas; this hides failed nodes and scales reads. A small database router (~17 lines) routes reads to replicas but checks transaction.get_autocommit to avoid visibility bugs (uncommitted inserts read as zero). Workarounds include optimizing get_or_create and forcing generic-relations to the primary; tested on AWS RDS with single‑digit ms replication lag and works in practice.
AI-written summary · about
chapters (14)
- 0:00Introduction and welcome
- 1:07Scaling basics explained
- 3:18Database sharding overview
- 3:59Primary-replica setup benefits
- 5:42Load balancers for databases
- 7:04Configuring Django databases
- 8:31Database routers in Django
- 11:42Challenges at scale
- 12:03Transaction consistency issues
- 14:12Django ORM optimizations
- 16:22Bugs in Django discovered
- 19:12Generic relations workaround
- 20:15Recap and benefits summary
- 22:24Q&A session
