Horizontally Scaling Your Database with Django
summary
Compares three practical steps: scale up then feature partitioning then sharding, with concrete tradeoffs (lose cross-db foreign keys, select_related, cascades). Uses and extends DJ_DATABASE_URL for many DB URIs and adds shard group metadata, implements an app-based router and instance.get_shard delegation, and provides a custom management command plus South migration hacks to run migrations across every shard. Chooses many logical shards per physical node, avoids automatic balancing, and recommends Snowflake-style 64-bit IDs for globally unique keys.
AI-written summary · about
chapters (27)
- 0:00Intro
- 2:51separate databases
- 3:07dj-database-url
- 3:19Setup more databases
- 3:30Database Router for Feature Partitioning
- 4:17Databases for Read and Write
- 4:46Relationships between different instances
- 5:32Syncing the Database
- 6:32Multi-database applications have a cost
- 7:48Multiple databases with the same schema
- 9:00Good sharding key?
- 9:21Harder to Shard
- 9:53Bad sharding key?
- 10:55Database Definitions
- 11:23Extending South
- 12:56db_for_read() method
- 13:56instance.get_shard()
- 14:21allow_relation() method
- 14:37allow_syncdb() method
- 14:56Reading from a shard
- 15:18Writing to a shard
- 15:47Many Logical Shards per Physical Node
- 16:10Table Alterations are faster
- 16:40Obtain globally unique IDs
- 17:01Use an AUTO_INCREMENT column
- 17:36ID Generator
- 18:37In Summary
