Make a Retry Helper Testable With Backoff and Jitter

Last updated: November 29, 2026

Quick Overview

Write a retry helper for calls to a flaky internal RPC that uses capped exponential backoff with full jitter, retries only transient errors, and can be unit tested without real sleeping.

Google
Software Engineering Fundamentals
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


Write a retry helper for calls to a flaky internal RPC that uses capped exponential backoff with full jitter, retries only transient errors, and can be unit tested without real sleeping.

Google's SRE guidance stresses backoff with jitter to avoid retry storms, and a retry loop is a quick way to check both correctness and testability. Interviewers look for selective retries, a cap, jitter, and an injectable sleep and random source.

What the Interviewer Expects
  • Retries only transient error types
  • Uses exponential backoff with a cap
  • Adds jitter to avoid synchronized retries
  • Injects sleep and randomness for tests
  • Preserves the original error as the cause
Key Topics to Cover
exponential backoff
jitter
retry storms
testability
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • Why can retries make an outage worse, and how do retry budgets help?
  • How would you respect a deadline propagated from the caller?
  • Should every layer of a call stack retry?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • retry(fn, attempts, base, cap) calls fn up to attempts times.
  • Retry on ConnectionError and TimeoutError only; other errors propagate immediately.
  • Delay before retry k is uniform in [0, min(c...
High-Level Design

A loop over attempts. On a retryable error, sleep for the jittered delay unless this was the last attempt. sleep and rand are parameters with production defaults, so tests can pass sleeps.append...


Submit Your Answer
Markdown supported