Multi-tenant SaaS Platforms — Cells, Rings & Progressive Delivery›04 · Moving a tenant between cells

Lesson 04 of 16 · Cells

Moving a tenant between cells

Move a tenant from one cell to another with a short, per-tenant write pause instead of downtime: provision, bulk copy, stream changes, wait for lag near zero, pause writes, flip the routing map, verify, keep a rollback point, and automate the whole thing so moves become routine.

Architect
Key wordstenant migrationcell rebalancingchange data captureCDClogical replicationwrite freezecutoverdual writeverificationrollback pointworkflow engine

When you need to move tenants

  • A tenant outgrew its shared cell and needs a dedicated one.
  • A cell is too full and needs rebalancing.
  • You are replacing a cell (new version of the infrastructure, new region).
  • A customer needs a different region or compliance level.

If moves are rare, risky and manual, cells will slowly fill and you'll avoid using them. Make moves routine and automated.

Moving a family to a new house: you pack most things first (bulk copy) while they still live in the old house, bring over the last daily items on moving day (changes), ask everyone to stop using the old kitchen for an hour (write pause), change the address with the post office (routing flip), check nothing's missing (verify), and keep the old keys for a week in case (rollback point).

The move, step by step

1. Provision   tenant config, schema, buckets, topics in the target cell (from code)
2. Bulk copy   snapshot of the tenant's rows, objects, search documents → target
3. Stream      change data capture (logical replication, CDC tool) source → target
4. Catch up    wait until replication lag for this tenant is near zero
5. Pause       mark tenant "moving": reject or queue writes for this tenant only (seconds),
               let in-flight writes finish, confirm the last changes arrived
6. Flip        update the tenant → cell map; routers refresh; target cell now owns the tenant
7. Resume      writes go to the target; source cell rejects the tenant (lesson 3's rule)
8. Verify      counts, checksums of key tables, synthetic requests as the tenant
9. Keep        source read-only for N days as the rollback point; then delete

Typical tools: PostgreSQL logical replication filtered to the tenant (or a CDC pipeline such as Debezium), object-storage sync, re-indexing for search. In a pooled database, filter by tenant_id; with a database or schema per tenant, the move is simpler.

Keeping the pause short and safe

  • The pause covers one tenant, not the cell.
  • Clients see a brief "retry" (HTTP 503 with Retry-After) or writes queue; reads can often continue.
  • Measure lag continuously and only pause when it is near zero, so the pause is seconds, not minutes.
  • Dual writing (writing to both cells) avoids the pause but is much harder to get right (ordering, failures halfway). Prefer a short pause.

Verification and rollback

  • Automated checks: row counts per table, checksums on key tables, recent records present, background jobs running in the target.
  • A rollback point: keep the source read-only (or set up reverse replication) so the map can be flipped back if something is wrong.
  • A post-move watch: error rates and latency for that tenant for a day.

Automate it

Run moves as a workflow (a workflow engine such as Temporal or Step Functions, or a Kubernetes operator) with explicit states (provisioning, copying, streaming, paused, flipped, verifying, done, rolled-back), retries and an audit trail. Then moves can be scheduled, rate-limited (a few at a time) and handled by on-call without a specialist.

Say it precisely

A tenant move is "near-zero downtime with a short, per-tenant write pause and a rollback point", not "zero downtime". Promising zero leads to dual-write designs that fail in rare, nasty ways.

Try it

With two PostgreSQL instances (two containers is enough), create a table with tenant_id, insert rows for tenants A and B in the first, and set up a logical replication publication filtered to tenant A (CREATE PUBLICATION … FOR TABLE t WHERE (tenant_id = 'A'), PostgreSQL 15+). Subscribe from the second instance, keep inserting rows for A, then simulate the pause and flip by stopping writes, checking counts match, and pointing a client at the second instance.

Recap

  • Moves are about data: provision, bulk copy, stream changes, catch up, pause briefly, flip the map, verify, keep a rollback point.
  • Pause one tenant for seconds rather than attempt dual writes.
  • Automate moves as a workflow with states and audit, so rebalancing is routine.

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