Cosmic Module
O
Qubits of DPK
March 20, 2026
Core Open Source
The Analogy
Imagine a single large office building with 100 companies renting floors. Each company has its own employees, furniture, filing cabinets, and confidential data. They share the building (electricity, plumbing, security guard at the door) but they NEVER see each other's data.
Apache Fineract is that office building. Multiple banks (tenants) share ONE running Java application, but each bank's data is completely isolated.
Why Multi-Tenancy?
If you're a SaaS company offering banking software:
- Running 100 separate Fineract instances = 100x infrastructure cost
- One multi-tenant Fineract instance = 1x infrastructure cost, 100 banks
This is exactly how cloud services like Salesforce, Shopify work.
How Fineract Implements It — Schema-Based Isolation
Fineract uses schema-per-tenant isolation. Each bank gets its own MySQL/PostgreSQL schema (like its own separate filing room).
javascript
QUBITS OF DPK
Each schema has ALL the same tables (m_client, m_loan, m_savings_account etc.) but completely separate data.
The Tenant ID Header — The Security Guard
Every HTTP request to Fineract MUST include:
javascript
QUBITS OF DPK
This is how Fineract knows which bank's schema to use. Missing this header → 400 Bad Request.
java
QUBITS OF DPK
ThreadLocal — How the Tenant Context Travels
Layman Explanation
In a call centre, every agent has their own headset. When Agent A takes a call from Bank Kenya and Agent B takes a call from Bank India, they don't mix up the conversations. Each agent's headset carries only THEIR call.
In Java, ThreadLocal is that personal headset. Each HTTP request runs on its own thread. The tenant context is stored in a ThreadLocal — only visible to that thread.
java
QUBITS OF DPK
DataSourcePerTenantService — The Magic Switch
This is the core of multi-tenancy. Every time a DB query runs, Fineract:
- #Reads the current tenant from ThreadLocal
- #Gets that tenant's database connection
- #Runs the query against that tenant's schema
- #Returns the result
java
QUBITS OF DPK
The Tenant Registry — fineract_tenants Schema
The global fineract_tenants database (separate from all tenant schemas) stores:
sql
QUBITS OF DPK
When a request comes in with Fineract-Platform-TenantId: bank_kenya, Fineract:
- #Queries fineract_tenants.tenants to find the record for bank_kenya
- #Gets the schema name: fineract_bank_kenya
- #Sets up a DB connection to fineract_bank_kenya
- #All subsequent queries in that request use fineract_bank_kenya
Complete Request Flow with Multi-Tenancy
javascript
QUBITS OF DPK
Liquibase — Schema Migration Per Tenant
When a new column is added to m_loan, it needs to be added to EVERY tenant's schema. Liquibase handles this.
javascript
QUBITS OF DPK
On startup, Fineract runs all pending migrations against every registered tenant's schema.