30. Which combination gives defence in depth for a pooled PostgreSQL database?
- Random UUIDs for ids and nothing else
- Scoped repositories, RLS enforced for a non-owner app role, and two-tenant isolation tests
- A tenant id header sent by the browser
- A superuser connection with careful code review
Show answer
Answer: Scoped repositories, RLS enforced for a non-owner app role, and two-tenant isolation tests
Each layer catches what the others miss: repositories make the safe path easy, RLS catches forgotten filters, tests prove it. Ids, client headers and superusers do not enforce isolation.
Lesson: Cheat Sheet: Multi-Tenancy on One Page
31. An interviewer asks: "Your pooled product just signed a bank that requires dedicated storage. What changes?" Which answer is strongest?
- Fork the codebase for the bank
- Refuse, because pooled products cannot host such customers
- Move every tenant to dedicated databases
- Provision a dedicated database for that tenant, record it in the catalogue, and keep the same application code routing by lookup
Show answer
Answer: Provision a dedicated database for that tenant, record it in the catalogue, and keep the same application code routing by lookup
Tier-based placement through a catalogue lets one tenant be siloed without a fork and without changing everyone else's placement.
Lesson: Common Interview and Exam Questions
32. In the snippet above, the connection comes from a pool and the table uses RLS keyed on `app.tenant_id`. What is the main problem?
- RLS cannot read custom settings
- SELECT statements are never filtered by RLS
- With is_local set to false the setting lasts for the whole session, so a later request on the pooled connection that forgets to set the tenant runs with this tenant's id
- Python cannot pass parameters to SQL
Show answer
Answer: With is_local set to false the setting lasts for the whole session, so a later request on the pooled connection that forgets to set the tenant runs with this tenant's id
set_config(..., false) behaves like a plain SET and lasts for the session. Run the work in a transaction with set_config(..., true) or SET LOCAL so the tenant setting cannot leak to the next borrower of the connection.
Lesson: Mixed Self-Check