Technology1 min read

Build a Multi-Tenant SaaS Backend That Can't Leak One Customer Into Another

By · Published by Everything Blog

In short

Under the updated architecture, tagging an entity field with a tenant annotation automatically locks all bulk updates, criteria queries, finds, and counts to the active customer. A request-level filter dynamically derives this identity from headers, hosts, or authenticated credentials, treating missing contexts as exceptions rather than exposing global records. Cross-tenant entries simply appear missing, ensuring users cannot verify the existence of another organization's data. Furthermore, sessions handling tenant-scoped entities disallow native SQL execution by default to avert bypasses.

Key points

  • Data segregation occurs strictly at the ORM level to automate filtering across queries an…: Data segregation occurs strictly at the ORM level to automate filtering across queries and bulk data updates.
  • Native SQL execution and unscoped queries require targeted opt-in methods to maintain an…: Native SQL execution and unscoped queries require targeted opt-in methods to maintain an auditable footprint for administrative tasks.
  • Enterprise backend updates deliver broader capabilities including GraphQL support, multi-…: Enterprise backend updates deliver broader capabilities including GraphQL support, multi-cloud object storage, and Active Directory integration.

Sources checked by our analysis pipeline: 1

The worst bug a SaaS company can ship is one customer seeing another customer’s invoices. It doesn’t crash anything and no test fails. A support ticket arrives, then a lawyer. It almost always comes from the same place: one query, somewhere, that forgot the WHERE tenant_id = ?

.

This week the Codename One backend refuses to run that query. It also picked up the rest of what an enterprise customer asks about in the first meeting: GraphQL, SAML single sign-on, LDAP and Active Directory, object storage on every major cloud, and document and search databases. Friday’s post argued that the baseline for an app moved. This is the baseline for its server.

One annotation, and every query is scoped

Mark the field that holds the tenant:

@Entity

public class Invoice {

@Id @GeneratedValue long id;

@TenantId String tenant;

String customer;

}

From then on the ORM stamps the tenant on insert and treats it as immutable. Finds, criteria queries, JPQL, counts, bulk updates and bulk deletes are all filtered to the current tenant. Another tenant’s row doesn’t throw an…

Technology