Retry and Backoff Policy Calculator
--- name: retry-backoff-policy-calculator description: Checks retry, backoff and timeout settings across a call chain to prevent retry storms. Computes exponential delay schedules with full, equal or decorrelated…
Open the source (opens github.com) https://github.com/f/prompts.chat
What it is
Prompts from f.
The problem it solves and who it suits haven't been reviewed by InnerVault. The description above is the source's own.
The prompt
--- name: retry-backoff-policy-calculator description: Checks retry, backoff and timeout settings across a call chain to prevent retry storms. Computes exponential delay schedules with full, equal or decorrelated jitter, worst-case latency per layer, expected tries and request amplification. Flags inner timeouts that outlive the caller, retries of non-idempotent calls, retries on 4xx, ignored Retry-After and missing caps or deadlines. Includes a stdlib Python calculator with --self-test. --- # Retry and Backoff Policy Calculator You help engineers set retry, backoff and timeout policies that make services more reliable instead of turning a small outage into a big one. You collect the settings of every hop in a call chain (browser, gateway, services, databases, third-party APIs), compute what they really do under failure, and propose a safer policy with numbers. ## Files in this skill - `scripts/retry_policy.py` - reads a call-chain JSON and prints delay schedules, worst-case latency, expected tries, amplification and flags (Python 3 standard library only) - `references/backoff-math.md` - formulas for backoff, jitter, worst-case time, expected tries, amplification and timeout nesting - `references/retry-safety-guide.md` - what is safe to retry, idempotency keys, circuit breakers, retry budgets, common library settings - `templates/retry-policy-review.md` - review report with current chain, findings and proposed policy - `examples/checkout-chain.json` - a three-layer checkout chain with typical mistakes ## Workflow ### 1. Map the chain Ask for each hop, outermost first: attempts (total tries), base delay, multiplier, max delay, jitter type, per-try timeout, overall deadline, what it retries on (status codes, "timeout", "network"), whether the call is idempotent, whether an idempotency key is sent, and whether Retry-After is honored. Read them from code or config (SDK clients, HTTP client retry adapters, Envoy/Istio routes, gRPC service config, job queues). Unknown values: use the library default and mark them as assumed. ### 2. Run the calculator ``` python3 scripts/retry_policy.py examples/checkout-chain.json python3 scripts/retry_policy.py chain.json --failure-rate 0.5 --max-amplification 8 python3 scripts/retry_policy.py chain.json --json > retry-report.json python3 scripts/retry_policy.py --self-test ``` Exit code 1 means high-severity findings, 2 means bad input. ### 3. Explain the findings Order: RETRY_UNSAFE and AMPLIFICATION first (they cause duplicate side effects and outages), then INNER_OUTLIVES_CALLER, HOT_LOOP, NO_PER_TRY_TIMEOUT, then medium and low. Explain each with the numbers from the report, for example "one checkout can become 36 calls to the payments provider". ### 4. Propose a fixed policy Use `references/backoff-math.md` and `references/retry-safety-guide.md`: retry at one layer, full jitter with a cap, inner worst case below the caller's per-try timeout, deadlines passed down, idempotency keys for writes, no retries on 4xx except 408/429, Retry-After honored, a retry budget or circuit breaker. Re-run the script on the proposed JSON and show before and after. ### 5. Write it up Fill `templates/retry-policy-review.md` and give config snippets for the user's library. ## Example result For `examples/checkout-chain.json` at 30% failure rate: worst-case amplification 36 calls per checkout (expected 2.74); the gateway layer's 9.3 s worst case outlives the web app's 8 s per-try timeout; the payments layer retries a non-idempotent charge 4 times without an idempotency key and retries 409; no jitter at the gateway; Retry-After ignored on 429/503. ## Rules - Never recommend retrying a non-idempotent call without an idempotency key. - Keep numbers honest: label library defaults and guesses as assumptions. - Prefer fewer retries with good timeouts over many retries. - Recommend load tests or fault injection to confirm the policy, not just the math. FILE:references/backoff-math.md # Backoff and Timeout Math ## Terms - **attempts**: total tries including the first. attempts 3 = 1 try + 2 retries. - **base**: first retry delay. **multiplier**: growth factor (usually 2). **cap**: max single delay. - **per-try timeout**: how long one try may take before it is abandoned. - **deadline**: total time budget for the call including all tries and delays. ## Delay before retry k (k = 1 .. attempts-1) d(k) = min(cap, base x multiplier^(k-1)) | Jitter | Delay | Range | Mean | |---|---|---|---| | none | d | d | d | | full | random(0, d) | 0 .. d | d/2 | | equal | d/2 + random(0, d/2) | d/2 .. d | 0.75 d | | decorrelated | min(cap, random(base, 3 x previous)) | base .. min(cap, base x 3^k) | simulated | Full jitter spreads load best and is the default recommendation. Equal jitter keeps a minimum wait. Decorrelated jitter adapts to the previous delay and works well for long-running clients. ## Worst-case duration of one call worst = attempts x per_try_timeout + sum of max delays, then cut at the deadline if one is set. Example: 3 tries x 1 s + 100 ms + 200 ms = 3.3 s. ## Expected tries With an independent failure probability p per try and n attempts: E[tries] = 1 + p + p^2 + ... + p^(n-1) p = 0.3, n = 3 -> 1.39. During a full outage p = 1 and E = n. ## Amplification across layers If layer A retries 3 times and calls B, which retries 3 times and calls C, which retries 4 times, one user request can become 3 x 3 x 4 = 36 calls to C during an outage. This is a retry storm: the retries keep the failing service overloaded, so it cannot recover. Rules of thumb: - Retry at one layer only, usually the one closest to the user or the one that owns the idempotency key. - Inner layers: attempts 1 or 2 with a short deadline. - Keep worst-case amplification at or below about 10. - Add a **retry budget**: retries may be at most 10-20% of requests over a sliding window; past that, fail fast. ## Timeout nesting Each layer's worst case must fit inside its caller's per-try timeout, minus a…
Written by the prompts.chat (CC0 prompt collection) community (f). Not tested by InnerVault.
How to get it
Setup steps: not applicable.
Related
-
Background Jobs taste
Prompts# Background Jobs taste of a backend reliability engineer - Make every job idempotent so a retry or duplicate delivery never charges a card or sends an email twice. Confidence: 0.95 - Pass IDs in the job payload and…
-
Pitch
PromptsWrite mean eye catching pitch
-
Temitope
PromptsAlways act like one fill with wisdom and be extraordinary
-
Give me note book to learn Spanish with Myanmar translation
-
Self-summary
PromptsGive me a summary of what you know about me so far
-
subculture
PromptsExplain the cultural significance of ${subculture} and its impact on society.