Network failure and retry budgets
Quick answer
A network timeout tells a client it did not receive a result in time; it does not prove that the server did nothing. A retry budget limits additional attempts and total elapsed time.
Classify failures and bound work
Retry only eligible transient failures when the operation is safe to repeat. Use a deadline, per-attempt timeout, capped exponential backoff and jitter; retries at multiple layers can amplify load. Permanent validation failures should stop immediately. These simulations use fixed inputs rather than sleeping or contacting a service. In production, derive remaining time from a monotonic clock and use vetted client policies.
fn main() { let mut delay = 100u64; for _ in 0..4 { println!("{delay}"); delay = delay.saturating_mul(2).min(500); }}Expected stdout (not executed):
100200400500Milliseconds are modeled; production clients should also randomize intervals and respect a deadline.
fn allowed(remaining: u64, delay: u64, attempt: u64) -> bool { delay.checked_add(attempt).is_some_and(|cost| cost <= remaining)}fn main() { println!("{} {}", allowed(300, 100, 200), allowed(299, 100, 200)); }Expected stdout (not executed):
true falseThis policy reserves time for a complete next attempt; a real timeout must be enforced by the I/O layer.
Common mistake
Do not retry every failure indefinitely or assume a timeout is proof of no side effect.
Try it yourself
With a 600 ms budget, calculate which delays and 100 ms attempts can fit; include the initial attempt.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Network failure and retry budgets — practice quiz
Choose one answer per question. Code examples are predictions; review explanations after attempting them.
A retry needs 100 ms delay and 200 ms attempt time, but only 250 ms remain. Should this policy start it?
Network failure and retry budgets — example 1. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```rust fn main() { let mut delay = 100u64; for _ in 0..4 { println!("{delay}"); delay = delay.saturating_mul(2).min(500); } } ``` What standard output should the program produce if its run succeeds? Ignore Cargo and diagnostic messages.
Network failure and retry budgets — example 2. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```rust fn allowed(remaining: u64, delay: u64, attempt: u64) -> bool { delay.checked_add(attempt).is_some_and(|cost| cost <= remaining) } fn main() { println!("{} {}", allowed(300, 100, 200), allowed(299, 100, 200)); } ``` What standard output should the program produce if its run succeeds? Ignore Cargo and diagnostic messages.