skip to content

Which distribution models the number of retries before a flaky request finally succeeds?

level: juniorimportance: should knowfreq 48%

answer

  1. counting trials, not events in a window
  2. you stop at the first success
  3. a single parameter: success probability
  4. mean is one over p when the success is counted

basics

~20 s

The geometric distribution. It counts repeated independent attempts, each succeeding with the same probability p, up to the first success. It is not Poisson, because Poisson counts events inside a fixed window rather than trials.

solid answer

~50 s

Retries are a sequence of independent attempts, each succeeding with the same probability `p`, and you stop at the first success. That is exactly the geometric distribution. Two conventions exist and you should say which you mean: counting the trials including the successful one gives support 1, 2, 3, ... with mean `1 / p`, while counting only the failed retries before the success gives support 0, 1, 2, ... with mean `(1 - p) / p`. The phrase *retries before success* is the second one. It is not Poisson: a Poisson models how many events land in a fixed window of time or space, and there is no notion of a trial or a stopping rule. If instead you fixed the number of attempts at `n` and counted how many succeeded, that would be binomial.

go deeper

for a junior

Be ready to recognise a stop-at-first-success process on sight and name the geometric distribution, plus its single parameter, the per-attempt success probability.

for a middle

Explain both indexing conventions and their means, and articulate precisely why a count of trials is a different object from a count of events in a fixed window.

for a senior

Demonstrate that you check the constant-probability assumption against real retry logs, and that you handle retry caps and backoff as censoring or as a mixture rather than forcing one geometric fit.

for a principal

Own what the model is for: retry budgets, client timeouts and load amplification during an incident all follow from the assumed attempt distribution, so say which decision the family choice is meant to support.

## What the process actually looks like Strip the scenario to its skeleton. A client sends a request. It either succeeds or it does not. If it fails, the client sends another one. This repeats until a success arrives, and then it stops. Recording *how many attempts that took* produces the random quantity in question. Three features fix the family: 1. **Each attempt is a two-outcome trial.** Success or failure, nothing in between. A single such trial is a Bernoulli trial with success probability `p`. 2. **Trials are independent and `p` does not change** from one attempt to the next. 3. **The stopping rule is the first success.** You do not run a fixed number of attempts; the count itself is what varies. Any process with those three features is geometric. That is the whole identification rule, and it is worth memorising in that form because it transfers far beyond retries: coin flips until the first head, cold calls until the first sale, lock acquisitions until one is granted, cards drawn with replacement until a face card appears. ## The two conventions, and why they matter The geometric distribution comes in two indexings, and interviewers do notice when a candidate blurs them. - **Trials until and including the first success.** Support 1, 2, 3, ... The probability of needing exactly `k` trials is `p` multiplied by `(1 - p)` raised to the power `k - 1`. The mean is `1 / p`. - **Failures before the first success.** Support 0, 1, 2, ... The probability of exactly `k` failures is `p` multiplied by `(1 - p)` to the power `k`. The mean is `(1 - p) / p`, exactly one less than the other convention. With `p = 0.2`, the expected number of trials is 5 and the expected number of failed retries is 4. Both are correct answers to different questions. Naming the convention in one clause costs nothing and prevents an off-by-one that looks careless. ## Why not Poisson The most common wrong answer is Poisson, usually reached by the reasoning *it is a count of failures, and failures are rare events, so Poisson*. The mismatch is structural: - A Poisson count is defined over an **exposure**, a window of time, an area, a batch. Change the window and the mean changes proportionally. Retries have no window; they have a stopping rule. - A Poisson has **no upper limit and no ordering** of trials. The retry count is generated by a sequence with a defined stop. - The Poisson question would be *how many failed requests occurred in the last five minutes*, which is a genuinely different quantity from *how many retries did this one request need*. Both can be answers on the same system. Which one you want depends on whether you are describing one request's journey or a stream of failures over a period. ## Neighbouring choices for neighbouring processes - **Fixed number of attempts, count the successes:** binomial, with parameters `n` and `p`. - **Waiting for the r-th success rather than the first:** negative binomial, of which the geometric is the case `r = 1`. - **Retries capped at a maximum:** a truncated geometric with a point mass at the cap. This matters operationally, because the observed mean retry count is pulled below `1 / p` by the give-up rule, and reading the raw average as if it were `1 / p` overstates the success probability. - **Success probability that changes between attempts,** for example exponential backoff into a service that is recovering: the trials are no longer identically distributed, so no single geometric applies. Model the per-attempt probabilities explicitly, or simulate. ## Diagnosing it from data Given a column of retry counts, the family is easy to sanity-check. The distribution should be strictly decreasing: one retry is more common than two, two more than three, with no interior hump. A hump in the middle is a signal that `p` is not constant, most often because attempts early in an outage fail far more often than attempts later. In that case the honest answer is a mixture, not a single geometric, and saying so is stronger than forcing the fit. ## What a good answer sounds like Name the family, state the convention you are using, give the mean under that convention, and then note the assumption that would break it in production, namely that `p` is constant across attempts. That is four sentences and it covers everything the question is testing.

  • What changes if the client gives up after five attempts?
    The distribution is truncated, with the leftover probability piling up as a point mass at the cap. The observed mean number of attempts is then lower than `1 / p`, so estimating `p` by inverting the raw average biases it upward. Model the give-up explicitly, or estimate `p` only from requests that eventually succeeded, accounting for the censoring.
  • What if each retry uses backoff into a service that is gradually recovering?
    Then the success probability rises across attempts, so the trials are not identically distributed and no single geometric fits. The empirical retry counts will show a shape that decays too slowly early and too fast late. Model the per-attempt probability as a function of attempt number, or simulate the policy directly.
  • How would you instead model the number of failed requests in a fixed five-minute window?
    That is a count over an exposure, not a count of trials, so it is Poisson-shaped if failures occur independently at a roughly constant rate. If the number of requests in the window is fixed and known, and each fails independently with the same probability, it is binomial instead.

saying these in an interview costs you the question

  • Calls any count of failures a Poisson count
  • Ignores that trials must be independent with constant success probability
  • Mixes the two conventions and reports the mean off by one
  • Assumes unlimited retries when the client caps attempts
  • Cannot say what changes when the number of attempts is fixed instead

context