---
title: "Find and contain noisy neighbours · Agent Wranglers"
url: https://agentwranglers.se/playbook/data/multi-tenancy/noisy-neighbours
id: DAT-73
level: Recommended
updated: 2026-10-22
tokens: 980
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Find and contain noisy neighbours

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Multi-tenancy](https://agentwranglers.se/playbook/data/multi-tenancy.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-22.

- ID: DAT-73
- Level: Recommended
- Chapter: [Multi-tenancy](https://agentwranglers.se/playbook/data/multi-tenancy.md)
- Rule: Measure database time per tenant, and give each tenant its own query time limit and job share. Move a tenant that uses more than a quarter of the database time to its own resources.
- Check: A dashboard lists the 10 tenants with the most database time over the last 24 hours. An alert fires when one tenant passes 25% of the total for an hour. On staging, one tenant runs a heavy report, and another tenant's p95 page time stays within 20% of its baseline.
- How: In shared tables, one tenant's large report slows every other tenant's pages. Tag each query with the tenant, in a SQL comment or the connection's `application_name`. The slow query log and query statistics then group by tenant. Cap each tenant's running jobs, as [Give each customer a fair share](https://agentwranglers.se/playbook/scaling/load-balancing-and-autoscaling/per-tenant-limits.md) shows. Set the query time limit from [Set time limits on every query](https://agentwranglers.se/playbook/data/operations/query-timeouts.md) per role or per tenant tier. A tenant that stays above a quarter of the load moves to its own database. That is the mixed model in [Choose the isolation model before the first customer](https://agentwranglers.se/playbook/data/multi-tenancy/tenant-isolation-model.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
export const tagQuery = (tenantId, sql) => `/* tenant_id=${Number(tenantId)} */ ${sql}`;

const rows = await db.any(tagQuery(req.tenant.id, 'SELECT id, total FROM invoices WHERE due_at < now()'));
```

### Python example

```python
def tag_query(tenant_id: int, sql: str) -> str:
    return f"/* tenant_id={int(tenant_id)} */ {sql}"

rows = conn.execute(tag_query(tenant.id, "SELECT id, total FROM invoices WHERE due_at < now()")).fetchall()
```

## Sources

- [AWS SaaS Lens, noisy neighbour](https://docs.aws.amazon.com/wellarchitected/latest/saas-lens/noisy-neighbor.html)

## Related rules

- DAT-70 [Put the tenant on every log line and trace](https://agentwranglers.se/playbook/data/multi-tenancy/tenant-in-logs.md) in Data and databases
- SCL-31 [Give each customer a fair share](https://agentwranglers.se/playbook/scaling/load-balancing-and-autoscaling/per-tenant-limits.md) in Scaling
- DAT-37 [Set time limits on every query](https://agentwranglers.se/playbook/data/operations/query-timeouts.md) in Data and databases
- DAT-67 [Choose the isolation model before the first customer](https://agentwranglers.se/playbook/data/multi-tenancy/tenant-isolation-model.md) in Data and databases

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/data/multi-tenancy/noisy-neighbours">Agent Wranglers data and databases playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Delete every copy of a tenant when the contract ends](https://agentwranglers.se/playbook/data/multi-tenancy/tenant-offboarding.md)
- Next: [Give each tenant its own encryption key when customers ask to hold it](https://agentwranglers.se/playbook/data/multi-tenancy/tenant-encryption-keys.md)
- [Multi-tenancy](https://agentwranglers.se/playbook/data/multi-tenancy.md)
