📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

During a database slowdown, traffic to your inventory service jumps to eight times normal while user traffic is flat, and a small incident becomes a 45-minute outage across five services. You suspect a retry storm. How do you prove it, stop it, and fix it with retry budgets so it can't happen again?

A retry storm across a five-service call chain: proving retry amplification with distributed traces and metrics, stopping it during the incident, and preventing it with single-layer retries, retry budgets, Retry-After, circuit breakers and jitter.

Senior RealWorldScenario Advanced application-insights distributed-systems incident-response resilience retry-budget retry-storm

🎯 Key points

  • Signature: downstream request rate rises while user traffic stays flat; dependency calls per operation rise
  • Amplification: each retrying layer makes 1 attempt + r retries, so n layers give (1 + r)^n calls; four layers with r = 3 is 4 × 4 × 4 × 4 = 256
  • Prove it with traces: count spans per operation_Id and the retry share from Polly telemetry
  • Stop it: cut retries through configuration, open breakers, shed load at the bottom, and let the dependency recover
  • Retry in one layer only; layers above fail fast
  • Retry budget: retries capped at about 10% of calls (token bucket); gRPC RetryThrottlingPolicy does this built in
  • Honour Retry-After, use jitter, and never retry an overloaded signal immediately
  • Prevent with a budget table per call chain, retry-share alerts and chaos tests

⏱ 30-second answer

The signature of a retry storm is downstream traffic rising while user traffic is flat. Each layer retries its own failures, so load multiplies. A layer with three retries makes up to 4 attempts per call it receives. Stack four such layers and the bottom sees 4 × 4 × 4 × 4 = 256 calls for one user request, aimed at the service that is already struggling. In general that is (1 + r)^n.

I prove it with distributed traces (dependency spans per operation_Id in Application Insights) and Polly retry telemetry. To stop it, I cut retries through configuration, let circuit breakers open and shed load at the bottom so the dependency can recover. The lasting fix: retry in one layer only, enforce a retry budget (retries at most ~10% of calls), honour Retry-After, and use jitter. The trade-off: fewer retries means a few more user-visible errors in small blips, in exchange for never amplifying a big one.

🗣 Full answer (senior)

How I would answer this in an interview

"The clue in that symptom is the ratio. If inventory gets eight times normal traffic while users send the same amount, the extra traffic is being created inside our own system, and retries are the usual cause. A retry storm happens when every layer in a call chain has its own retry policy. A gateway, a BFF, orders, pricing and inventory each retrying three times means a failure at the bottom is multiplied at every level. Four retrying layers is 4 to the power of 4, which is 256 attempts for one click, all arriving at the service that's already slowest.

For example, at [company] we [had exactly this: a SQL slowdown under inventory became a 45-minute outage]. I proved it in Application Insights by counting dependency calls per operation ID. Normal requests had about 4 spans. During the incident some had over 100, with the same call repeated at different levels. Polly's retry metrics showed retries were [more than 70%] of inventory's traffic. To stop it, we cut retries to zero above orders through App Configuration, which took effect in about 30 seconds without a deploy. Inventory's circuit breaker could then open and the database recovered within [3 minutes]. The lasting fix was a rule: one retrying layer per call chain, a retry budget so retries can never exceed about 10% of calls, Retry-After honoured everywhere, and an alert on retry share.

The mistake I see is thinking each team's retry policy is reasonable on its own, so the system must be fine. Each policy is reasonable. Stacked together, they amplify. Retries are a shared resource, and you have to budget them."


The chain and the multiplication

User ──► Gateway ──► BFF ──► Orders ──► Pricing ──► Inventory ──► SQL (slow)
          r=3        r=3     r=3        r=3          (fails)

attempts reaching inventory per user request:
  Pricing:  1 + 3            =   4
  Orders:   4 × 4            =  16
  BFF:      16 × 4           =  64
  Gateway:  64 × 4           = 256

Proving it

Evidence Tool What it shows
Inventory rps vs gateway rps Azure Monitor / App Insights metrics Internal amplification (8× while users flat)
Dependency spans per operation App Insights KQL on dependencies grouped by operation_Id Repeated calls in one trace
Retry share Polly v8 metrics (resilience.polly.strategy.events, retry events) Retries as % of calls
SQL waits and DTU Query Store, Azure SQL metrics The original slowdown and its recovery

Fix: retries as a shared resource

Rule Mechanism
One retrying layer per chain Remove retries above the layer nearest the dependency; others fail fast
Retry budget Token bucket: each success adds 0.1 token, each retry costs 1, so retries stay at or below ~10%
Respect overload signals Honour Retry-After; do not retry 503 from load shedding immediately
Breaker below the retry Open circuits fail retries instantly
Jitter Spread retries so they don't arrive in synchronised waves

Production example

In the incident above, gateway traffic held steady at about 1,200 rps while inventory went from 900 to 7,400 rps. After moving to a single retrying layer and a 10% budget, a similar SQL slowdown three months later peaked at 1,050 rps to inventory, the breaker opened for 20 s, and user-visible errors lasted 90 seconds instead of 45 minutes.

🔍 What the interviewer is checking

Checks whether the candidate can recognise internal load amplification, prove it with telemetry, act calmly during the incident, and fix the system rather than one service.

Green flags

  • Spots the flat-user-traffic versus rising-internal-traffic signature
  • Does the (1 + r)^n arithmetic
  • Uses traces per operation and retry metrics as evidence
  • Proposes a single retry layer, retry budgets, Retry-After and jitter, plus governance

Red flags

  • "Scale up the inventory service" as the main fix
  • Adds more retries or longer timeouts
  • Blames only the database and stops there

📚 Learn in depth

1. Why retries amplify

A retry is only useful if the failure is transient and the dependency has spare capacity for the extra attempt. In a storm, neither is true: the failure is overload, and retries add more load. Retrying makes recovery impossible while the extra load lasts, which turns a brief slowdown into a stable outage. This feedback loop is sometimes called a metastable failure: the system stays broken after the original trigger has gone.

SQL slows ──► inventory times out ──► callers retry ──► more load on inventory
     ▲                                                         │
     └─────────────── SQL slower still ◄────────────────────────┘

2. Retry budgets

A retry budget caps retries as a share of normal traffic. The common implementation is a token bucket per client process:

  • Each successful (or first-attempt) call deposits a fraction of a token, for example 0.1.
  • Each retry withdraws 1 token.
  • With no tokens left, the call fails without retrying.

In steady state, retries can't exceed about 10% of calls. In a storm the bucket drains in seconds and retries stop by themselves, while one-off blips still get retried.

gRPC has this built in: RetryThrottlingPolicy in the client service config (MaxTokens, TokenRatio) follows the same idea, and the .NET gRPC client supports it. Service meshes (Envoy-based) offer retry budgets as configuration. For HTTP with Polly v8 there is no built-in budget, so you implement it in the retry ShouldHandle predicate, as in the code example.

3. Choosing the retrying layer

Retry closest to the failing dependency, where the error is best understood and the cost of a retry is smallest. Every layer above fails fast and passes the error up, ideally as a 503 with Retry-After. The exception is the very edge (mobile app or SPA), where a user-initiated retry with backoff is fine because it is naturally rate-limited by people.

4. Proving it with KQL

In Application Insights, every dependency call carries the operation_Id of the user request. Counting dependency calls per operation to the same target shows repeated attempts:

dependencies
| where timestamp between (incidentStart .. incidentEnd)
| where target has "inventory"
| summarize calls = count() by operation_Id
| summarize p50 = percentile(calls, 50), p99 = percentile(calls, 99), max = max(calls)

Compare with the same query for a normal hour. A p99 of 1–2 normally and 64+ during the incident is the proof.

5. Stopping it during the incident

  1. Reduce retries through configuration (Azure App Configuration with refresh) above the bottom layer. This is the fastest lever if you built it in.
  2. Shed load at the struggling service (concurrency limiter, 503 with Retry-After) so it serves some requests well.
  3. Let breakers open; don't reset them by hand early.
  4. Only then scale out the bottom tier. Scaling into a storm often just moves the bottleneck to the database.

Try it yourself

  1. Build three minimal APIs in a chain with AddStandardResilienceHandler on each hop. Make the bottom one fail 50% of calls and count calls with a counter middleware.
  2. Remove the retries from the top two hops and count again.
  3. Implement the retry budget below and run a load test where the bottom service fails 100%. Check that retries stop at about 10% of traffic.
  4. Write the KQL above against a test Application Insights resource with injected failures.
  5. Configure a gRPC client with RetryThrottlingPolicy and observe throttled retries in the logs.

💻 Code

A per-client retry budget enforced in Polly v8's ShouldHandle, used by the single retrying layer, and fail-fast clients above it.

// RetryBudget.cs: retries can never exceed ~10% of calls from this process.
namespace Inventory.Resilience;

public sealed class RetryBudget(double tokenRatio = 0.1, double maxTokens = 100)
{
    private readonly Lock _gate = new();
    private double _tokens = maxTokens;

    // Every first attempt earns a fraction of a token.
    public void RecordAttempt()
    {
        lock (_gate) _tokens = Math.Min(maxTokens, _tokens + tokenRatio);
    }

    // A retry spends one token; with none left, we fail instead of amplifying.
    public bool TryWithdraw()
    {
        lock (_gate)
        {
            if (_tokens < 1) return false;
            _tokens -= 1;
            return true;
        }
    }
}
// Program.cs in Pricing (the ONE retrying layer, closest to Inventory)
using Inventory.Resilience;
using Microsoft.Extensions.Http.Resilience;
using Polly;

var builder = WebApplication.CreateBuilder(args);
var budget = new RetryBudget();

builder.Services.AddHttpClient("inventory", c => c.BaseAddress = new Uri("https://inventory.internal"))
    .AddResilienceHandler("inventory", pipeline =>
    {
        pipeline.AddTimeout(TimeSpan.FromSeconds(2));             // total budget for this hop
        pipeline.AddRetry(new HttpRetryStrategyOptions
        {
            MaxRetryAttempts = 2,
            UseJitter = true,                                     // de-synchronise retry waves
            ShouldRetryAfterHeader = true,                        // respect the server's overload signal
            ShouldHandle = args =>
            {
                if (args.AttemptNumber == 0) budget.RecordAttempt();
                var transient = HttpClientResiliencePredicates.IsTransient(args.Outcome);
                // Retry only transient failures AND only while the budget allows it.
                return ValueTask.FromResult(transient && budget.TryWithdraw());
            }
        });
        pipeline.AddCircuitBreaker(new HttpCircuitBreakerStrategyOptions
        {
            FailureRatio = 0.3, MinimumThroughput = 50, BreakDuration = TimeSpan.FromSeconds(20)
        });
        pipeline.AddTimeout(TimeSpan.FromMilliseconds(500));      // per attempt
    });

var app = builder.Build();
app.Run();
// Program.cs in Orders / BFF / Gateway: NO retries, fail fast and pass the 503 up.
builder.Services.AddHttpClient("pricing", c => c.BaseAddress = new Uri("https://pricing.internal"))
    .AddResilienceHandler("pricing-fail-fast", pipeline =>
    {
        pipeline.AddTimeout(TimeSpan.FromSeconds(3));             // > pricing's 2 s, < our caller's
        pipeline.AddCircuitBreaker(new HttpCircuitBreakerStrategyOptions
        {
            FailureRatio = 0.3, MinimumThroughput = 50, BreakDuration = TimeSpan.FromSeconds(20)
        });
    });

⚠ Common mistakes

  • Mistake: Every service adds its own retry policy "to be safe". Why it is wrong: Retries multiply to (1 + r)^n at the bottom of the chain during an outage. Instead: Retry in one layer per chain; others fail fast.
  • Mistake: Scaling out the struggling service first. Why it is wrong: More instances accept more amplified load and pass it on to the database, which is the real bottleneck. Instead: Cut retries and shed load first, then scale if still needed.
  • Mistake: Retrying 503s from load shedding immediately. Why it is wrong: The overload signal is ignored, so shedding becomes a loop. Instead: Honour Retry-After with jitter, and count the retry against a budget.
  • Mistake: Retries with no jitter. Why it is wrong: Clients retry in synchronised waves that hit the dependency together. Instead: UseJitter = true on exponential backoff.
  • Mistake: No visibility of retries. Why it is wrong: The storm looks like real traffic growth, and teams chase the wrong cause. Instead: Track retry share from Polly telemetry and alert when it passes about 10%.
  • Mistake: Hard-coded retry settings. Why it is wrong: During the incident, the only lever is a redeploy, which is slow and risky. Instead: Read retry counts from configuration with live refresh (Azure App Configuration).
  • Mistake: Treating the database slowdown as the whole root cause. Why it is wrong: The trigger was the slowdown, but the 45-minute duration was caused by amplification. Instead: Record both in the post-incident review and fix the amplifier.

🏛 Senior insight: trade-offs

The senior lesson is that a slowdown triggered this incident, but amplification made it last. In the post-incident review I separate the two, because fixing only the database leaves the amplifier waiting for the next trigger. Retries still have a job: for genuinely transient faults (a dropped connection, a single pod restarting, a brief failover) with spare capacity downstream, one retry turns a user-visible error into a slightly slower success. The budget keeps exactly that benefit. In normal operation a 1–2% failure rate is retried in full, and only when failures go past the budget do retries stop.

Retries are a shared resource across teams, so the fix is partly governance: a timeout and retry budget per call chain, owned by the platform or architecture group, checked in code review, and visible on a dashboard of retry share per dependency. In .NET 10 the pieces are standard. Microsoft.Extensions.Http.Resilience pipelines (Polly v8) emit retry and breaker events through System.Diagnostics.Metrics, which OpenTelemetry exports to Azure Monitor. HttpRetryStrategyOptions.ShouldRetryAfterHeader honours server back-off, and Azure App Configuration with refresh gives on-call a live lever for retry counts. I measure success by recovery time after the trigger ends. Without amplification, the system should recover within a minute of the dependency recovering. If it stays broken, something is still feeding the loop.

Option When it fits Cost When not to
Single retrying layer Every synchronous call chain Coordination across teams Never skip it
Retry budget (token bucket) High-traffic clients A little code, or mesh config Very low-traffic clients where the bucket never fills; use a small fixed cap
gRPC RetryThrottlingPolicy gRPC clients Service config only HTTP clients (no equivalent built in)
Mesh retry budgets (Envoy, Istio) Polyglot estates with a mesh Mesh complexity; hidden from code When code also retries
Hedging Tail latency on idempotent reads Extra load by design During overload; budget it or turn it off

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions backoff, jitter or which errors to retry Why: Checks the fundamentals of the retry pattern and its idempotency requirement
    How to answer

    Retry handles transient faults: a network blip, 503, 429 or a timeout that will probably succeed if you try again shortly.

    • What to retry: 5xx, 408, 429 (honour Retry-After), connection errors and timeouts. Never retry 400, 401, 403, 404, 409 or validation failures.
    • How: exponential backoff with jitter, so thousands of clients don't retry in lockstep. Cap the attempts, and keep the whole thing inside a total timeout.
    • Safety: retry only idempotent operations. For POST, use an idempotency key or disable retries for unsafe methods.

    The danger is amplification: retries at the API, service and client layers multiply, which creates a retry storm against a recovering dependency. Retry at one layer and pair it with a circuit breaker.

    In .NET 10 it's Polly v8 (AddRetry) or AddStandardResilienceHandler (3 retries, exponential, jitter, 2 s base). The trade-off is higher success rates against extra load and latency.

  2. When: Candidate mentions timeouts per hop or the order of resilience strategies Why: Checks composing timeout, retry and breaker correctly and budgeting timeouts across a chain
    How to answer

    Resilience strategies are wrappers, so order decides what each one sees. The order I use, outer to inner, is the one in AddStandardResilienceHandler: concurrency limiter → total timeout → retry → circuit breaker → per-attempt timeout. The total timeout caps the whole operation, retry delays included. The retry wraps the breaker, so every attempt counts towards the breaker's failure ratio, and once the breaker opens the retries fail at once instead of hammering. The attempt timeout sits innermost, so a hung call becomes a fast, retryable failure.

    Across services, timeouts form a budget: each hop must give up before its caller does. You also propagate the deadline, so work stops when nobody is waiting for it. The trade-off: every retry layer you add improves the odds for one call but multiplies load on the dependency when it is already struggling.

  3. When: Candidate mentions shedding load or returning 503 with Retry-After at the bottom service Why: Checks load shedding and how clients should react to overload signals
    How to answer

    An overloaded service with unbounded queues collapses: requests wait so long that many time out after the server has done the work, so goodput (successful responses that arrive in time) falls towards zero while CPU stays at 100%. Load shedding means rejecting excess work early and cheaply so the work you accept finishes in time.

    In ASP.NET Core I use the rate limiting middleware (AddRateLimiter / UseRateLimiter) with a concurrency limiter sized by Little's law (concurrency = throughput × latency, measured at the healthy limit) and a small queue. Rejected requests get 503 with Retry-After, or 429 when a single client is over its quota. I shed by priority: checkout before batch exports, health probes never. Clients must honour Retry-After and back off with jitter.

    The trade-off: you deliberately fail some users to keep the system serving most of them.

🛠 Real-world problems: how you handle them

Retry storm turning a SQL slowdown into a 45-minute outage
Situation
An online store with a five-service checkout chain (gateway, BFF, orders, pricing, inventory) on [AKS, Australia East], peaking at [1,200 user rps]. Each service used its own retry policy (three retries) through AddStandardResilienceHandler.
Signals
Inventory rps went from 900 to 7,400 while gateway rps stayed flat. Azure SQL DTU at 100%, inventory p95 above 10 s, 503s and 504s across all five services, and the incident lasting [45 minutes] after the SQL trigger (a [missing index on a new query]) had been mitigated.
Investigation
Application Insights KQL counting dependency calls per operation_Id showed p99 of 120 calls to inventory per user request, against 2 normally. Polly retry metrics showed retries at 75% of inventory traffic. Query Store identified the original slow query.
Resolution
Immediate: set retries to zero in all services above pricing through Azure App Configuration, let inventory's breaker open, and added a concurrency limiter returning 503 with Retry-After on inventory. The database recovered within about 3 minutes. Real fix: a single retrying layer per chain, a 10% retry budget, Retry-After honoured, the missing index added.
Prevention
A timeout and retry budget table per call chain in the architecture docs, a code review checklist item, a dashboard and alert on retry share above 10%, and a chaos test in staging (Azure Chaos Studio adding SQL latency) that checks recovery within 60 s.

How to tell it (STAR)

**S:** At [company], a slow SQL query under our inventory service turned into a [45-minute] checkout outage, even though the query was fixed in [10 minutes]. **T:** I was incident lead and then owned the follow-up. **A:** I noticed inventory traffic had gone up eightfold while user traffic was flat, so I counted calls per operation in Application Insights and found over a hundred inventory calls for a single user request. Every service was retrying three times. We turned retries off above pricing through App Configuration, the breaker opened and the database recovered in [about 3 minutes]. Afterwards I introduced one retrying layer per call chain, a 10% retry budget and an alert on retry share. **R:** A similar slowdown three months later caused [90 seconds] of errors instead of 45 minutes, and retries never went above [8%] of traffic.

More in Reliability Patterns

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me