Lesson 3 of 8 High Availability and Resilient Design Patterns

Isolating Noisy Customers with Shuffle Sharding

This lesson explains how shuffle sharding assigns each customer a small, random combination of workers in a shared multi-tenant service, so the damage one noisy or malicious customer can do is shared by very few others.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish shuffle sharding from simple sharding.
  • Explain the arithmetic that makes overlap rare.
  • Identify where AWS uses shuffle sharding.

From sharding to shuffle sharding

Without any sharding, every customer's requests can land on every worker, so one customer whose requests crash workers, a so-called poison request, can bring down the whole fleet, and every customer is affected. Plain sharding divides the workers into fixed groups and assigns each customer to one group. A poison request now brings down only its group, but every customer in that group shares the outage: with eight workers in four groups of two, a quarter of all customers are affected.

Shuffle sharding instead gives each customer its own combination of workers, chosen from the whole pool, sometimes called a virtual shard. Two customers may share one worker, but very few share the same combination, so when a poison request brings down a customer's workers, almost every other customer still has at least one healthy worker in its own combination.

The following diagram compares the two approaches with eight workers and two customers.

Plain sharding compared with shuffle sharding over eight workers. With plain sharding in four groups of two, customers A and B share group 1, so A's poison request takes down both of B's workers. With shuffle sharding, A is assigned workers 1 and 4 and B workers 1 and 6, so when A's workers fail, B still has worker 6.
Red workers are the ones customer A's poison request has brought down. The worker assignments are an example.

The arithmetic

The effect comes from the number of possible combinations, which grows very quickly with the size of the pool and the number of workers per customer. The following table shows how many distinct combinations exist for two pool sizes.

WorkersWorkers per customerDistinct combinations
8228
1005About 75 million

With 8 workers and 2 per customer, there are 28 combinations. A customer that brings down both of its workers fully affects only the customers assigned the same pair, about one in 28, rather than one in four with plain sharding; every other customer still has at least one healthy worker. With 100 workers and 5 per customer, a full overlap becomes vanishingly unlikely. The isolation depends on clients using the rest of their shard: a client must retry on another worker in its combination when one fails, or the healthy worker does not help it.

Fill in the value

Shuffle sharding arithmetic

Exam skills 4.3.3

Calculate the effect of sharding choices.

Log in to try this activity Interactive activities are free with an account.

Where it is used

AWS uses shuffle sharding in its own services. In Route 53, each hosted zone is served by a different combination of four name servers drawn from a large pool, so a denial-of-service attack against one customer's domain affects very few other domains. The same idea suits multi-tenant APIs, queues and worker fleets, where giving every tenant dedicated infrastructure would be too expensive but one tenant must not be able to harm the others.

Shuffle sharding combines with other isolation techniques. Per-tenant throttling limits how much load a tenant can send in the first place. Cells bound the worst case, because a failure never leaves its cell, and shuffle sharding within a cell reduces the impact further.

Worked example

Limiting the impact of a poison request

A multi-tenant image processing API runs on a pool of eight worker groups. Occasionally one customer sends an image that crashes the worker processing it, and with simple sharding (four shards of two groups each) every customer in that shard suffers an outage. The architect assigns each customer a shuffle shard of two worker groups chosen from the eight:

Possible shuffle shards = C(8, 2) = 8! / (2! x 6!) = 28

Simple sharding:  a crashing customer takes down its whole shard -> 25% of customers affected
Shuffle sharding: only customers with exactly the same two groups lose both workers
                  -> about 1/28 (3.6%) of customers fully affected; others keep at least one healthy group

Clients retry a failed request on the other worker group in their shard, so customers who share only one group with the offender see a single retry rather than an outage. Combined with per-customer throttling at the API layer and a dead-letter queue that quarantines the poison request, the blast radius of one bad customer falls from a quarter of the platform to a few per cent.

Check yourself

Why does shuffle sharding limit the impact of one bad customer?

Show answer

Each customer is assigned a different combination of workers, so other customers rarely share all of the same workers and keep at least one healthy one.

Exam Tips

Remember for the exam

  • To isolate noisy or malicious tenants, use shuffle sharding.
  • Each customer is assigned a random combination of a few workers from the pool.
  • Clients must retry on another worker in their shard for shuffle sharding to help.
  • Shuffle sharding complements per-tenant throttling and cell-based architecture.