Zeeshan Adil
Book a call
← All concepts

CONCEPT

What is a metastable failure?

A metastable failure is a state where a system stays broken after the trigger that caused it is gone, because a feedback loop inside the system keeps the overload alive. Removing the original cause does not help. The system only recovers when load is cut or the loop is broken.

By Zeeshan Adil··Distributed Systems

Chart of PostgreSQL during a simulated cache expiry: after the entry expires at 10 seconds the database is sent close to 20,000 queries a second, far above the safe 500 a second, and finishes none of them in time for the rest of the 60-second run.

Why it happens

The term comes from Bronson et al. Their point is that an outage is usually explained by its trigger: a spike, a deploy, a cache expiry. A metastable failure is different, because the trigger ends and the outage does not. The system has two stable states, a healthy one and a bad one, and a push moved it from one to the other. A feedback loop then holds it in the bad state.

The loop is often work that is wasted. Work is done, thrown away, and the next request has to do it again, so load grows instead of shrinking.

How to recognize it

  • The incident started with a small, short trigger that is long over.
  • The system is busy but useful output is near zero (high CPU, low goodput).
  • Retries and timeouts make it worse, not better.
  • It only happens above a certain load. Below it, the same trigger is harmless.

What fixes it (and what does not)

Waiting does not fix it, and a bigger machine may only move the threshold. What works is breaking the loop:

  • Shed load early, so what is accepted can finish.
  • Cap retries and refresh work with a budget, so recovery work cannot swamp the system.
  • Serve an older answer instead of recomputing, so demand on the slow part drops.
  • Share one in-flight computation per key instead of starting many.

The cheapest defense is to design so the loop cannot start, because once it is running the only recovery is to cut load by hand.

Measured

In my cache stampede challenge (a simulation, not a real database), one popular post is read 20,000 times a second by 20 API processes, and an 8-core PostgreSQL can safely run 500 of these queries a second. When the cached entry expires, the 500 connections fill, each 12 ms query slows to about 750 ms, and the 500 ms read deadline cancels every query before it finishes. Nothing refills the cache, so every request misses again.

The expiry lasted a moment. The outage did not end: from 10 to 60 seconds, 0.0% of reads were served and no query finished in time. The loop was the deadline. With a 1,000 ms deadline the same run recovered in about 2 seconds, and at 5,000 reads a second a 500 ms deadline recovered too. At 10,000 reads a second it never did.

RUN IT YOURSELF

Challenge · Distributed Systems ChallengesA popular post takes down the database

GO DEEPER

Circuit Breakers in Production: Timeouts, Retry Storms, and Failure RecoveryHow circuit breakers limit calls to a failing API, how half-open probes work, and how timeouts and retries can prevent a retry storm.
What is a cache stampede?What is request coalescing?What is stale-while-revalidate?

SOURCES

Get the next deep dive by email

New deep dives on how production systems really behave, from Kubernetes networking to PostgreSQL internals. About one email a month.

You will get one email to confirm. Unsubscribe from any email with one click. Your address is used for this newsletter and nothing else.

Written by Zeeshan Adil

I run systems like this for a living. If your team is fighting the same problem, or wants this as a talk, write to me.