Multi-tenant SaaS Platforms — Cells, Rings & Progressive Delivery›03 · Routing tenants to cells

Lesson 03 of 16 · Cells

Routing tenants to cells

Get every request to the right cell: identify the tenant early, look up its cell in a tenant directory, cache the map at the edge so routing survives directory outages, and handle the failure modes of the routing tier itself.

Architect
Key wordstenant routingcell routertenant directorytenant to cell mapsubdomain routingtoken claim routingedge cachestatic stabilityDNSrouting failure modes

The routing problem

With cells, every request must reach the cell that owns its tenant. That needs three things: identify the tenant, look up its cell, forward the request, all fast, and without turning the router into a new single point of failure.

The school receptionist has a class list pinned to the desk: "Asha → room 5". She doesn't phone the head office for every visitor; she checks the list. When a child changes class, head office sends an updated list, and until it arrives the old one is almost always right.

Identify the tenant

  • Subdomain (acme.app.example.com): the edge can route on the Host header; simple and cacheable.
  • Token claim (tenant: acme in the access token): natural for APIs; the router validates or at least decodes the token.
  • Path prefix: works, but spreads into every URL.
  • Login-time lookup: the user signs in once, the system finds their tenant and cell, then the client talks to a cell-specific hostname.

The tenant directory and the map

The tenant directory is the source of truth: tenant → cell, plus tier, region, status (active, moving, suspended). It is part of the control plane:

tenant directory (control plane, strongly consistent, rarely written)
      │ publishes the map (push or periodic pull)
      ▼
routing tier / edge (data plane): in-memory map, refreshed every few seconds
      │ Host or token → tenant → cell
      ▼
cell gateway → services
  • Cache the map at every routing node and at the edge. If the directory is unavailable, routing continues with the last known map (static stability).
  • Version the map and log changes; a bad map push is a global incident, so validate before publishing and roll it out gradually.

Forwarding

  • Edge-based: CDN or edge functions look up the cell and forward to the cell's origin hostname.
  • Router service: a small fleet of proxies (Envoy, NGINX) in each region with the map loaded.
  • DNS-based: per-tenant DNS records pointing at the cell. Simple, but TTLs make moves slow and caching is outside your control.

Failure modes to design for

Failure Design response
Directory down Cached map keeps routing; tenant creation and moves pause
Router node down Many stateless routers behind the edge; health checks
Stale map during a move Cells reject requests for tenants they don't own; the router retries after a refresh
Bad map published Validation, staged publishing, instant rollback to the previous version
Cell down Its tenants are affected (by design); others are not; optional regional failover for critical tenants

Never serve a tenant you don't own

During a move, two cells may briefly receive requests for the same tenant. The cell that does not currently own the tenant must refuse (or redirect) rather than serve from stale local data. Otherwise you get writes in two places.

Try it

Sketch the routing for a product using subdomains. Write the map format (JSON is fine), the refresh mechanism, and what each component does if the directory is unreachable for 30 minutes. Then add the rule a cell uses to reject requests for tenants it doesn't own.

Recap

  • Identify the tenant early (subdomain, token claim), look up the cell in a directory, forward to the cell.
  • Cache the map at the edge and routers for static stability; version and stage map changes.
  • Design for directory, router, stale-map and bad-map failures; cells serve only tenants they own.

This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.