Testable Retry With Exponential Backoff for Agent Tool Calls

Last updated: November 29, 2026

Quick Overview

Write a helper that calls a flaky downstream tool (such as an order API) and retries transient failures with capped exponential backoff and full jitter, while staying deterministic in unit tests.

Sierra
Software Engineering Fundamentals
Software Engineer
Sierra
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


Write a helper that calls a flaky downstream tool (such as an order API) and retries transient failures with capped exponential backoff and full jitter, while staying deterministic in unit tests.

Sierra agents call customer systems like order management and CRMs that time out or rate limit, and a naive retry loop can either give up too early or hammer a struggling backend. The interviewer checks retry policy basics and, just as much, whether you design the code so it can be tested without real sleeps.

What the Interviewer Expects
  • Retry only on errors classified as transient
  • Use exponential backoff with a cap and jitter
  • Bound attempts and respect an overall deadline
  • Inject sleep, clock and randomness for deterministic tests
  • Mention idempotency for non-read tool calls
Key Topics to Cover
testing and debugging
retries and backoff
dependency injection
idempotency
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
  • Which tool calls are unsafe to retry, and how would you make them safe?
  • How would you honor a Retry-After header from a 429 response?
  • How would you add a circuit breaker on top of this?
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

Call fn(). If it raises RetryableError, wait and try again, up to max_attempts total. Any other exception propagates immediately. Delay for attempt n is a random value in `[0, min(cap, base * 2^...

High-Level Design

Keep policy in parameters and side effects behind injected callables: sleep, rng and clock. Production uses the real ones; tests pass a list's append as sleep and a constant rng to assert exac...


Submit Your Answer
Markdown supported

Related Questions