Interview: 5,000 customers share one database, and one of them slows down everyone

Pooled vs schema vs database per tenant vs hybrid: noisy neighbour, restore one tenant, leaks, gradual schema rollout, moving a big tenant out, and the…

More on Ticket interviews

Keep learning

Overview

ui-monospace, SFMono-Regular, Menlo, monospace Schema per tenant Database per tenant Heavy export Restore to yesterday Bug in access check New column rollout one big shared room Schema each flats in one building Database each separate houses flats plus a big house Four ways to house tenants: one shared room, flats in one building, a separate house each, or flats for most plus a house for the biggest tenant. does it shared tables, tenant_id column spring sale june news VIP list One shared table with a tenant_id column. A query that filters tenant_id equals E sees only E's three rows. Without the filter it would see everyone's rows. tenant_id list_name SELECT * FROM lists Every query must carry this filter. Forget it, and you read everyone's rows. Database CPU share. Without limits the giant tenant takes 70 percent. With a per-tenant cap of 30 percent, everyone else gets 70 percent. Illustrative. Without limits (illustrative) With a per-tenant cap of 30% (illustrative) Share of the database's CPU. A cap protects the others, but the giant tenant now waits. Rolling a two-second schema change over 5000 tenants takes about 2.8 hours one at a time, or about 8 minutes 20 at a time. Illustrative. 5,000 tenants × 2 seconds each (illustrative) one at a time: 2.8 h 20 at a time: 8 min In a pool it is one change, everyone at once. Per tenant you can start with a few and stop if it goes wrong. Cell 1 · EU Cell 2 · US Cell 3 · US E (big) A directory sends each tenant to a cell. Each cell has its own app servers and database, and sits in a region. A fault in cell 3 does not reach cells 1 and 2. Directory: tenant → cell, region has a fault keeps working App servers and storage are grouped together, so a fault stays inside its cell. How tenants are hosted What happens Which tenant (E is the big one) Other tenants hurt Maybe hurt At 5,000 tenants, things to run a few pools + 1 per big tenant What to notice: pooling is the cheapest and spreads every problem to everyone. Separate databases contain the problem but cost more to run. Hybrid pays for isolation only where it is needed. E is big and lives in the pool. The directory says so. Create E’s own database and copy its rows. E keeps running. Catch up Keep copying new changes until both are level. Pause E’s writes briefly, check counts, flip the directory entry. Serve from the new home E reads and writes its own database. Old rows kept as a safety net. Clean up Delete E’s rows from the pool. E can’t slow the others now. Shared pool E's own database not created yet copying rows level with the pool = 1 && step Directory: tenant → home D → pool E's database E's requests go to the pool Start the move Next step What to notice: the directory changes last. It is the one small table that says where each tenant lives, so moving a tenant never means changing application code. 5,000 customers (tenants) share one database. One big export slowed them all. schema per tenant database per tenant noisy neighbour Shared room, flats, or houses How should 5,000 tenants be hosted, given one giant, a restore request and an EU rule? 5,000 (illustrative) Biggest tenant about 40% of traffic Everyone else, p99 10× slower (illustrative) Open requests restore one tenant · keep one in the EU 5,000 tenants: about 4,900 tiny, 99 medium, 1 giant. Two have EU residency rules. What do you build? Hybrid: pooled shards for small tenants, a database of their own for the giant and the EU tenants, and a directory Isolation where needed Cost per small tenant Operations load Keep everything pooled and add per-tenant limits Limits tame the noisy neighbour. No EU home, and restore stays hard. A separate database for every one of the 5,000 tenants Perfect isolation, but 5,000 mostly idle databases to patch and back up. What is the difference between pooled and a database per tenant? explain simply Pooled: a tenant_id column, and every query must filter on it. Schema per tenant sits between: own tables, shared server. tenant_id on every query cost vs isolation names the middle option One tenant slows everyone down. What do you do in a pooled setup? what breaks if Cap each tenant, find who it is, and move a chronic giant out. They share CPU, memory cache, disk and locks. Tag every metric with tenant_id, or you are guessing. shared resources moves the big one out A schema change takes 2 seconds on one tenant. How long to roll it out to 5,000? The win is safety: try a few tenants, watch, stop early. does the arithmetic gradual rollout is the benefit two versions at once The biggest tenant has outgrown the shared pool. How do you move it? what would you do instead Copy, catch up, pause briefly, flip the directory entry. The directory is the small table mapping tenant → home. Keep old rows briefly as a safety net, then delete. copy, catch up, switch a directory tenant must fit one node A customer deleted data by mistake and wants yesterday's version. How do you restore only them? Own database: restore it alone. Pooled: a slow manual side-restore. Pooled full restore would erase everyone’s work since yesterday. So restore to a side copy, pull rows by tenant_id, copy back. If per-tenant restore is a promise, that justifies per-tenant units. unit of backup side restore for pooled links to compliance Product wants a dashboard across all customers, and EU customers must stay in the EU. Now what? staff curveball Group servers and storage into cells so a fault stays in one cell. The directory is now critical: small, cached, replicated. separate analytics copy region in the directory cells and blast radius How would you host 5,000 customers in one SaaS product? Ask first Biggest tenant? Size spread? Region rules? The risks Noisy neighbour, leaks, hard restore. Cap and tag. Big or regulated Own database, via a directory. The cost Directory, tooling, separate analytics copy. One model for every tenant Too costly for the small, too weak for the big. Trusting every WHERE tenant_id One missing filter leaks data. Enforce it in one place. No per-tenant metrics or limits You can’t tell who is slowing things, or stop them. The tenant that outgrows one node Per-tenant databases assume it fits. Plan for the giant. Three models, one cost each Noisy neighbour, two fixes Restore one tenant in each model Move: copy, catch up, switch Cross-tenant reports and residency E keeps running stream new changes Pause + check counts match Flip directory E → own DB delete old rows

5,000 customers share one database, and one of them slows down everyone

One tenant’s export made everyone 10× slower All 5,000 tenants share one pooled database 1 · The story in plain words Shared room Cheapest. One loud family wakes everyone. Locked doors, shared walls and pipes. schema each Quiet and private. 5,000 to build and clean. database each Flats for the many, a house for the big one.

A big customer's export made the whole product slow

5,000 tenants share one database, split by a tenant_id column. At 9:00 the biggest tenant’s export made everyone ~10× slower. Noisy neighbour One export slows 4,999 others. Restore one tenant The backup holds everyone. Stay in the EU One database lives in one place.

Pick a hosting model, then break something

Pick a model, an event and a tenant. See who gets hurt. Now move the big tenant out while the product stays up.

Four ways to host tenants

Cheap per tenant Noisy neighbour contained Restore one tenant Gradual rollout Region per tenant Pooled (tenant_id column) Schema per tenant Database per tenant Hybrid + directory Four ways to host tenants Pooled pays in Leaks from one missing filter, manual restores, everyone changes at once. Per-tenant pays in Overhead per database, hard cross-tenant joins, each tenant must fit one node.

More courses

  • Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
  • Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
  • React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
  • System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
  • NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
  • Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
  • Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
  • AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
  • Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
  • TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
  • CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
  • Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
  • Docker — What an image is, why layers cache, and how containers find each other on a network.
  • Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
  • Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
  • AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
  • Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.