|
160 | 160 | * *Schema-per-tenant*: Becomes hard to scale and migrate when tenant counts exceed 1,000, causing connection pool exhaustion. |
161 | 161 |
|
162 | 162 | ### 6.2 Tenant Resolution Mechanism |
163 | | -* **Chosen Tool:** **NestJS Interceptor + PostgreSQL Connection Session Context** |
164 | | -* **Why Chosen:** Resolves the `tenant_id` from JWT claims or `X-Tenant-ID` headers at ingress, and uses a database transaction wrapper to inject the tenant context into the active PostgreSQL session dynamically. |
| 163 | +* **Chosen Tool:** **NestJS Interceptor + SQL Server SESSION_CONTEXT** |
| 164 | +* **Why Chosen:** Resolves the `tenant_id` from JWT claims or `X-Tenant-ID` headers at ingress, and uses a database interceptor/wrapper to inject the tenant context into the active SQL Server session using `sp_set_session_context`. |
165 | 165 | * **Alternatives Rejected:** |
166 | 166 | * *Application-level filtering*: Prone to developer omissions (forgetting a `WHERE tenant_id = x` clause), leading to critical data leak vulnerabilities. RLS prevents this at the database level across all runtimes. |
167 | 167 |
|
@@ -277,6 +277,12 @@ To avoid cloud-provider lock-in and support offline, on-premise environments, ** |
277 | 277 | * **Rationale:** Eliminates infrastructure fragmentation and ensures unified security enforcement (RLS). |
278 | 278 | * **Revisit When:** Licensing costs exceed budget or a specific context requires native NoSQL features. |
279 | 279 |
|
| 280 | +### Decision 3: Single Database Engine Strategy — SQL Server 2022 for all services |
| 281 | +* **Decision:** All services, including NestJS satellites (Config, Template, Profile managers), must persist exclusively in SQL Server 2022. |
| 282 | +* **Rationale:** Polyglot persistence (PG/Mongo) was rejected to minimize operational overhead in on-premise deployments and unify the Row-Level Security (RLS) implementation. |
| 283 | +* **Impact:** All services share a single backup, security, and maintenance strategy. Node.js services must use the `mssql` driver. |
| 284 | +* **Revisit When:** Re-evaluate if unstructured data volume requires a specialized NoSQL engine for non-relational workloads. |
| 285 | + |
280 | 286 | --- |
281 | 287 |
|
282 | 288 | ## 14. Open Questions |
|
0 commit comments