Core Concepts

Resilience Patterns

Limit how long a dependency can hold work, how often we retry it, and how much of the service it can affect.

Free~20 min

One slow dependency can tie up capacity that healthy dependencies share. A deadline limits how long the caller waits. Bounded retries and separate capacity help the service keep useful work moving while a dependency is slow.

Give each cell a deadline

In Prompt Playground, each model's reply appears in a separate cell. A shared adapter calls the model APIs and uses one slot per active call. If model A occupies every slot, even a healthy model B can miss its deadline. The timings below are illustrative.

A deadline says when we must stop waiting for an outcome. An attempt timeout limits one call inside that deadline. If a cell has 800 ms to show its first usable output or report a startup failure, that budget includes dispatch, waiting for a connection, any retry delay, and reporting the result. A started token stream needs separate limits for inactivity and total duration.

Suppose dispatch takes 80 ms. The adapter reserves 50 ms to publish the cell's startup status and caps each attempt at 250 ms. The first attempt ends at 330 ms. That leaves at most 420 ms for further waiting and another call before the reserved reporting time. If the deadline expires while work is still running, stop waiting and pass cancellation to the work we control. The remote provider may still finish. Keep a local work slot occupied until the local work actually stops. AWS Builders' Library on timeouts · gRPC cancellation

Choose timeouts using observed healthy latency and the product's deadline. Include connection setup in the measurement. A timeout that cuts off ordinary calls leads to avoidable retries. Clamp each attempt to the time remaining so its timeout fits inside the operation deadline.

Retry within the remaining budget

Suppose the first attempt ends in a temporary rejection that the provider contract says happened before execution. Retrying after a short pause can work. A validation error needs new input. A timeout after dispatch leaves the outcome uncertain, so another call needs an operation-specific rule.

Backoff delays the next attempt. In a capped exponential policy, the range of possible delays starts at a chosen value, doubles for later retries, and stops growing at a maximum. Jitter adds randomness. For example, with full jitter we choose a delay between zero and the current cap. A fleet that gets the same error at once then distributes its retries over time. AWS Builders' Library on backoff and jitter

In the 800 ms example, suppose the first backoff range is 0 to 100 ms and the adapter picks 90 ms. It can start attempt two at 420 ms. That attempt can use up to 250 ms and finish by 670 ms. The two-attempt cap includes the initial call, so the adapter stops after attempt two even if a little time remains. If the first response at 330 ms had returned HTTP Retry-After: 1, the earliest follow-up would be at 1,330 ms. The adapter reports a startup failure for this cell. HTTP Retry-After

The adapter owns retries to the provider. Check the settings in any client library it calls. If the caller, queue consumer, and provider client each make three total attempts, a single logical operation can generate up to 27 provider attempts when each layer repeats the work below it. Re-delivery of a work item can still happen. Make the operation recognize that work as the same cell.

A per-cell limit controls one cell's contribution. Many cells can still retry during the same incident. A shared retry budget can give retries a limited number of tokens per model. An additional attempt spends one token, and a bounded refill limits the retry rate. When tokens run out, the adapter returns the current failure or lets the cell expire rather than adding more calls. Cap the first attempts through admission and capacity controls as well. Google SRE on retries and cascading failures

Open the circuit for repeated failures

A circuit breaker uses recent failures to decide when to stop sending calls for a while. A retry decides whether to repeat one operation. A breaker decides whether the adapter should send an attempt at all, including a new operation's first call.

StateWhat the adapter allowsWhat changes the state
ClosedSends normal calls and measures qualifying failures.Opens when the configured threshold is exceeded.
OpenFails this model's attempts quickly.Allows a limited trial after a cooldown.
Half-openAllows a small number of trial calls. Remaining attempts fail quickly.Closes when trials show recovery. Reopens when a trial fails.

For example, count provider attempts over 60 seconds and open above a 50 percent failure rate once there are at least ten samples. Decide which failures indicate a dependency problem. A pattern of connection timeouts can qualify. An invalid prompt from one user is a different error. A 429 can reflect a specific quota or caller, so match the breaker key and counting rules to what actually failed. These thresholds are policy choices. A shared breaker needs coordinated half-open admission if we want just one probe across the fleet. Otherwise every adapter may send a trial at once. Azure Architecture Center circuit breaker pattern

The Playground walkthrough scopes its breaker to each provider and model. When A's gate is open, the orchestrator can mark its cells provider_unavailable and deliver B's results. When two models share the same provider-level quota, add protection at that shared boundary. Continue to track final cell outcomes alongside breaker state. A closed state says calls are allowed, and a successful trial provides only a small sample of capacity.

Reserve slots for healthy work

A breaker needs time and evidence to open. While it gathers that evidence, slow calls can hold all six slots in a shared pool. A bulkhead separates capacity so one kind of work cannot occupy all of it. Give A four slots and B two in this example. If A fills its four, B can still use its two, provided the rest of its path has capacity. A request for A can wait briefly in a bounded queue if its deadline allows, or finish with a busy status. Azure Architecture Center bulkhead pattern

Reuse the caps on every retry, and check the breaker before sending the next attempt. An operation sleeping between attempts need not hold an idle connection slot once the previous local attempt has ended. Keep waiting work bounded separately. If every model uses the same underlying connection pool, database, or provider quota, it can still hit that common limit. Measure queue wait, saturation, and final failures by model as well as for the shared adapter. Fixed reservations can leave slots idle when the other pool is busy. Choose the isolation boundary and sizes based on the delays we need to contain.

Recover one intended operation

The developer can retry Run because a response went missing even though the playground already created the sweep. Give each intentional Run a durable identity and derive each cell's identity from the user, the run, and the chosen model and parameters. Reuse that identity when the same Run is replayed. When the saved result already exists, return it. If the current attempt is known to be active, reconnect to its progress. The Playground uses a cell identity to coordinate dispatch and protect stored results. Idempotency · AWS Builders' Library on idempotent APIs

Now suppose a worker sent A's request and crashed before saving the provider's response. A local result constraint can prevent two result rows. It cannot tell us whether A ran the model or incurred a charge. A new local worker may still repeat the external effect. If the provider documents a compatible idempotency key or a result lookup, use it within its scope and retention window. If repeated provider work is unacceptable and the outcome is unknown, surface that uncertainty and reconcile before dispatching again. A stream that has already delivered output needs its own resume or failure rule as well.

For the Playground, preserve completed cells and explain which cells failed or are unavailable. Returning a different model silently changes what the developer is comparing. Keep the state visible when following a partial-result policy.

See also

Used in

  • Prompt Playground - its provider adapter owns retries and scopes circuit state to a provider and model. Healthy cells can return results while an affected model is unavailable.
  • Coding Interview Platform - it separates jobs and runner pools by language so a burst of Java runs cannot consume the Python pool.

Done reading? Mark it so it sticks in your dashboard.

Discussion