Karakoram Technologies Logo
← Back to Case StudiesArchitecture Case Study

Engineering a Leak-Proof Multi-Tenant Architecture

The Business Problem

Building a B2B SaaS platform introduces a critical risk: data leakage. If Agency A logs in and accidentally views the draft campaigns or proprietary brand metrics belonging to Agency B, the trust is broken, and the platform fails. Early in the design of Karakoram Studio, we faced the classic SaaS dilemma: do we provision a separate database for every single tenant (secure but incredibly expensive and hard to maintain), or do we put everyone in the same database and risk a developer forgetting to add a WHERE TenantId = X clause?

The Requirements

  • Absolute data isolation between tenant organizations.
  • Cost-effective scaling (avoiding the overhead of managing 1,000 separate SQL databases).
  • Developer velocity (engineers shouldn't have to manually write isolation logic into every query).

The Architecture & Implementation

We architected a "Single Database, Multiple Schema" approach utilizing the ABP Framework and Entity Framework (EF) Core on top of ASP.NET Core.

Instead of relying on application-level filtering, we pushed the isolation down to the ORM layer. We implemented the IMultiTenant interface across all domain entities. By doing this, EF Core's Global Query Filters automatically intercepted every single SELECT, UPDATE, and DELETE command executed by the application.

// Example: Automatic Tenant Filtering
builder.Entity<Customer>().HasQueryFilter(c => EF.Property<Guid>(c, "TenantId") == _tenantProvider.TenantId);

The Technical Challenge

The major challenge was providing access to the "Host Administrators"—our internal support staff who needed to query across all tenants to generate system-wide health reports and billing metrics.

The Solution

We leveraged the ABP Framework's IDataFilter service. In highly restricted, specifically authorized Host-level API controllers, we temporarily disabled the multi-tenancy filter within a strict using block. This allowed safe, cross-tenant querying for administrative dashboards without compromising the core isolation used by the rest of the application.

Lessons Learned

Relying on developers to remember to filter data is a security incident waiting to happen. By enforcing isolation at the lowest possible layer (the ORM), we eliminated human error. This architecture proved that enterprise-grade security and cost-effective scaling are not mutually exclusive when using the right framework.

Karakoram AI

Online

Hi! I am the Karakoram AI assistant. How can I help you today?