Scrivio Interview library
ScenarioAdvanced6 min read · updated 12 November 2026

In your shared-database SaaS, one customer now produces 40 percent of the load and their batch jobs slow down every other tenant. What would you do in the short term and long term?

In the short term, I would rate-limit and schedule that tenant's batch jobs and add per-tenant concurrency limits so they cannot take over the shared database, and start measuring resource use per tenant so the problem is visible and contracts or billing can reflect it. In the long term, I would move large tenants to dedicated databases or shards, which needs tenant routing in the data layer, build that move as a repeatable tenant migration because more large tenants will appear, and review the product's isolation promises and pricing tiers with the business owners.

Why this question is asked

The noisy neighbour problem is the price of a shared database: it is cheap because everyone shares the same resources, and it hurts when one tenant uses far more than its share. When one customer produces 40 percent of the load and its batch jobs slow down everyone else, every other customer pays for that customer's success. Interviewers ask this scenario to see whether we can stop the damage quickly, then fix the architecture without overreacting, and involve the business in a question that is partly commercial. In this answer, we will contain the problem in the short term, make per-tenant usage visible, plan the long-term move, make tenant migration repeatable, and review the product's promises.

1Understanding What Is Happening

In a shared database, every tenant's queries compete for the same CPU cores, memory, disk and connections. A batch job that imports 5 million rows or recalculates a year of invoices runs heavy queries for hours. While it runs, it fills the buffer cache with its own data, pushing out other tenants' hot pages, holds many connections, and saturates disk I/O. Other tenants' small queries then queue behind it, and their p99 latency jumps from 50 ms to several seconds.

So the problem has two parts: the tenant's normal interactive load is large, and its batch jobs are bursty and heavy. The short-term measures mostly target the second part, because that is what hurts everyone at specific times.

2Short Term: Limit and Schedule the Heavy Work

The fastest relief is to control when and how hard the batch jobs run. We move them to quiet hours where possible, and break them into smaller chunks with pauses, for example 10,000 rows per transaction with a short sleep, so they never hold locks or saturate I/O for long. Then we add per-tenant concurrency limits in the service: a tenant may run at most a fixed number of concurrent batch tasks and use at most a few of the pool's database connections, while interactive requests get their own share.

Java
// per-tenant limit on concurrent batch work
private final Map<String, Semaphore> batchSlots = new ConcurrentHashMap<>();
void runBatch(String tenant, Runnable job) {
Semaphore s = batchSlots.computeIfAbsent(tenant, t -> new Semaphore(2)); // at most 2 jobs per tenant
if (!s.tryAcquire()) { requeueLater(tenant, job); return; } // wait instead of piling on
try { job.run(); } finally { s.release(); }
}
Step throughShort-term containment
  1. Batch job requestedtenant acme, 5 million rows
  2. Tenant under its concurrency limit?
    YesStart in chunks of 10,000 rowsNoQueue until a slot frees
  3. Inside quiet hours or a low-load window?
    YesRun at normal paceNoThrottle chunk rate
  4. Record usage per tenantrows, DB time, connections

4 steps in order. Play them, or step through them one at a time.

A rate limit on the tenant's API, for example requests per second per tenant at the gateway, protects against interactive bursts in the same way. We tell the customer about these limits and why; a predictable limit is better for them than a database that slows everyone down, including them.

3Measure Resource Use Per Tenant

We cannot manage what we cannot see. Today the database shows load per query, not per tenant. So we attribute usage: tag requests and jobs with the tenant id in metrics, record database time and rows touched per tenant in the service, and pass the tenant in SQL comments or the application name for batch connections so database-side statistics can be grouped. A weekly view of the top tenants by database time, request volume and storage makes the problem visible to engineering and to the business.

That data also changes the commercial conversation. If one tenant uses 40 percent of the resources and pays 8 percent of revenue, the business can decide whether the contract, the price tier or the limits should change, which is a decision engineers should inform, not make alone.

Weekly usage per tenant (example)
TenantShare of DB timeShare of revenuePeak connections
acme40%8%38
globex9%11%7
initech6%5%4
other 1,240 tenants45%76%41
Usage and revenue side by side make the business decision concrete.

4Long Term: Move Large Tenants Out

The structural fix is to stop large tenants sharing a database with small ones. We move acme to a dedicated database or to its own shard. That requires tenant routing in the data layer: a tenant directory that maps each tenant to its database, a data source per location, and a routing component, for example a routing data source keyed by the tenant from the request context, so services stop assuming one database. Once routing exists, acme's batch jobs only slow acme, and its database can be sized and tuned for its workload.

5Make Tenant Migration Repeatable

acme will not be the last large tenant. So we design the move as a repeatable operation, not a one-off project. The steps are the same every time: create the target database at the current schema version, copy the tenant's rows with a backfill, keep them in sync with change data capture filtered by tenant, verify counts and checksums, then cut over by pausing the tenant's writes for a few seconds, draining the change stream, switching the directory entry and resuming. The old rows are kept until the move is confirmed, so we can switch back.

Once this is automated and rehearsed, moving a tenant becomes routine, and the platform can define a rule such as any tenant above 10 percent of a shared database's load moves to dedicated capacity.

Step throughMoving tenant acme to a dedicated database
MigratorShared DBDedicated DBTenant directory
backfill acme's rows
insert copied rows
CDC stream for tenant acme
pause acme writes, drain stream
verify counts and checksums
acme -> dedicated DB
resume writes, keep old rows for rollback

7 messages in order. Play them, or step through them one at a time.

6Reviewing Isolation Promises and Pricing

Finally, this is a product question. What does the product promise each customer about performance and isolation? If the answer is nothing explicit, that is the gap that let one customer degrade everyone. With the business owners, we can define tiers: a standard shared tier with documented limits, and a dedicated tier with its own database, higher limits and a price that covers the cost. That turns the noisy neighbour from an incident into a sales conversation, and gives engineering clear rules for limits and placement.

7Follow-up questions

Would you throttle the large tenant without telling them?

No. Limits should be documented and communicated, ideally with the account team, and expressed as fair-use rules that apply to every tenant. Surprising a large customer with silent throttling damages trust, and they may see it as an outage.

Could database features help in the short term?

Some. A per-role connection limit for the batch user, statement timeouts for batch connections, and running the heavy reads against a replica can all reduce the impact. They complement application-side limits but do not replace them.

What if the large tenant's data cannot easily be separated?

Then the first long-term task is to find the tables without a tenant column or with cross-tenant references, and fix them, because the same problem will block any future tenant move, sharding or per-tenant restore.

8Conclusion

In this answer, we contained a noisy tenant in the short term with scheduled, chunked batch jobs, per-tenant concurrency limits and rate limits, and made usage visible per tenant so the business could see cost against revenue. In the long term, we move large tenants to dedicated databases or shards behind tenant routing, make that move a repeatable migration with backfill, change data capture and a short cutover, and review isolation promises and pricing tiers with the business owners.

What to say in the interviewAbout 90 seconds aloud

Open with

In the short term I would stop the batch jobs from hurting everyone. I would schedule them in quiet hours where possible, run them in small chunks, and add per-tenant concurrency limits, for example at most two batch jobs and a few database connections per tenant, plus a per-tenant rate limit at the gateway, and I would tell the customer about the limits.

Then, if they want more

At the same time I would start measuring resource use per tenant, database time, rows, requests and connections, so we can see that this tenant uses 40 percent of the load and compare it with what they pay. That gives the business what it needs to adjust contracts or pricing.

In the long term, large tenants should not share a database with small ones. I would add tenant routing in the data layer, a tenant directory mapping each tenant to its database, and move this tenant to a dedicated database or shard.

Because more large tenants will appear, I would build the move as a repeatable migration: copy the data, sync it with change data capture, verify, then a short cutover with a few seconds of paused writes and a way back.

Finally, I would work with the business owners on clear isolation promises and tiers, such as a shared tier with documented limits and a dedicated tier priced for its cost.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "In your shared-database SaaS, one customer now produces 40 percent of the load and their...": https://scrivio-interview-library.netlify.app/databases/database-scaling/57cf4fdca5/