The AWS Kinesis outage of 2020
medium 26 minOn 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
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
14 November 2013
AWS announces Amazon Kinesis on its news blog.
25 November 2020
The capacity addition to the front-end fleet and the outage described here.
7 December 2021
Another large event in the same Region, with a different cause, again slows monitoring and the status page. See that page.
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.
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.
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
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
What happened
The timeline
25 November 2020, PST
| Time | Event |
|---|---|
| 2:44 AM | Capacity begins to be added to the front-end fleet |
| 3:47 AM | The addition is finished. Existing servers need up to an hour to learn of new ones |
| 5:15 AM | First alarms: errors on putting and getting records. CloudWatch and EventBridge also affected |
| 6:15 AM | Lambda error rates rise: memory contention from buffered metrics |
| 7:01 AM | Cognito error rates rise significantly, after extra capacity had first helped |
| 7:51 AM | A couple of candidate causes remain. Each would need a full restart of the fleet |
| 9:39 AM | Root cause confirmed: the thread limit, not memory pressure |
| 10:07 AM | The first group of restarted servers takes traffic |
| 10:15 AM | Cognito starts deploying a change that depends less on Kinesis |
| 10:36 AM | Lambda hosts are relieved and its error rates recover |
| 12:00 noon | From here on, the Kinesis error rate drops steadily |
| 2:18 PM | Cognito is normal |
| 4:15 PM | Most ECS and EKS issues are resolved |
| 5:47 PM | CloudWatch shows early signs of recovery |
| 10:23 PM | Kinesis is fully normal |
| 10:31 PM | CloudWatch metrics and alarms fully recovered; backfill continues |
How long it lasted
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 servers, one server needs a number of threads that grows in step with , and the fleet as a whole grows with squared.
Threads per server, and in the whole fleet
An example with invented numbers
| Servers N | Threads per server | Limit 10,000 | Fleet total |
|---|---|---|---|
| 2,000 | 500 + 2,000 - 1 = 2,499 | 25% used | about 5 million |
| 4,000 | 4,499 | 45% used | about 18 million |
| 8,000 | 8,499 | 85% used | about 68 million |
| 9,501 | 10,000 | exactly full | about 95 million |
| 9,502 | 10,001 | over, on every server | about 95 million |
From an addition to no routing
Diagnosis
Why finding it took over four hours
- 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
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
A convincing wrong candidate
The leading idea was memory pressure. It looked promising and was not the cause.
- 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
Fleet size divided by restart rate
What was done
- 1
Remove the new capacity
Already under way as a precaution. Once done, the thread count was under the limit again.
- 2
Leave the limit alone
The team did not want to raise the operating system limit without further testing.
- 3
Speed up starting
A configuration was prepared so that a starting server reads from the authoritative store instead of its neighbours.
- 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
| Service | Why it needed Kinesis | What happened |
|---|---|---|
| Cognito | Best-effort stream of API access patterns, buffered locally | A latent bug made web servers block on full buffers. Sign-in and temporary credentials failed |
| CloudWatch | Processes metrics and logs | Most metrics not processed, alarms in INSUFFICIENT_DATA, gaps remain |
| Auto Scaling | Reactive policies read CloudWatch | Delayed until 5:47 PM |
| Lambda | Must publish metrics when invoked | Buffered metrics used up host memory, errors from 6:15 to 10:36 AM |
| EventBridge | Delivers events | API errors, delays, a backlog to work off |
| ECS and EKS | Workflows driven by EventBridge | Slow provisioning and scaling of clusters |
| Status updates | The posting tool needs Cognito | The 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
Change
What AWS said it would do
| When | Change | What it removes |
|---|---|---|
| Very short term | Larger servers, so fewer of them | Fewer neighbours means fewer threads each |
| Very short term | Fine-grained alarms on thread use | The blind spot |
| After testing | Higher thread limits in the operating system | Little headroom |
| In addition | Front-end cache moved to a dedicated fleet | Slow cold start |
| In addition | Large AWS users such as CloudWatch on a separate, partitioned fleet | One fleet for everyone |
| Medium term | Cells for the front end, as in the back end | Unknown limits that grow with the fleet |
| Cognito | Web servers survive Kinesis errors without exhausting buffers | Blocking on an optional stream |
| CloudWatch | Three hours of metrics kept in a local store | Total dependence for recent metrics |
| Support | Regular training on the backup posting tool | Delay in status posts |
The repaired shape
Cells keep the number constant
Lessons
Six lessons for your design
| Lesson | Do this | Read more |
|---|---|---|
| Know limits that grow with the fleet | List per-server cost as a function of N and alarm at half the limit | Throughput |
| Avoid everyone talking to everyone | Gossip to a few, use a shared cache, or split into cells | Failure detection |
| Watching must not need the watched | Keep recent metrics locally, with a second path for alarms | Monitoring basics |
| Add capacity like code | Small steps, wait longer than the learning delay, then compare | Operability |
| Optional means droppable | Bounded buffers, timeouts, breakers | Circuit breaker |
| Limit who shares a fate | Cells, separate fleets for big users, more than one Region for critical paths | High 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.