Domain tracks · L2Multi-tenancy and noisy neighbours

Multi-tenancy and noisy neighbours

Many customers share one system. Learn to keep their data apart and stop one busy customer from slowing down everyone else.

L2 SeniorDomain tracks19 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 21 Oct 2026 · How we check content
Senior at work · lesson 21 of 26
Section 1 of 8

What broke

A made-up story to show a common failure. Not about a real company.

This story is made up, but it is common. A small company sells invoicing software to 400 businesses. All of them share one set of app servers and one Postgres database. This is cheap and easy to run.

On the last day of the year, the biggest customer starts a full export of five years of invoices. It runs as hundreds of heavy queries at once. The database CPU goes to 100%.

Every other customer now waits 20 seconds to open an invoice. Support gets messages from 399 businesses that did nothing wrong. The on-call engineer sees "database slow" on the dashboard, but nothing says which customer is causing it.

It takes an hour to find the export and stop it. Then a second question comes: "Could a slow query ever return another customer's invoices?" Nobody is sure. Every query has WHERE tenant_id = ?, but only because developers remembered to add it.

Section 2 of 8

The idea in simple words

A tenant is one customer organisation, such as one company. Multi-tenancy means one running system serves many tenants. The tenants share code, servers and often databases, but each must feel like it has the system to itself.

You must keep tenants apart in two ways:

  1. Data. A tenant must never see another tenant's data. A 2020 AWS whitepaper calls crossing this line "a significant and potentially un-recoverable event" for a SaaS (software as a service) business. 3
  2. Performance. One tenant must not make the system slow for the rest. This is the noisy neighbour problem: one user puts so much load on shared resources that other users suffer. 2

The key idea. Sharing makes SaaS cheap. Every shared thing is also a path for a leak or a slowdown. Decide what to share on purpose, and isolate each shared thing.

Section 3 of 8

How it works

Silo, pool and bridge

AWS names three models. 1

  • Silo model. Each tenant gets its own resources, such as its own database or even its own full stack.
  • Pool model. Tenants share resources. This is classic multi-tenancy, and it lowers the cost per tenant as you grow.
  • Bridge model. A mix. Some services are siloed and others are pooled. Strict data rules or noisy load can push one service to silo. Cost and agility can push another to pool.

The pool is cheapest, because it scales with the real load of all tenants. The same 2020 whitepaper lists its costs too: noisy neighbours, harder cost tracking per tenant, and a bigger blast radius. One outage will likely hit every tenant. 4

You can mix models by price tier. Basic tenants share a pool, and premium tenants pay for their own stack. A 2022 AWS whitepaper (now archived) adds a warning: every silo should run the same version and setup as the pool, with no one-off changes. 5 If you skip this, you end up running many different products.

Tenant id everywhere

In a pool, the tenant id is the only thing that keeps data apart. Our advice:

  • Put tenant_id on every row of every tenant table, and in every index that starts a lookup.
  • Read the tenant from the login token once, at the edge. Pass it down in a request context. Never trust a tenant id from the request body.
  • Put the tenant id in every log line, metric label, cache key, queue message and file path.

A cache key like invoice:991 can leak data between tenants. Use tenant:42:invoice:991.

Row-level security

Remembering WHERE tenant_id = ? in every query is not enough. One missed filter leaks data. Row-level security (RLS) moves the rule into the database.

In PostgreSQL, you turn on RLS for a table and add a policy. If RLS is on but no policy exists, the default is to deny: no rows are visible. 6 A common tenant policy reads the current tenant from a session setting:

ALTER TABLE invoices ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation ON invoices
  USING (tenant_id = current_setting('app.current_tenant')::uuid);

The app sets app.current_tenant at the start of each request. Now the database adds the filter to every query. 7

Know the traps:

  • Superusers and roles with BYPASSRLS always skip the policies. The table owner usually skips them too, unless you use FORCE ROW LEVEL SECURITY. 6 So the app must connect as a role that does not own the tables. 7
  • Session settings may not work with a connection pooler such as PgBouncer, which can share session state. 7 Our advice: set the tenant inside each transaction, for example with SET LOCAL, and test it.

Noisy neighbours and per-tenant limits

The first wall is a per-tenant limit. Amazon describes fairness as giving every client "a single-tenant experience". Its services set quotas per tenant. A common way to enforce them is a token bucket. 8 See rate limiting for how a token bucket works.

Not all requests cost the same. Amazon notes that the cost of a call is not always known up front, and some services count large responses as several requests. 8 Our advice: limit the costly things separately. Cap each tenant's concurrent exports, background jobs and database connections, not just requests per second.

Tell tenants about their limits. Amazon's services show clients their quota and how close they are to it. 8

Cells

Limits stop one tenant from using too much. Cells stop one failure from reaching everyone.

A cell is a full, independent copy of your workload. It shares no state with other cells and serves only some of the tenants. A thin cell router sends each request to the right cell, using a partition key such as the customer id. With 10 cells, a failure in one cell leaves 90% of requests unaffected. 10

Shopify does this with pods. Each pod is a set of shops on its own fully isolated datastores. Sorting Hat, software in Shopify's load balancers, sends each request to the right pod. This keeps one shop from "sucking up database time across the platform". 11

Shuffle sharding

Shuffle sharding goes one step further. Amazon's example has 8 workers. 9

  • With no sharding, a bad customer can crash all 8 workers. Everyone is down.
  • With 4 fixed shards of 2 workers, a bad customer crashes one shard. That is 25% of customers. 9
  • With shuffle sharding, each customer gets a random pair of workers. There are 28 possible pairs. A bad customer crashes its own pair. Only customers with that exact pair lose everything. The impact drops to 1/28, which Amazon calls 7 times better than plain sharding. 9

Every other customer shares at most one worker with the bad customer. They keep working if their clients retry on the other worker. 9 Route 53 uses 2,048 virtual name servers and gives each domain 4 of them. That makes about 730 billion possible shuffle shards. 9

Step through it with Next and Back, or the ← and → keys.

One big tenant's spike: a shared pool slows everyone, shuffle sharding contains it8 shared workers W1 W2 W3 W4 W5 W6 W7 W8 A · pool: every tenant uses every workerBig, Rose, Sun and 397 more Big runs a huge export · all 8 busy Rose, Sun and everyone else wait B · shuffle sharding: 2 workers eachBig → W1 + W4Rose → W1 + W8Sun → W4 + W68 workers give 28 possible pairs Big's spike fills only W1 and W4✓ Rose uses W8, Sun uses W6only Big's exact pair (1 in 28) is down SeniorPath
  1. Path A, a shared pool. Eight workers serve 400 tenants. Every tenant's requests can land on any worker. This is cheap, because no worker sits idle.
  2. The biggest tenant, Big, starts a huge export. Its heavy requests spread over all eight workers and fill every one of them.
  3. Every other tenant now waits behind Big's work. Rose and Sun did nothing wrong, but their pages time out. One tenant's spike became everyone's outage.
  4. Path B, shuffle sharding. Each tenant gets its own random pair of workers. Big has W1 and W4, Rose has W1 and W8, and Sun has W4 and W6. Eight workers give 28 different pairs.
  5. Big's spike now fills only W1 and W4. Rose shares W1 but still has W8. Sun shares W4 but still has W6. If their clients retry on the other worker, they keep working. Only a tenant with Big's exact pair is hurt.
Step 1 of 5

Big tenants and observability

Some tenants are much bigger than the rest. Our advice: give them their own cell or silo, as a paid tier, before they become a problem. Move them in a planned migration, not during an incident.

Amazon puts the throttle key and the rate limit in its request log on every request. 8 Build dashboards for the top tenants by requests, CPU time and errors. Your first question in an incident should be "Which tenant?", and the answer should take seconds.

Section 4 of 8

Trade-offs

ModelData isolationNoisy neighbour riskCost per tenantUse it when
SiloYes Separate resources.No Its resources are its own.High. Idle capacity, many copies to run.Strict data rules, or big tenants who pay for it.
PoolOnly by tenant id and RLS.Yes Needs per-tenant limits.Low. Scales with real load.Many small tenants.
BridgeMixed, per service.Mixed.Medium.Some data or services need a silo, the rest do not.
CellsYes , between cells.Only inside one cell.Medium. Needs a router and a system to manage the cells.You must limit how many tenants one failure can hit.
Shuffle shardingNot by itself.Rarely shared fully.Low to medium.Many tenants, and clients that can retry on another worker.

Our simple rule: start with a pool, RLS and per-tenant limits. Add cells when one failure would hurt too many tenants. Give the biggest tenants a silo as a paid tier.

Section 5 of 8

At work: how a senior uses this

  • In every design review, ask: "Where is the tenant id here, and what stops a query without it?"
  • Write a test that logs in as tenant A and tries to read tenant B's data through every API. Run it in CI.
  • Ask: "What is the most one tenant can use?" Check requests, connections, jobs, storage and export size.
  • Put tenant id on every log line and metric, so on-call can see who is noisy and who is hurt.
  • Keep a list of your largest tenants and their growth. Plan their move to a bigger tier early.
  • Keep every silo on the same version as the pool. Treat a "special build for one customer" as a warning sign.
  • Before an incident, know your blast radius: how many tenants share each database, cell and queue.
Section 6 of 8

With AI

What to ask the agent

"Add PostgreSQL row-level security to these tables. Use a policy on tenant_id that reads current_setting('app.current_tenant'). The app role must not own the tables."

"Find every query, cache key and queue message in this service that does not include the tenant id. List them by file and line."

"Write an integration test: log in as tenant A, then call every read endpoint with ids that belong to tenant B. Every call must return 404 or 403."

"Add a per-tenant limit on concurrent export jobs, 2 per tenant, stored in Redis. Log the tenant id and the limit when a job is rejected."

What to check yourself

  • The app connects as a role that does not own the tables and does not have BYPASSRLS. Otherwise RLS does nothing.
  • The tenant id comes from the auth token, not from a header or body the client controls.
  • The tenant setting is set per transaction and cannot leak to the next request on a pooled connection.
  • Cache keys, file paths and search indexes include the tenant id, not only database rows.
  • Limits are per tenant, not global. A global limit lets one tenant use it all.
Section 7 of 8

Check yourself

1. Your app runs one shared Postgres database for all tenants. What protects you best if a developer forgets a tenant filter in one query?

Show answer

Row-level security on the table, with the app connecting as a role that is not the table owner. Row-level security adds the tenant filter inside the database, for every query. The table owner skips it by default, so the app must use another role.

2. Which model gives the strongest isolation, at the highest cost per tenant?

Show answer

Silo. In the silo model each tenant gets its own resources. Nothing is shared, but you pay for idle capacity and run many copies.

3. You have 8 workers. Each tenant gets a random pair of 2 workers (shuffle sharding). How many different pairs are there?

Show answer

28 There are 8 × 7 / 2 = 28 pairs. A bad tenant takes down its own pair. Another tenant loses both workers only if it has the exact same pair.

4. One tenant's traffic grows 50 times in an hour. What should stop it from hurting the others first?

Show answer

A per-tenant quota or rate limit that rejects the extra requests early. A per-tenant limit rejects the extra requests at once and affects only that tenant. Autoscaling is slower and shares the new capacity with the noisy tenant.

5. Why should you log the tenant id on every request?

Show answer

So you can see which tenant uses the most capacity, and who is affected in an incident. Without the tenant id, a dashboard shows "the system is slow" but not "tenant 42 is causing it" or "tenants 7 and 9 are hurt".

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 11 sources and related lessons
  1. AWS, “Silo, Pool, and Bridge Models”, SaaS Lens, AWS Well-Architected Framework (opens in a new tab)
    Short definitions of the three models, and why one service might be siloed while another is pooled.
  2. AWS, “Noisy Neighbor”, SaaS Lens, AWS Well-Architected Framework (opens in a new tab)
    What a noisy neighbour is and why it matters more when tenants share resources.
  3. AWS, SaaS Tenant Isolation Strategies whitepaper (2020, now marked historical), introduction (opens in a new tab)
    Why tenant isolation is a core part of any SaaS design.
  4. AWS, “Pool isolation”, SaaS Tenant Isolation Strategies whitepaper (2020, now marked historical) (opens in a new tab)
    Pros and cons of the pool model, including noisy neighbours, cost tracking and blast radius.
  5. AWS, “Full stack silo and pool”, SaaS Architecture Fundamentals whitepaper (now marked historical) (opens in a new tab)
    Basic tier tenants in a pool and premium tenants in their own stacks, all on one version.
  6. PostgreSQL documentation, “Row Security Policies” (section 5.9) (opens in a new tab)
    How row-level security works, the default-deny rule, and who bypasses it.
  7. Michael Beardsley, “Multi-tenant data isolation with PostgreSQL Row Level Security”, AWS Database Blog, 2020 (opens in a new tab)
    A tenant policy that reads the tenant from a session setting, plus traps with owners and connection pools.
  8. Amazon Builders' Library, “Fairness in multi-tenant systems”, 2020 (opens in a new tab)
    Per-tenant quotas, token buckets, telling clients their quota, and logging the throttle key.
  9. Amazon Builders' Library, “Workload isolation using shuffle-sharding”, 2019 (opens in a new tab)
    The 8-worker example, the 1 in 28 maths and Route 53's 730 billion shuffle shards.
  10. AWS, “What is a cell-based architecture?”, Reducing the Scope of Impact with Cell-Based Architecture whitepaper (opens in a new tab)
    Cells, the partition key, the thin cell router and how cells limit a failure.
  11. Xavier Denis, “A Pods Architecture To Allow Shopify To Scale”, Shopify Engineering, 2018 (opens in a new tab)
    Groups of shops on their own datastores, with a routing layer in front.

Case studies: Amazon: Shuffle sharding: shrink the blast radius of one bad customer · Shopify: Pods: splitting Shopify into isolated groups of shops · Slack: Shared channels broke the one-workspace-per-shard rule · Slack: Moving from per-workspace shards to Vitess · Swiggy: Turning a delivery monolith into a logistics platform

Related: Sharding and consistent hashing · Rate limiting · Cell-based architecture (coming soon) · Load shedding and graceful degradation · Tenant onboarding, observability and cost (coming soon) · Authorization models: RBAC, ABAC and ReBAC · Observability, SLOs and error budgets

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper