ProgramGuru

Retry with Backoff and Jitter Pattern

Retry with Backoff and Jitter: start from the problem

See the responsibilities

AttemptHas an operation identity
Failure classificationDecides if another attempt is appropriate
Budget + waitBounds time, count and spacing
OutcomeReturns success or unresolved/final failure
Attempt: Has an operation identity → Failure classification: Decides if another attempt is appropriate → Budget + wait: Bounds time, count and spacing → Outcome: Returns success or unresolved/final failure

A service experiences a temporary read failure. Repeating the operation may succeed, but repeating every failure immediately at every layer can create a storm. Repeating a write can also duplicate an already committed effect.

This is a workflow and resilience pattern lesson. Follow the responsibilities, inspect the small JavaScript example and compare the design choices. The example is local teaching code; its boundary is explained before you apply the idea to a real service.

What you’ll learn

  • Explain the problem Retry with Backoff and Jitter addresses and the roles involved.
  • Follow the example and distinguish this pattern from nearby alternatives.
  • Choose when the benefit justifies the extra responsibilities and testing.

How the responsibilities work

A Retry policy selects which failures may be transient, bounds attempts and elapsed time, and preserves operation identity where effects can repeat. Backoff spaces attempts; jitter varies waits so many callers do not all retry together.

The small synchronous example retries a local transient result and succeeds on attempt three. It does not simulate delays or remote commit uncertainty. Production code must combine the attempt rule with a remaining deadline and the actual effect contract.

Follow a small example

Read the JavaScript from top to bottom and compare the expected output. The values are chosen to make this pattern’s responsibility visible. This example runs in one local execution context; it does not create remote services, durable storage or production access controls.

JavaScript · local teaching example

let attempts = 0;
function operation() { attempts++; return attempts === 3 ? 'ok' : 'transient'; }
let result;
for (let i = 0; i < 3; i++) {
  result = operation();
  if (result === 'ok') break;
}
console.log(result + ' after ' + attempts);

Expected output

ok after 3

Choose a design and inspect the consequence

Compare the design choices

Every service layer independently makes three attempts.
Thousands of callers wake for a retry together.

Compare the visible consequences. With JavaScript enabled, choose an option in each scenario to assemble your decision record.

This is an exploratory design exercise. It does not run infrastructure, measure capacity or replace the lesson’s quiz.

Use the consequences to explain your decision, including the simpler alternative.

Apply the pattern to two situations. Select one option in each situation to build a decision record. Every option and its consequence stays visible, and you can change your choices.

When it helps—and what it costs

Use it for retryable outcomes where another attempt is justified and bounded. Prefer one deliberate retry boundary to independent amplification at every layer.

Retrying validation failures wastes work. Timeout outcomes may be uncertain. Stable idempotency keys need atomic coordination with the effect, and a new key on each attempt can duplicate the operation. Attempts must fit the total deadline, including waits.

Distinguish the neighbouring patterns

Circuit Breaker may prevent normal attempts while a dependency is unhealthy. Outbox relays and job workers can retry too, but each needs its own stable identity and progress boundary.

Follow the retry-amplification lab, repeat publication after lost acknowledgement, checking accepted work outcomes to compare the specific responsibility before combining patterns.

For further reading, use Microsoft’s Retry guidance. Compare it with this original example and the guarantee required by your application.

Check your pattern reasoning

Should a permanent permission rejection be retried indefinitely?
Choose one answer. You can try again.

Answer and explanation

No; classify the failure and obey the operation contract.

Repeating a permanent rejection does not fix permission.

Check your pattern reasoning

Why reuse the supported identity for a retried payment?
Choose one answer. You can try again.

Answer and explanation

To coordinate repeats as the same intended operation.

The remote effect may already have committed.

Name the responsibility before choosing the pattern

For Retry with Backoff and Jitter, describe the problem, the participating roles and the observable contract. Use the example as a starting point and test the boundaries identified in the trade-offs. A pattern name alone does not establish correctness or performance.

Return to the design-pattern guide to compare families, or apply the idea alongside checking accepted work outcomes.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Sidecar Pattern →