NestJS · Senior · Question 24 of 75
How would you implement multi-tenancy with a database per tenant in Nest?
- 1Use one connection and change the database name with each query string
- 2Create a new Nest app per tenant at runtime
- ✓Correct answer: Resolve the tenant from the request (subdomain, header, token), and provide a tenant-specific connection via durable providers or a connection cache keyed by tenant
Explanation
Cache connections per tenant and limit pool sizes, or the total number of DB connections explodes.