Skip to main content

Module backoff

Module backoff 

Source
Expand description

BackoffPolicy — whether a failed request is tried again, and how long the caller waits first.

Every wire protocol the engine speaks needs this decision, and answers kept per client drift apart — most damagingly on jitter: without it, every client that hits the same rate limit retries in lockstep.

§What is protocol-specific and what is not

Reading a retry-after header is protocol work: the header exists on one side and not the other, and its spelling is part of the wire format. So parsing stays in the client. What the number means — whether to honour it, whether the attempt budget is spent, how long to actually sleep — is not protocol work, and that is what moves here. A client’s whole contribution is to describe the failure it just had, in the four kinds below, plus whatever the provider itself asked for.

§The attempt budget is the policy’s, not the caller’s

Bounding a retry loop by comparing an attempt counter against the ladder’s length would put “how many times” in the caller and “how long” in the table. They are one decision. The policy is asked after every failure and answers Backoff::GiveUp when it is done, so a deployment that wants four retries, or none, changes one thing rather than two.

Structs§

FailedAttempt
One failed attempt, as the policy sees it.
LadderBackoff
The engine’s own answer: a ladder of delays, jittered, deferring to the provider when it names a delay itself.
NoBackoff
Never retries anything.

Enums§

Backoff
What the caller should do about it.
RequestFailure
Why an attempt failed, reduced to what a backoff decision can act on.

Traits§

BackoffPolicy
Whether a failed request is tried again, and after how long.