AlgoViz

The AWS Kinesis outage of 2020

medium 26 min

On 25 November 2020 a small capacity addition to Amazon Kinesis in US-EAST-1 pushed every front-end server over an operating system thread limit.

Video lesson · Chapter 1 of 5

The router needs a map

0:00 / 3:48

The Kinesis outage in 75 seconds

1:15Reel coming soon

Theory

Read or listen first. About 2 min.

What it is

Amazon Kinesis carries streams of records. A front-end fleet receives each request, checks who is asking, limits the rate and sends the request to the right place. Behind it, back-end cell-clusters store and process the streams.

On 25 November 2020 AWS added a relatively small number of servers to the front-end fleet in US-EAST-1. Every front-end server keeps an operating system thread for every other one. The addition made all of them exceed a thread limit, so they could not finish building the table that says where each shard lives, and could not route requests.

Every fact and time on this page comes from the report that AWS published. Times are Pacific Standard Time (PST).

Why it exists

It is the textbook case of a hidden limit that depends on fleet size. Nothing about the new servers was bad. The number of servers itself was the problem, and it hit old and new servers alike.

It also shows how a service that others use quietly, for metrics or usage statistics, can stop things that have nothing to do with streaming, such as signing in. And it shows why a fleet that is slow to start is slow to repair.

A short history

  1. 14 November 2013

    AWS announces Amazon Kinesis on its news blog.

  2. 25 November 2020

    The capacity addition to the front-end fleet and the outage described here.

  3. 7 December 2021

    Another large event in the same Region, with a different cause, again slows monitoring and the status page. See that page.

  4. 20 September 2023

    AWS publishes its guidance on cell-based architecture, the approach that the Kinesis team promised to speed up.

Words to know

Front-end fleet
The servers that authenticate, throttle and route requests.
Shard
One ordered part of a stream.
Shard-map
The cached table that says which back-end cluster owns which shard.
Full mesh
Everyone connected to everyone else.
Thread
One line of work that the operating system runs. Each uses memory, and the number is limited.
Cell
A small complete copy of a service that serves some of the customers and fails alone.
Cold start
The slow time after a start while caches are still empty.

How it works

Step through the idea, or press Play.

Step 1 of 3

A few servers are added. Each existing server opens a thread to each new one

Understand it

Start here

The ribbon dance

In this dance everyone holds one ribbon to everyone else. A pair of hands can hold four ribbons. Five dancers are fine. The sixth dancer does nothing wrong, and the whole dance falls apart.

One dancer too many
4 dancers, 3 ribbons eachHands hold 4 at most

The limit was on each pair of hands. The size of the ring decided when it was reached.

Background

How the front end works

Front end and back end

Producers and readers call a front-end server. It routes by shard to back-end cell-clusters 1 and 2. It builds its shard-map from a membership service, configuration in DynamoDB, and messages from other front-end servers.
Pink is the request path. Orange dashed arrows are how a front-end server learns where shards live.
  • Small but important

    The front end does authentication, throttling and request routing. It stores no records.

  • Shard-map

    A cache on each front-end server with membership details and shard ownership of the back-end clusters.

  • Three sources

    Calls to a membership microservice, configuration from DynamoDB, and a steady flow of messages from the other front ends.

  • Cells in the back

    The back end was already split into many cell-clusters. The front end was not yet.

A write on a normal day

Without a complete shard-map the third step has no answer, however healthy the cells are.

What happened

The timeline

25 November 2020, PST

TimeEvent
2:44 AMCapacity begins to be added to the front-end fleet
3:47 AMThe addition is finished. Existing servers need up to an hour to learn of new ones
5:15 AMFirst alarms: errors on putting and getting records. CloudWatch and EventBridge also affected
6:15 AMLambda error rates rise: memory contention from buffered metrics
7:01 AMCognito error rates rise significantly, after extra capacity had first helped
7:51 AMA couple of candidate causes remain. Each would need a full restart of the fleet
9:39 AMRoot cause confirmed: the thread limit, not memory pressure
10:07 AMThe first group of restarted servers takes traffic
10:15 AMCognito starts deploying a change that depends less on Kinesis
10:36 AMLambda hosts are relieved and its error rates recover
12:00 noonFrom here on, the Kinesis error rate drops steadily
2:18 PMCognito is normal
4:15 PMMost ECS and EKS issues are resolved
5:47 PMCloudWatch shows early signs of recovery
10:23 PMKinesis is fully normal
10:31 PMCloudWatch metrics and alarms fully recovered; backfill continues
All from the AWS report.

How long it lasted

22:23−05:15=17 h 08 min=1028 min10280.0001×525600≈19.622{:}23 - 05{:}15 = 17\text{ h }08\text{ min} = 1028\text{ min} \qquad \tfrac{1028}{0.0001 \times 525600} \approx 19.6
From the first alarms to full recovery. That is almost 20 years of a 99.99% yearly allowance (52.56 minutes), if it counted as fully down. Errors fell step by step from noon, so treat it as an upper bound.

Cause

A full mesh meets a fixed limit

For messages between front ends, each server creates operating system threads for each of the other servers. If there are NN servers, one server needs a number of threads that grows in step with NN, and the fleet as a whole grows with NN squared.

Threads per server, and in the whole fleet

Tserver=b+k (N−1)Tfleet=N Tserver≈k N2T_{\text{server}} = b + k\,(N-1) \qquad T_{\text{fleet}} = N\,T_{\text{server}} \approx k\,N^2
bb is the threads for requests and other work, kk the threads per neighbour. The report says the total each server must maintain is directly proportional to the number of servers.

An example with invented numbers

Servers NThreads per serverLimit 10,000Fleet total
2,000500 + 2,000 - 1 = 2,49925% usedabout 5 million
4,0004,49945% usedabout 18 million
8,0008,49985% usedabout 68 million
9,50110,000exactly fullabout 95 million
9,50210,001over, on every serverabout 95 million
Assumes b = 500 and k = 1. AWS has not published its fleet size, limit or thread counts. It says only: many thousands of servers.

From an addition to no routing

The trigger was the addition. The cause was a design in which one fixed limit was shared by every server.

Diagnosis

Why finding it took over four hours

  1. 1

    The suspect did not explain everything

    New capacity was suspected at once, but a number of errors seemed unrelated and likely to persist without it. It was removed as a precaution, while research went on.

  2. 2

    Too many kinds of error

    Errors appeared in all aspects of the calls made by existing and new servers, so side effects hid the cause.

  3. 3

    A convincing wrong candidate

    The leading idea was memory pressure. It looked promising and was not the cause.

  4. 4

    A wrong fix was expensive

    Every candidate needed a new configuration and a restart of every server. A wrong guess would have doubled the recovery time.

Alarms first fired at 5:15 AM, although the addition was finished at 3:47 AM and servers learn of newcomers within an hour. A delayed effect makes the cause look innocent. This is why use against a limit deserves its own alarm, long before errors.

Watch these

  • Threads, file handles and connections as a share of the limit
  • Size and age of the shard-map
  • Share of requests with no route
  • Growth per server added

Not enough

  • CPU and memory only
  • Error rate only
  • Averages over the fleet
  • Testing only the new servers

Repair

Why the restart took twelve hours

Inside a front-end server, the work of filling the shard-map competes with the work of serving requests. If many servers start at once, each has few resources left for requests, becomes slow, may be judged unhealthy and is removed, which sets the recovery back. So servers were added at a few hundred per hour.

Start too fast and go backwards

A loop to break by admitting few servers at a time, or by making the start cheap.

Fleet size divided by restart rate

t=Nrexample: 5000400 per hour=12.5 hevent: 10:07→22:23=12 h 16 mint = \frac{N}{r} \qquad \text{example: } \frac{5000}{400\ \text{per hour}} = 12.5\text{ h} \qquad \text{event: } 10{:}07 \to 22{:}23 = 12\text{ h }16\text{ min}
5,000 and 400 are our example. The report says many thousands of servers and a few hundred per hour.

What was done

  1. 1

    Remove the new capacity

    Already under way as a precaution. Once done, the thread count was under the limit again.

  2. 2

    Leave the limit alone

    The team did not want to raise the operating system limit without further testing.

  3. 3

    Speed up starting

    A configuration was prepared so that a starting server reads from the authoritative store instead of its neighbours.

  4. 4

    Restart in groups

    First traffic at 10:07 AM, then a few hundred servers an hour, watching the error rate.

Spread

Who else went down, and how

One stream service, many users of it

Kinesis Data Streams affects EventBridge through events, CloudWatch through metrics and logs, and Cognito through full buffers. EventBridge affects ECS and EKS workflows. CloudWatch affects Lambda through memory and Auto Scaling through missing metrics. Cognito affects the sign-in of the dashboard tool.
Arrows point from the failing service to the one that felt it.
ServiceWhy it needed KinesisWhat happened
CognitoBest-effort stream of API access patterns, buffered locallyA latent bug made web servers block on full buffers. Sign-in and temporary credentials failed
CloudWatchProcesses metrics and logsMost metrics not processed, alarms in INSUFFICIENT_DATA, gaps remain
Auto ScalingReactive policies read CloudWatchDelayed until 5:47 PM
LambdaMust publish metrics when invokedBuffered metrics used up host memory, errors from 6:15 to 10:36 AM
EventBridgeDelivers eventsAPI errors, delays, a backlog to work off
ECS and EKSWorkflows driven by EventBridgeSlow provisioning and scaling of clusters
Status updatesThe posting tool needs CognitoThe public dashboard could not be updated with it

Three patterns hide in that table. Best effort must really be optional: a buffer for statistics must drop when full, never block a login. Buffers have a size: Lambda's copies of metrics ate the memory that functions needed. Talking to customers must not need the thing that is down: the backup tool worked, but it was manual and less familiar, so posts were delayed.

What a full buffer should do

Waiting is the one thing missing here. Waiting turns an optional dependency into a required one.

Change

What AWS said it would do

WhenChangeWhat it removes
Very short termLarger servers, so fewer of themFewer neighbours means fewer threads each
Very short termFine-grained alarms on thread useThe blind spot
After testingHigher thread limits in the operating systemLittle headroom
In additionFront-end cache moved to a dedicated fleetSlow cold start
In additionLarge AWS users such as CloudWatch on a separate, partitioned fleetOne fleet for everyone
Medium termCells for the front end, as in the back endUnknown limits that grow with the fleet
CognitoWeb servers survive Kinesis errors without exhausting buffersBlocking on an optional stream
CloudWatchThree hours of metrics kept in a local storeTotal dependence for recent metrics
SupportRegular training on the backup posting toolDelay in status posts
From the report. It gives no later confirmation for each item, and neither do we.

The repaired shape

Clients send requests to a thin cell router, which sends each to cell A, cell B or a cell for CloudWatch. Each cell has few front ends, and all read the shard-map from a cache fleet.
Our drawing of the stated plan. A server only knows its own cell, so adding a cell adds no threads anywhere else.

Cells keep the number constant

N=8000,;20 cells⇒400 per cellTserver=500+399=899instead of8499N = 8000,; 20\text{ cells} \Rightarrow 400\text{ per cell} \qquad T_{\text{server}} = 500 + 399 = 899 \quad\text{instead of}\quad 8499
Same invented numbers as before. Doubling the service to 40 cells leaves 899 unchanged.

Lessons

Six lessons for your design

LessonDo thisRead more
Know limits that grow with the fleetList per-server cost as a function of N and alarm at half the limitThroughput
Avoid everyone talking to everyoneGossip to a few, use a shared cache, or split into cellsFailure detection
Watching must not need the watchedKeep recent metrics locally, with a second path for alarmsMonitoring basics
Add capacity like codeSmall steps, wait longer than the learning delay, then compareOperability
Optional means droppableBounded buffers, timeouts, breakersCircuit breaker
Limit who shares a fateCells, separate fleets for big users, more than one Region for critical pathsHigh availability

Prefer

  • Cells with a tested maximum size
  • Independent paths for metrics and status
  • Gradual changes with automatic rollback
  • Breakers and bulkheads between services

Avoid

  • A full mesh in a growing fleet
  • Monitoring that needs the monitored service
  • Big-bang capacity changes
  • Tight coupling for optional data

Summary

The whole topic in one minute.

A capacity addition raised the number of threads on every front-end server above an operating system limit. Shard-maps could not be built, so requests could not be routed. Diagnosis was slowed by many different errors, and the repair was a careful restart of many thousands of servers at a few hundred per hour. Kinesis was normal again at 10:23 PM, about 17 hours after the first alarms.

Services that used Kinesis for support work failed too: Cognito blocked on full buffers, CloudWatch lost metrics, Lambda hosts ran short of memory, and even the tool for posting status updates needed Cognito. The fixes: fewer and larger servers, alarms on thread use, a separate cache fleet, and cells so that no server has to know the whole fleet.

  • The trigger was a small capacity addition; the cause was a thread per neighbour and a fixed limit.
  • All servers crossed the limit, so the whole fleet failed together.
  • The wrong candidate, memory, nearly cost a second restart.
  • Restart speed was limited by cold starts: about 12 hours at a few hundred servers an hour.
  • Optional uses of Kinesis stopped sign-in, metrics and even status posts.
  • Cells keep every server inside a tested size.

Sources