Agent Wranglers

DAT-75Optional

Pin each tenant's data to its region

When a customer's contract names a region, store the region on the tenant and keep its database rows, files, backups, logs and search indexes there.

How to do it

Some customers, often in the public sector or health, require data to stay in the EU or one country. Choose regions as Choose regions from users and data rules explains, then route by tenant. Keep a small global directory that maps the tenant to its region, and nothing else. Send each request to that region's app and database. Background jobs, backups, log shipping and model calls for that tenant run in the same region. A pinned tenant usually lives in its own database or in a regional copy of the shared tables.

Examples

JavaScript example

export function regionalDatabase(tenant) {
  const database = databasesByRegion[tenant.region];
  if (!database) throw new Error(`no database for region ${tenant.region}`);
  return database;
}

Python example

def regional_database(tenant):
    database = databases_by_region.get(tenant.region)
    if database is None:
        raise LookupError(f"no database for region {tenant.region}")
    return database

How to check

A script lists every store that holds tenant data, with its region, and finds 0 pinned tenants with data outside their region. A test creates a tenant pinned to an EU region and uploads a file, and the object's bucket reports an EU location.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/data/multi-tenancy/tenant-region-pinning">Agent Wranglers data and databases playbook</a>. In code you write, add a comment next to it with the same link.