Course contentsShow
← Databases & SQL
Lesson 1708 of 1,95316. Distributed Data ArchitecturesFree lesson

Shard Isolation and Multi-tenancy

Prevent noisy neighbor issues by enforcing resource limits on a per-shard basis.

In this lesson, you will learn how to prevent noisy neighbor issues in multi-tenant distributed systems by enforcing strict resource boundaries on individual database shards.

The Noisy Neighbor Problem

In a multi-tenant environment, you often host data for multiple customers (tenants) across the same physical or logical shards. A "noisy neighbor" occurs when one tenant executes an expensive, resource-heavy query or floods the system with writes, consuming all available CPU, memory, or I/O bandwidth. Without isolation, this spike degrades the performance of every other tenant sharing that same shard, leading to an unpredictable user experience.

Implementing Shard Isolation

To mitigate this, we move beyond simple sharding and implement Resource Quotas and Admission Control at the shard level. By decoupling the resource lifecycle of a shard from the global cluster capacity, we ensure that no single tenant can starve the infrastructure.

Consider a system using directory-based sharding where we map tenant IDs to specific shards. We can enforce isolation by placing a "wrapper" or middleware layer between the Query Proxy and the shard:

-- Conceptual limit policy for Shard_A
-- This is enforced at the connection pool or proxy level
SET SESSION max_cpu_percent = 20;
SET SESSION max_concurrent_queries = 5;

-- Tenant A's query remains within bounds
SELECT * FROM orders WHERE tenant_id = 'A' AND status = 'pending';

By setting strict concurrency limits (max_concurrent_queries) and throughput caps on a per-shard basis, the proxy can reject or throttle incoming requests that exceed the allocated budget for that tenant. If Tenant A hits their threshold, their queries are queued or dropped, leaving the remaining capacity available for other tenants residing on that same shard.

Strategic Placement

Isolation is most effective when paired with your previous knowledge of consistent hashing and hotspot mitigation. By dynamically remapping tenants—moving a "noisy" tenant from a high-density shard to a dedicated, low-density "sandbox" shard—you can restore stability to the rest of the cluster while maintaining performance for the power user.

Ultimately, resource-constrained sharding transforms multi-tenancy from a "best-effort" performance model into a predictable, tiered service level agreement (SLA) architecture.

Key Takeaway: To prevent noisy neighbors, you must treat shards as isolated resource containers by applying query quotas and throughput limits that prevent any single tenant from monopolizing the shard’s underlying hardware.