StoicBuilder

HandbookXIII the AqueductTimeouts and back-pressure

XIIIthe Aqueduct, Scale it

Timeouts and back-pressure

1 min readUpdated 28 November

In plain words

Timeouts cap how long you wait for another service, and back-pressure means refusing or slowing new work when you're already full, so one slow part can't drag the whole system down with it.

Where you see it

Harbor's tax provider starts answering in 30 seconds instead of 200 ms. Checkout calls it with no timeout, so requests pile up, the servers run out of connections, and the dashboard and sign-in fail too, though neither uses tax at all.

services/billing/tax.tsserver
const res = await fetch(TAX_URL, { method: "POST", body: JSON.stringify(order), signal: AbortSignal.timeout(2000), // give up after 2 seconds}); if ((await exportQueue.count()) > 50_000) // full: say so instead of queueing forever return Response.json({ error: "busy" }, { status: 503, headers: { "Retry-After": "30" } });
A deadline on every outside call, and a clear 503 with Retry-After when the queue is already too long.

What goes wrong

  1. Relying on the default timeout

    Many HTTP clients and database drivers wait minutes by default, and some wait forever. Set an explicit timeout on every outbound call, shorter than the request that's waiting on it.

  2. Retries that multiply the load

    When a service slows down, three layers each retrying three times turn one request into 27. Retry at one layer only, with exponential backoff, jitter and a cap, and stop when a circuit breaker opens.

  3. Queues with no limit

    A queue with no maximum hides overload until memory runs out or jobs are hours old. Set a limit, and reject new work with a clear 503 and Retry-After when you reach it.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Find every outbound call in this service, including HTTP, database, Redis and queues, and give each an explicit timeout shorter than its caller's. Retry only idempotent calls, at most twice with exponential backoff and jitter, put a circuit breaker around the tax provider, and return 503 with Retry-After when our queues pass their limits.

Quick check

Sign in to earn +10 XP for it

Harbor's tax provider slows to 30-second responses, and soon sign-in fails too, though sign-in never calls the tax provider. Why?

Got a prompt that touches timeouts and back-pressure?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.