Skip to main content

Multi-Tenancy Roadmap

Current status

The system has completed Phase 0: Platform Decoupling and Phases 1-4: Hospital-Agnostic Refactoring (configuration extraction, prompt parameterisation, generic naming, database-driven configuration cache). It runs in single-tenant pilot mode for ZOL. Full multi-tenant routing (subdomain resolution, per-tenant authentication) is planned. See also the Multi-Tenancy Architecture page for current implementation details.

1. Vision​

The system was initially built as a single-hospital solution. To deploy it across several hospitals (a software-as-a-service model) the architecture must support tenant isolation: each hospital's data, configuration and user experience must be completely separate.

The decoupling follows a phased approach: first parameterise all hospital-specific references (Phase 0, completed), then make the codebase fully hospital-agnostic (Phases 1-4, completed 31 March 2026), then add tenant routing and management (planned), and finally implement full multi-tenant operations (future).

2. Phase 0: Platform decoupling (completed)​

Phase 0 converted all hardcoded references to the pilot hospital into parameterised, configuration-driven code, so the codebase can serve any hospital by changing configuration rather than code.

2.1 What was done​

ComponentBeforeAfter
Taxonomy37 module-level constants loaded at importA taxonomy object obtained from a per-hospital factory
Prompt templates70+ hardcoded references to the hospital nameA prompt-context object with hospital identity placeholders
Taxonomy tablesNo tenant scopingA tenant reference on all entities and relationships, with composite uniqueness rules
Redis keysFlat key prefixesA tenant prefix on all cache, rate-limit and session keys
Site configurationA single global configuration objectPer-hospital configuration profiles
Hub page detectionHardcoded page-type patternsAutomatic hub/detail classification by a language-model binary classifier
Document serviceHospital-specific title patternsPatterns loaded from the hospital configuration
Query serviceHardcoded base URLsURLs from the hospital configuration
RAG servicePilot-hospital identity in responsesIdentity taken from the prompt-context object
Taxonomy registryGlobal singletonPer-hospital registry cache
Frozen taxonomyOne global registryOne registry per hospital

2.2 Configuration architecture​

All hospital-specific data lives in one configuration file per hospital. A file contains these sections:

  • Hospital identity: name, short name, website and public contact number.
  • Campuses: for each campus an identifier, canonical name, aliases (the alternative names visitors use), address and contact number.
  • Domain knowledge: mappings from hospital-specific centres to the conditions and treatments they handle. Standard departments are covered by a universal, hospital-independent knowledge base instead.
  • Search aliases: a universal set plus hospital-specific aliases that map common lay terms to the right centre (for example a lay term for breast cancer mapping to the breast centre).
  • Specialty-to-department map: which departments correspond to each medical specialty.

Departments and page-type patterns were removed from the file on 2026-03-09: departments are now discovered automatically by the extraction pipeline, and hub/detail classification replaced the earlier page-pattern lists.

Adding a new hospital requires only a new configuration file, with no code changes.

2.3 Backward compatibility​

A compatibility shim re-exports the symbols of the old taxonomy module from the new one, so existing imports keep working during the migration period. It can be removed once all imports are updated.

3. Current state: single-tenant pilot​

The pilot serves one hospital (ZOL) under a default tenant. Every component defaults to that tenant, so the system works fully without explicit tenant routing.

3.1 What works today​

  • The full RAG pipeline with hospital-parameterised prompts
  • Taxonomy tables with tenant-scoped entities and relationships
  • Tenant-isolated Redis caching and rate limiting
  • Hospital-specific safety messages and disclaimers in several languages
  • A configurable taxonomy with SNOMED-CT synonym enrichment

3.2 What remains single-tenant​

  • The front end has no tenant routing or hospital selection
  • Authentication is not yet tenant-aware (separate Keycloak realms could provide per-tenant isolation in a later phase)
  • There is no tenant-management interface
  • There is no per-tenant billing or usage tracking
Updated 2026-06-09

Conversations, users and analytics events all carry a tenant reference in the current data model. A later schema migration added referential constraints with cascading deletion to documents and conversations, closing the last gap from the Phase 0 rollout. The earlier statement that those tables lacked a tenant reference no longer applies.

The remaining single-tenant gaps are operational rather than schema-level: request routing (subdomain, path or header resolution), per-tenant authentication flows, a tenant-management interface and usage metering.

4. Hospital-agnostic refactoring (completed 31 March 2026)​

Before multi-tenant routing, the codebase was made fully hospital-agnostic in a four-phase sprint:

PhaseWhatStatus
Phase 1Configuration extraction: a crawl-configuration table and administrative interfaceDone
Phase 2Prompt parameterisation: all language-model prompts use a prompt context built from the databaseDone
Phase 3Generic naming: the hospital-specific crawler was renamed, hospital branding removedDone
Phase 4Database-driven configuration cache replaces all in-code constantsDone

Result: according to the project's own count, 259 hospital-specific references were removed, and a new hospital can be onboarded with database configuration only.

5. Tenant routing (planned)​

The next phase adds the infrastructure to serve multiple hospitals from a single deployment.

5.1 Tenant resolution​

Tenant resolution options, ordered by complexity:

  1. Subdomain-based: one sub-domain per hospital; cleanest for end users.
  2. Path-based: one path prefix per hospital; simpler infrastructure.
  3. Header-based: a tenant request header; for programmatic API consumers.

5.2 Database tenancy​

ApproachIsolationComplexityRecommended?
Shared schema with a tenant columnRow-levelLowYes, at pilot scale
Separate schema per tenantSchema-levelMediumFuture option
Separate database per tenantFullHighNot needed

The shared-schema approach adds a tenant column to all PostgreSQL tables and enforces row-level filtering in the application layer. It is sufficient for the expected scale of five to ten hospitals.

5.3 Estimated scope​

TaskEffortDependencies
Add a tenant column to the remaining PostgreSQL tables (migration)MediumNone
Tenant resolver middlewareSmallNone
Per-tenant authenticationMediumTenant resolver
Front-end tenant contextSmallTenant resolver
Tenant-management interfaceMediumDatabase migration
Per-tenant configuration filesSmallPhase 0 (done)

6. Full multi-tenant operations (future)​

A later phase adds operational capabilities for managing multiple hospitals in production.

6.1 Features​

  • Tenant onboarding workflow: automated setup of a new hospital (configuration, database seeding, taxonomy initialisation, content crawl)
  • Per-tenant analytics dashboard: hospital administrators see only their own data
  • Content isolation verification: automated tests confirming there is no cross-tenant data leakage
  • Per-tenant feature switches: enable or disable pipeline components per hospital
  • Usage metering and billing: track language-model API costs, storage and query volumes per tenant

6.2 Content pipeline​

Each hospital requires its own content pipeline:

7. Storage isolation summary​

Storage layerPhase 0 (current)Phase 1 (planned)Phase 2 (future)
PostgreSQLSingle tenantRow-level tenant filteringRow-level (sufficient)
Taxonomy tablesTenant reference on all rowsSameSame
RedisTenant key prefixSameSame
MinIOTenant path prefixSameSame
pgvectorSingle collectionPer-tenant collection or filterPer-tenant collection

8. Risk considerations​

RiskMitigation
Cross-tenant data leakageAutomated integration tests verifying isolation at every storage layer
Configuration driftA validation schema for configuration files and continuous-integration checks for required fields
Performance at scalePer-tenant caching, connection pooling, lazy taxonomy loading
Compliance variationPer-tenant data-protection impact assessment and data-retention settings (stored in the tenant configuration)

Document version 2.0 | 2026-03-31 | SOFT4U BV. A planning document; later sections describe planned work, not delivered features.