Skip to content
Search lessons, topics, tests…
Esc

    ↑ ↓ moveEnter openEsc close
    Cheat sheets: all cheat sheets

    Designing Retry Budgets and Backpressure for Resilient HTTP APIs

    Separate retry limits, retry budgets and end-to-end deadlines.

    How to keep retries from turning a slow dependency into an outage: per-request limits, a shared retry budget, deadlines, and the backpressure that tells callers to slow down.

    At a glance

    • A retry is extra load sent exactly when a dependency may be struggling: with two retries each, 20,000 requests a second can become 60,000 attempts.
    • A per-request retry limit bounds one caller; a retry budget bounds the retries of all callers together, for example to 10% of the original attempts.
    • Every attempt's timeout comes out of one end-to-end deadline; a fresh full timeout per retry overruns the caller's latency target.
    • Retry only failures likely to be transient, with exponential backoff and jitter, and only when repeating the request is safe.
    • Backpressure is the receiver saying "slow down": bounded queues, concurrency and rate limits, and fast, cheap rejections that clients respect.
    • A circuit breaker fails fast while a dependency looks unhealthy; it is not a capacity limit.

    Which control bounds what

    ControlBoundsDoes not solve
    Attempt timeoutHow long one attempt may waitThe total time across retries, or work still running downstream
    End-to-end deadlineTotal time across queueing, attempts and processingFleet-wide load
    Per-request retry limitAttempts made for one logical requestMany callers retrying together
    Retry budgetRetries across all callers in a time windowToo much original traffic
    Circuit breakerCalls sent while a dependency looks unhealthyOverload of a slow but healthy dependency; all breakers probing at once
    Concurrency limitOperations in flight at the same timeThe request rate
    Rate limitRequests admitted per unit of timeConcurrency growing as latency rises
    Bounded queueWork waiting to be admittedSustained overload: it only adds latency
    • At a fixed arrival rate, slower operations hold more resources at once: that is why a rate limit alone is not enough.
    • A connection that fails after the request was sent leaves the outcome unknown: the server may have committed. Retry a non-idempotent call only with a replay-safe contract such as a stored idempotency key: Idempotency Keys for Reliable HTTP APIs.

    A retry budget, worked

    The opening case: 1,000 eligible original attempts in a window earn retries worth 10% of them; 90 retries were already sent when 50 more eligible failures arrive.

    C#Runs
    using System.Globalization;
    CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
    
    // The opening case: 1,000 eligible originals earn retries worth 10% of them.
    var budget = new RetryBudget(retriesPer100Originals: 10);
    for (int i = 0; i < 1_000; i++) budget.OnOriginalAttempt();
    int first = Retry(budget, failures: 90);
    int second = Retry(budget, failures: 50);
    Console.WriteLine($"first 90 failures: {first} retried; next 50: {second} retried, {50 - second} failed fast");
    
    // The denominator matters: 10% of all attempts allows retries = 0.1 / 0.9 of the originals.
    Console.WriteLine($"10% of originals: {1_000 * 10 / 100} retries; 10% of all attempts: {Math.Floor(1_000 * 0.1 / 0.9)} retries");
    
    // Amplification without a budget: every request allowed two retries, all of them failing.
    Console.WriteLine($"20,000 requests a second with 2 retries each: up to {20_000 * 3:N0} attempts a second");
    
    static int Retry(RetryBudget budget, int failures)
    {
        int retried = 0;
        for (int i = 0; i < failures; i++) if (budget.TryRetry()) retried++;
        return retried;
    }
    
    sealed class RetryBudget(int retriesPer100Originals)
    {
        private int _credit;                                   // in hundredths of a retry
        public void OnOriginalAttempt() => _credit += retriesPer100Originals;
        public bool TryRetry()
        {
            if (_credit < 100) return false;
            _credit -= 100;
            return true;
        }
    }
    Output
    first 90 failures: 90 retried; next 50: 10 retried, 40 failed fast
    10% of originals: 100 retries; 10% of all attempts: 111 retries
    20,000 requests a second with 2 retries each: up to 60,000 attempts a second
    • Only 10 of the 50 fit. Even then, a retry also needs enough deadline left and a request that is safe to repeat.
    • Say which denominator you mean: 10% of originals and 10% of all attempts are different budgets.
    • A real budget also ages out old credit, caps bursts, and is kept per dependency and per priority, so one failure cannot starve unrelated traffic.

    Scope of the budget

    • A fixed number of retries per process grows with the number of instances; a share of each process's own traffic does not.
    • A central budget is exact but adds a dependency and latency; local token buckets that earn credit from eligible original attempts (never from retries) are the usual compromise.
    • Keep critical and best-effort traffic in separate budgets.

    Backpressure on the receiving side

    • Put it at the constrained resource: an adaptive concurrency limit that admits less as latency or queueing grows.
    • Keep queues small and bounded; once full, rejecting fast is safer than waiting without limit.
    • Make overload answers cheap, and add Retry-After only when the server can estimate a delay.
    • In ASP.NET Core, the rate limiting middleware offers concurrency, fixed window, sliding window and token bucket limiters, with an optional queue. It rejects with 503 by default; set RejectionStatusCode to 429 when the caller is being limited.
    • On the client, AddStandardResilienceHandler() adds a concurrency limiter, a total request timeout, retries (by default up to 3, exponential with jitter), a circuit breaker and a per-attempt timeout (10 seconds by default) to an HttpClient. It retries every HTTP method by default and has no shared retry budget: configure method safety and a budget yourself.

    How a slowdown cascades

    1. A database failover raises processing time from 40 ms to 1.5 seconds.
    2. With queueing, attempts pass the callers' 2-second timeout, and each caller retries twice at once.
    3. The original work often still runs, so the dependency now does duplicate work while callers hold more sockets and memory.
    4. Health checks time out, instances are removed, and capacity falls further.
    5. Circuit breakers open everywhere at once and, thirty seconds later, all probe at once: another spike.

    The safer design: one deadline passed down the call chain, one short jittered retry for eligible failures, spent from a 10% budget, an adaptive concurrency limit with a small queue that rejects fast, degraded answers (such as slightly stale data) where the product allows, and sparse randomized probes.

    What to watch

    • Logical requests and physical attempts, separately: the attempts-to-originals ratio, budget use and exhaustion, retry outcomes.
    • Deadline left at each hop, timeouts by phase, breaker state and probe results.
    • Admitted and rejected requests, concurrency, queue depth and age, connection-pool saturation.
    • A rising retry ratio with a falling success rate is a warning that retries may be adding harmful load: check before calling it the cause. Keep raw URLs, customer IDs and idempotency keys out of metric labels.

    Common mistakes

    • Retrying every error, including authentication failures, validation errors and durable "not found" answers.
    • Retrying at several layers (SDK, service, proxy, gateway): the attempts multiply and no layer sees the total.
    • Fixed delays or identical breaker reset intervals: callers retry and recover in lockstep.
    • Treating a circuit breaker as a rate limit: a closed breaker still lets a slow dependency drown.
    • An unbounded queue: overload turns into memory growth and work that is stale before it starts.
    • Retrying after the caller has gone or the deadline has passed.

    In an interview

    Why can a two-retry limit per request still take a system down? Each logical request can become three attempts, and every caller does it at the same moment. Only a shared budget bounds the total.

    What is a retry budget? A cap on retries across all callers over a window, usually a share of the original attempts, such as 10%. When it is spent, callers fail fast or degrade instead of adding load.

    When is it safe to retry a request whose outcome is unknown? When the failure is likely transient, enough of the end-to-end deadline is left, and repeating the effect is safe: an idempotent method, or a stored idempotency key for a POST.

    Why use a concurrency limit if you already have a rate limit? At the same arrival rate, slower requests occupy more resources at once. A rate limit counts arrivals; a concurrency limit protects what is in flight.

    What is backpressure? The receiver signalling that it is at capacity, through bounded queues, limits and fast rejections, so upstream callers slow down instead of piling on.

    How do you bring traffic back after an incident? Ramp up gradually, keep backpressure on, drop work that has expired, and use sparse randomized probes while watching latency and saturation.

    Check yourself

    A window has 1,000 eligible original attempts and a retry budget of 10% of originals. 90 retries have been sent and 50 more requests fail. How many of them can be retried?

    A 50
    B 10
    C 0
    D 100
    Show answer

    Correct answer: B

    The budget allows 100 retries; 90 are spent, so 10 remain, and the other 40 must fail fast or degrade.

    Option A: Retrying all 50 would exceed the budget.

    Option C: Some budget is still left.

    Option D: 100 is the whole budget, most of which is already spent.

    Why is a circuit breaker not enough to protect a slow dependency?

    A It retries every failed call automatically
    B It opens on failures, so a slow but successful dependency can stay overloaded while it is closed
    C It always waits exactly one second between calls
    D It only works with POST requests
    Show answer

    Correct answer: B

    A breaker reacts to failures; it does not limit how much work is in flight, which is what a concurrency limit does.

    Option A: A breaker blocks calls while open; it does not retry them.

    Option C: Its delays are configurable and are not a limit on load.

    Option D: A breaker is independent of the HTTP method.

    What does the ASP.NET Core rate limiting middleware answer by default when it rejects a request?

    A 429 Too Many Requests
    B 503 Service Unavailable
    C 400 Bad Request
    D 408 Request Timeout
    Show answer

    Correct answer: B

    RejectionStatusCode defaults to 503; set it to 429 when you want to tell the caller it is being rate limited.

    Option A: 429 is a common choice, but it has to be configured.

    Option C: A rejected request is not malformed.

    Option D: 408 means the client was too slow to send its request.

    Sources

    TechInterviewNotes Editorial Team · Updated 28 Nov 2026 ·