Kayavak

Kayavak / Work backwards

Work backwards

One click, 64 calls to a database that was down

A single user request reached a failed database 64 times, though no layer retried more than three times.

The result

In Volume 3's resilience lab, one user request passed through a gateway, an orders service and a loyalty service to a database that was down. Each layer made one attempt plus three retries. The database received 64 calls. Retrying at only the layer next to the database gave 4 (the lab).

Every layer was "only" retrying three times.

Work back from it

First question: how many attempts does the loyalty service make for each call it receives?

Four: one try and three retries. That's the only layer that talks to the database directly.

Step 1: and how many calls does the loyalty service receive for one user request?

The orders service also tries four times for each call it gets, so the loyalty service receives 4 calls, and makes 4 attempts for each of them: 16 calls to the database.

Step 2: now add the gateway.

The gateway sends 4 calls to the orders service. 4 × 4 × 4 = 64. Retries multiply across layers; they don't add.

calls=∏layers(1+ri)=43=64
Step 3: why is this worse than wasted work?

When the database starts to recover it's met by up to 64 times the normal load from every user who tried meanwhile, which can keep it down: a retry storm (retry amplification).

The root cause

Independent retry policies at each layer multiply. No layer was wrong on its own; the system was.

What follows from it

Recall

Three layers each make 1 attempt and 3 retries. How many calls reach the bottom?

64 (4 × 4 × 4).

Name two ways to stop retries multiplying.

Retry at one layer only; propagate deadlines; use a retry budget.