A scalable, dynamic multi-tenant architecture implementation built with Spring Boot. This repository demonstrates how to isolate tenant data at the database/schema level while sharing a single application instance, utilizing dynamic datasource routing and custom HTTP header filtering.
- Dynamic Database Routing: Automatically routes queries to the correct database based on incoming HTTP headers (
orgId). - Schema-Level Data Isolation: Ensures strict boundaries between tenant data for enterprise-grade security and compliance.
- Runtime Configuration: Dynamically loads tenant datasource properties on startup without requiring application rebuilds.
- Extensible Design: Easily scalable to accommodate new tenants simply by adding a configuration file.
When a client makes a request, the TenantFilter intercepts it, extracts the tenant identifier, and sets the context. The data layer then dynamically routes all subsequent operations to the correct isolated database.
graph TD
Client[Client Request\n+ 'orgId' Header] --> Filter[TenantFilter API Interceptor]
Filter --> Config[MultiTenantConfiguration\nDatasource Map]
Config --> Router[Dynamic Datasource Router]
Router --> |orgId: tenantB| DB_B[(Tenant B Database)]
Router --> |orgId: tenantA| DB_A[(Tenant A Database)]
Router --> |No Header| DB_Def[(Default Database)]