Polyglot Persistence with Django: When One Database Isn't Enough
summary
Sets up Django with a PostgreSQL/SQLite default and a MongoDB document backend, installs a Django MongoDB engine, writes a Django database router and points models to each connection, and attempts migrations and transactional work. Migrations quietly skip the non-default DB and an enforced foreign key check fails with an OperationalError because referential integrity requires same-database references. Using MongoDB Queryable Encryption encrypts fields into ciphertext so filters and select_for_update stop working. Decision criteria: access patterns, compliance needs, and ongoing operational cost.
AI-written summary · about
chapters (16)
- 0:00Introduction and icebreaker
- 0:51Back story and motivation
- 1:39What is referential integrity?
- 2:50Why use multiple databases?
- 4:11Django multi-database setup
- 6:01Database router configuration
- 7:31Modeling data for polyglot persistence
- 8:41Migrations and safety nets
- 10:29Referential integrity failure case
- 11:58Lessons learned from the demo
- 12:45Encrypted field challenges
- 13:53Tradeoffs and performance costs
- 14:37Three key considerations before adding a second database
- 15:45When polyglot persistence is worth it
- 16:06Summary and closing
- 16:26Q&A session
