How would you handle multi-tenancy in a Flask application?
Instruction: Discuss the architectural considerations and implementation strategies for supporting multi-tenancy in a Flask application.
Context: This question explores the candidate's knowledge in designing Flask applications that can serve multiple tenants from a single application instance, a common requirement for SaaS platforms.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Choose a tenancy model from isolation, recovery, compliance and operational requirements: shared tables with tenant keys, separate schemas or separate databases. Tenant count alone does not determine the best model, and a database per tenant introduces connection, migration and fleet-management costs.
Resolve the tenant from trusted identity and an allowed membership. A domain or X-Tenant-ID header can select a requested tenant, but must be checked against the authenticated caller's rights...