Course outline

JavaScript / Advanced: scheduling and trustworthy interfaces / Lesson 21

Retries, cancellation, and idempotent effects

Design bounded retry behavior around operation semantics, result ownership, and verification of ambiguous outcomes.

About 20 min read20 worked examples20 practice exercisesContent reviewed
On this page

Lesson goals

  • Classify failures before retrying.
  • Distinguish stale-result guards from cancellation and server-side idempotency.
  • Test bounded attempts and ambiguous write outcomes.
  • Classify failures and bound retry attempts, deadlines, and cancellation.
  • Use a documented server idempotency contract to address ambiguous write outcomes.

Classify the operation and failure

A retry repeats an operation, so its safety depends on what that operation does. A read can often be retried after a transient failure; a payment or order creation may already have succeeded even when its response was lost. Authentication failure, invalid input, and a programmer error usually need a different response from a transient transport failure. Establish a total time budget, maximum attempts, and the specific failures eligible for retry before adding a loop.

Bound and observe retry work

The example receives both the operation and the pause function so a test can control failures and time without sleeping. It retries only errors explicitly marked retryable and stops after a bounded number of attempts. Production policies should use a suitable backoff with jitter, respect service guidance, and record attempt count and final outcome without logging sensitive payloads. A retry policy should also propagate cancellation and account for the total deadline, which this small teaching example deliberately leaves to its caller.

javascript A bounded retry for a controlled read
async function retryRead(operation, pause, attempts = 3) {
  for (let attempt = 1; attempt <= attempts; attempt++) {
    try { return await operation(); }
    catch (error) {
      if (attempt === attempts || !error.retryable) throw error;
      await pause(attempt * 100);
    }
  }
}
let calls = 0;
retryRead(async () => {
  if (++calls === 1) throw Object.assign(new Error("temporary"), { retryable: true });
  return "ready";
}, async () => {}).then(console.log);

Injected pause makes the example deterministic; the caller supplies any real delay and cancellation policy.

Keep only the current result

A search interface can issue overlapping reads. An older request may finish after the latest one, even when an abort was requested. Assign a monotonically increasing identifier to each request and render a result only if its identifier is current. The example isolates that comparison; a real interface also needs error and loading-state ownership. This guard prevents stale presentation but does not stop network work or reverse any operation on the server.

javascript Guard a result by request identity
function isCurrent(requestId, currentId) {
  return requestId === currentId;
}
let currentId = 0;
const first = ++currentId;
const second = ++currentId;
console.log(isCurrent(first, currentId));
console.log(isCurrent(second, currentId));

Only the most recently issued request is current; the comparison itself does not cancel work.

Handle writes with a server contract

For a write with an ambiguous response, first determine whether the service provides an idempotency mechanism or a status lookup. A stable key associated with one logical operation can allow the server to recognize a repeated submission when the service explicitly implements that contract. Generate a new key for a genuinely new operation, preserve the original key for a retry, and follow the service’s retention and payload rules. A client-generated key alone does not guarantee deduplication.

Verify success, exhaustion, and ambiguity

Use a controlled operation that fails once and then succeeds, another that always fails with a retryable error, and a non-retryable failure. Assert exact attempt counts and the returned or propagated result. For the interface, complete two requests in reverse order and verify that the older result cannot replace the current one. For writes, test duplicate submissions against a controlled service implementing the stated key contract and verify the resulting effect, not merely the response code.

Classify failures and effects before retrying

A retry is another attempt at an operation, not proof that the first attempt did nothing. Classify both the operation and the failure before repeating work. A transient read failure may be retryable under a documented policy, while malformed input or an authorization denial normally needs correction or a different response rather than an automatic loop. A timeout is ambiguous: the caller may not know whether a remote write completed. Do not infer the absence of an effect from the absence of a response.

Define the total number of attempts, which failures are retryable, the deadline, and the outcome after exhaustion. A three-attempt policy means at most three calls in total, including the first. Preserve a useful final error for the owner while showing a safe user-facing message. The examples use controlled synthetic operations in Node; they make no network requests and do not establish a remote service contract.

Bound attempts, delay, and ownership

A bounded retry loop should stop on success, stop immediately for a non-retryable error, and stop when the attempt count or deadline is exhausted. If a pause is required between attempts, make it an explicit dependency so a test can inject a no-op pause and count attempts without waiting for real time. Production policies may use increasing delays and jitter to reduce synchronized retry bursts, but their exact limits depend on the service and product. Do not claim an arbitrary delay guarantees a remote recovery.

Check cancellation before starting another attempt and during a supported wait. Cancellation is cooperative: an AbortSignal can only stop work that observes it, and an already completed side effect is not undone. Ensure each started promise has an owner and that the final success, error, or cancellation reaches the caller. Test success on the last permitted attempt, immediate non-retryable failure, exhaustion, and cancellation without relying on external services.

Treat write retries as a server contract

A create-order response can time out after the server has already created the order. Sending a new request with a new key may represent a second logical operation and create a duplicate. When a service documents an idempotency-key contract, retry the same logical request with its original key and the same relevant payload according to that contract, or use its documented status lookup. The server must enforce the key's scope, retention, conflict behavior, and stored outcome; a client-generated key alone does not guarantee exactly-once effects.

A key reused with a different payload may be rejected or handled according to the service contract. Do not silently assume a universal behavior or retention period. Test an ambiguous first response using a controlled fake server that records actual effects, then assert that the retry under the supported contract produces one order. Also test a new logical operation with a distinct key and a conflicting payload case. Reconcile unknown outcomes when the service lacks a safe retry mechanism.

Separate cancellation from result ownership

A caller can cancel a supported read and still need to ignore a stale result if cancellation arrives too late. Associate each request with a generation and let only the current owner update success, error, and cleanup state. An older finally block must not clear the busy indicator of a newer request. A cancellation signal, a generation guard, and an idempotency key solve different parts of the workflow; none replaces server authorization or a documented write contract.

Do not retry a cancellation as if it were an ordinary transient error unless the product explicitly requests a new operation. Stop scheduling future attempts when the owner cancels, observe any promise already started, and release resources according to the underlying API. A cancelled client request may still have reached the server, so a write with an uncertain outcome still needs reconciliation or the same supported idempotency key. Test cancellation during a controlled pause as well as stale success and stale failure.

Test success, exhaustion, and ambiguity

Use injected operations, clocks or deadlines, and pauses to make retry tests deterministic. For a read that fails transiently twice and succeeds on the third call, assert the result and exactly three calls when the three-attempt limit and deadline allow them. For exhaustion, assert the final failure and exact call count. For a non-retryable error, assert one call and no pause. Test cancellation before the next attempt and verify no additional call is made.

For writes, use an isolated fake or authorized test service that records actual effects, not just client call counts. Simulate a timeout after creating an order, retry with the same logical key under a documented server contract, and assert one order. Test a new key and conflicting payload according to the service's rules. Record assumptions and unsupported behaviors; a local fake verifies the modeled contract, not the production server implementation. Include a safe user-facing error and appropriate private diagnostics for unresolved ambiguity.

20 worked examples

1. First attempt succeeds

Problem: Return a synthetic read result without making an unnecessary second attempt.

  1. The controlled read fulfills on its first invocation.
  2. The workflow returns the result immediately and the call count remains one.
javascript First attempt succeeds
let calls = 0; async function read() { calls++; return "ok"; } (async () => { const x = await read(); console.log(x, calls); })();
Expected output
ok 1

Why this result follows: The workflow returns the result immediately and the call count remains one.

2. Success on third attempt

Problem: Retry two transient read failures and return the third result.

  1. The synthetic operation fails on calls one and two and succeeds on three.
  2. The bounded loop returns the successful third result after exactly three calls.
javascript Success on third attempt
let calls = 0; async function read() { calls++; if (calls < 3) throw new Error("transient"); return "ok"; } (async () => { for (let n = 1; n <= 3; n++) { try { const x = await read(); console.log(x, calls); break; } catch (e) { if (n === 3) throw e; } } })().catch(console.error);
Expected output
ok 3

Why this result follows: The bounded loop returns the successful third result after exactly three calls.

3. Exhaust three attempts

Problem: Stop retrying a controlled read after three failed calls.

  1. Every synthetic call fails and the limit includes the first call.
  2. The loop reports exhaustion on the third failure without making a fourth call.
javascript Exhaust three attempts
let calls = 0; async function read() { calls++; throw new Error("transient"); } (async () => { for (let n = 1; n <= 3; n++) { try { await read(); } catch (e) { if (n === 3) console.log("exhausted", calls); } } })();
Expected output
exhausted 3

Why this result follows: The loop reports exhaustion on the third failure without making a fourth call.

4. Non-retryable failure

Problem: Stop after one controlled authorization failure rather than retrying it.

  1. The failure category is denied rather than the retryable transient category.
  2. The synthetic policy stops immediately and reports the authorization denial after the first single call.
javascript Non-retryable failure
let calls = 0; async function read() { calls++; throw { kind: "denied" }; } (async () => { try { await read(); } catch (e) { if (e.kind !== "transient") console.log(e.kind, calls); } })();
Expected output
denied 1

Why this result follows: The synthetic policy stops immediately and reports the authorization denial after the first single call.

5. Injected pause

Problem: Count retry pauses without waiting for real time in a synthetic test.

  1. Two failed calls are followed by the injected no-op pause.
  2. The successful third call needs no further pause, yielding three calls and two pauses.
javascript Injected pause
let calls = 0, pauses = 0; async function read() { if (++calls < 3) throw "transient"; return "ok"; } async function pause() { pauses++; } (async () => { for (let n = 1; n <= 3; n++) { try { await read(); break; } catch { if (n < 3) await pause(); } } console.log(calls, pauses); })();
Expected output
3 2

Why this result follows: The successful third call needs no further pause, yielding three calls and two pauses.

6. Cancellation before retry

Problem: Stop a synthetic retry loop when its signal is already aborted.

  1. The signal is aborted before the next attempt is considered.
  2. The cancellation guard prevents another operation call under this explicitly stated synthetic retry policy.
javascript Cancellation before retry
const c = new AbortController(); c.abort(); let calls = 0; if (!c.signal.aborted) calls++; console.log(calls);
Expected output
0

Why this result follows: The cancellation guard prevents another operation call under this explicitly stated synthetic retry policy.

7. Deadline blocks retry

Problem: Stop a synthetic retry when its deadline has already been reached.

  1. The controlled clock equals the deadline rather than preceding it.
  2. The strict before-deadline policy refuses to start another attempt at the boundary.
javascript Deadline blocks retry
const now = 10, deadline = 10; console.log(now < deadline ? "attempt" : "stop");
Expected output
stop

Why this result follows: The strict before-deadline policy refuses to start another attempt at the boundary.

8. Retryable classification

Problem: Classify a synthetic transient failure as eligible for retry.

  1. The controlled error carries the the policy transient category.
  2. The classifier permits retry consideration subject to the remaining attempts, deadline, and cancellation state.
javascript Retryable classification
const error = { kind: "transient" }; console.log(error.kind === "transient");
Expected output
true

Why this result follows: The classifier permits retry consideration subject to the remaining attempts, deadline, and cancellation state.

9. Input error is not transient

Problem: Classify invalid input as non-retryable under a synthetic policy.

  1. The input error does not match the configured transient category.
  2. The caller should handle the invalid data rather than repeat the same request automatically.
javascript Input error is not transient
const error = { kind: "invalid-input" }; console.log(error.kind === "transient");
Expected output
false

Why this result follows: The caller should handle the invalid data rather than repeat the same request automatically.

10. Current result wins

Problem: Ignore a stale result after a newer retrying search becomes current.

  1. The old result identifier does not match the current generation.
  2. The ownership guard preserves the newer visible search result despite the old operation completing late.
javascript Current result wins
let current = 2, view = "new"; function apply(id, value) { if (id === current) view = value; } apply(1, "old"); console.log(view);
Expected output
new

Why this result follows: The ownership guard preserves the newer visible search result despite the old operation completing late.

11. Guard old cleanup

Problem: Keep a new request busy when an older operation finishes cleanup.

  1. The old operation no longer owns the active busy indicator.
  2. The generation check prevents stale cleanup from clearing the newer request state.
javascript Guard old cleanup
let current = 2, busy = true; function finish(id) { if (id === current) busy = false; } finish(1); console.log(busy);
Expected output
true

Why this result follows: The generation check prevents stale cleanup from clearing the newer request state.

12. Same key same result

Problem: Model a server that reuses an outcome for the same key and payload.

  1. The synthetic server records the first outcome under key k1.
  2. The modeled same-key retry returns the recorded outcome and leaves one synthetic operation recorded.
javascript Same key same result
const saved = new Map(); function create(key, payload) { if (!saved.has(key)) saved.set(key, { payload, id: 1 }); return saved.get(key).id; } console.log(create("k1", "A"), create("k1", "A"), saved.size);
Expected output
1 1 1

Why this result follows: The modeled same-key retry returns the recorded outcome and leaves one synthetic operation recorded.

13. New key new operation

Problem: Show that two different synthetic keys can represent two create operations.

  1. The second request uses a distinct logical key.
  2. This modeled server records another operation rather than deduplicating across unrelated keys.
javascript New key new operation
const saved = new Map(); function create(key) { if (!saved.has(key)) saved.set(key, saved.size + 1); return saved.get(key); } console.log(create("k1"), create("k2"), saved.size);
Expected output
1 2 2

Why this result follows: This modeled server records another operation rather than deduplicating across unrelated keys.

14. Conflicting payload

Problem: Reject reuse of a synthetic key with a different payload under a stated policy.

  1. Key k1 already belongs to payload A in this fake contract.
  2. The different payload is rejected rather than silently treated as the same logical request.
javascript Conflicting payload
const saved = new Map([["k1", "A"]]); function create(key, payload) { if (saved.has(key) && saved.get(key) !== payload) return "conflict"; saved.set(key, payload); return "ok"; } console.log(create("k1", "B"));
Expected output
conflict

Why this result follows: The different payload is rejected rather than silently treated as the same logical request.

15. Timeout is ambiguous

Problem: Model a lost response after a synthetic order has already been recorded.

  1. The fake records the order before returning the timeout marker.
  2. A missing response does not prove that the side effect failed to occur.
javascript Timeout is ambiguous
const orders = []; function create() { orders.push("order"); return "timeout"; } console.log(create(), orders.length);
Expected output
timeout 1

Why this result follows: A missing response does not prove that the side effect failed to occur.

16. Observe final error

Problem: Return a controlled exhaustion error to the caller after a failed attempt.

  1. The async workflow rejects with the documented final error.
  2. The caller owns the returned promise and observes its final failure through the attached catch.
javascript Observe final error
async function run() { throw new Error("exhausted"); } run().catch(e => console.log(e.message));
Expected output
exhausted

Why this result follows: The caller owns the returned promise and observes its final failure through the attached catch.

17. No pause after success

Problem: Stop the retry workflow immediately after a synthetic successful read.

  1. The first call returns successfully and no retry is needed.
  2. The successful result is delivered after one operation call and zero injected retry pauses.
javascript No pause after success
let calls = 0, pauses = 0; async function run() { calls++; return "ok"; } (async () => { const result = await run(); console.log(result, calls, pauses); })();
Expected output
ok 1 0

Why this result follows: The successful result is delivered after one operation call and zero injected retry pauses.

18. Bounded attempts include first

Problem: Count the total calls in a two-attempt synthetic policy.

  1. The loop starts with attempt one and stops after attempt two.
  2. The configured total includes the initial attempt, so exactly two calls are permitted.
javascript Bounded attempts include first
let calls = 0; for (let attempt = 1; attempt <= 2; attempt++) calls++; console.log(calls);
Expected output
2

Why this result follows: The configured total includes the initial attempt, so exactly two calls are permitted.

19. Cancel is not rollback

Problem: Show an existing synthetic effect remains after a cancellation flag changes.

  1. The order effect exists before the cancellation flag is set.
  2. Changing client cancellation state alone does not remove the previously recorded effect.
javascript Cancel is not rollback
const effects = ["order"]; let cancelled = false; cancelled = true; console.log(cancelled, effects.length);
Expected output
true 1

Why this result follows: Changing client cancellation state alone does not remove the previously recorded effect.

20. Separate logical keys

Problem: Associate two synthetic order intents with different idempotency keys.

  1. The two keys denote separate logical intents in this fixture.
  2. The second key identifies its own operation rather than retrying the first key.
javascript Separate logical keys
const intents = new Map([["k1", "order A"], ["k2", "order B"]]); console.log(intents.size, intents.get("k2"));
Expected output
2 order B

Why this result follows: The second key identifies its own operation rather than retrying the first key.

Common errors and fixes

A retry creates duplicate orders

Why it happens
The original write succeeded but its response was lost, and a repeated request had no supported deduplication contract.
How to fix it
Check operation status or use the service’s documented idempotency mechanism.
Prevent it next time
Model ambiguous responses and retry semantics before enabling automatic write retries.

A stale search overwrites a newer result

Why it happens
Completion order was assumed to match request order.
How to fix it
Guard rendering with the current request identity.
Prevent it next time
Test reversed completion and ensure loading and errors have the same ownership.

A retry loop never finishes

Why it happens
Attempts or the overall deadline are not bounded, or permanent failures are retried.
How to fix it
Classify eligible failures and impose an attempt and time budget.
Prevent it next time
Test both exhaustion and immediate propagation of permanent errors.

20 practice exercises

1. A read fails transiently twice and succeeds on the third attempt. What should a three-attempt policy return?

Show hint

The three-attempt limit includes the first call.

Show worked solution

It returns the third result after three calls, provided both failures are classified retryable and the deadline allows the attempts. A test can inject a no-op pause and assert the call count without waiting for real time.

If both failures are retryable and the deadline permits, return the third result after three total calls. Inject a no-op pause and assert the call count and result without waiting for real time. Do not schedule a fourth call after success.

Check your solution

  • The result comes from attempt three.
  • Exactly three calls are made.

2. A create-order response times out. Is it safe to submit a new request with a new key?

Show hint

A timeout does not prove the first write had no effect.

Show worked solution

Not automatically: the original order may exist, and a new key may represent a second operation. Use the documented status lookup or retry the same logical request with its original key when the server supports that contract. Verify the number of actual orders.

The original order may already exist. Do not assume a new key is safe: use the documented status lookup or retry the same logical request with its original key and payload when the server supports that contract. Verify the actual order count in an isolated test.

Check your solution

  • The ambiguous first effect is reconciled.
  • The retry does not blindly use a new key.

3. A read fails transiently twice then succeeds under a three-attempt limit. Determine the result.

Show hint

The limit includes the initial call.

Show worked solution

If both failures are classified retryable and the deadline permits, return the third result after exactly three calls. Inject a no-op pause in the test and assert both result and call count. Do not make a fourth call after success.

Check your solution

  • The third result is returned
  • Exactly three calls are made

4. Define what a three-attempt retry limit counts for a failing read. Explain the expected policy and outcome.

Show hint

Count the initial request as the first attempt.

Show worked solution

The policy allows at most three total calls, not one initial call plus three retries. If all three fail with retryable errors, report the documented exhaustion outcome and do not start a fourth call. Test the exact call count.

Check your solution

  • The initial call counts as attempt one
  • Exhaustion occurs after at most three calls

5. A read returns an authorization denial. Decide whether to retry under a transient-only policy.

Show hint

A denial is not the configured transient category.

Show worked solution

Stop after the first denial and return the documented non-retryable failure to the caller. Do not pause and repeat identical unauthorized requests automatically. Test one call, no retry pause, and a safe user-facing error.

Check your solution

  • Only one call occurs
  • No retry pause is scheduled

6. A malformed input error occurs before a read. Explain why retrying unchanged input is inappropriate.

Show hint

The input must be corrected rather than repeated.

Show worked solution

Classify invalid input as non-retryable under the stated policy and report the correction needed. Repeating the same malformed value does not repair its syntax and wastes work. Assert one attempted validation path and no repeated operation calls.

Check your solution

  • The error is classified non-retryable
  • No repeated operation is started

7. Inject a pause into a retry test that succeeds on the third attempt.

Show hint

A no-op pause can record calls without real elapsed time.

Show worked solution

Pass a synthetic pause function that increments a counter and resolves immediately. With two retryable failures then success, assert three operation calls and two pauses. Await the whole workflow so the test observes the result and any rejection.

Check your solution

  • There are three operation calls
  • There are two injected pauses

8. Define behavior when a retry deadline is reached before the next attempt.

Show hint

Check the deadline before starting more work.

Show worked solution

Stop scheduling attempts once the documented deadline no longer permits another call and return the appropriate deadline outcome. Test the exact boundary using an injected clock, not a guessed sleep. Observe any already-started operation according to its cancellation contract.

Check your solution

  • No attempt starts after the deadline
  • Already-started work remains owned

9. Cancel a retry during its pause and state what happens to the next attempt.

Show hint

The pause and loop must observe cancellation.

Show worked solution

Use a pause that supports the signal and check cancellation before scheduling the next operation. On cancellation, stop the loop and return or throw the documented cancellation outcome. Test with a controlled pause and assert no additional operation call occurs.

Check your solution

  • Cancellation is observed during the pause
  • No next attempt is started

10. Explain why cancellation should not normally be classified as a transient failure to retry.

Show hint

The owner has requested that the operation stop.

Show worked solution

Treat cancellation as its own documented outcome and stop scheduling further attempts. Retrying it as an ordinary transient error can defeat the caller intent and waste resources. Start a new operation only when the product explicitly requests one.

Check your solution

  • Cancellation stops the retry loop
  • A new operation requires an explicit decision

11. An order create response times out. Explain why the order may still exist.

Show hint

The server effect and the client response are separate events.

Show worked solution

The server may have created the order before the response was lost or delayed, so timeout alone does not prove failure. Use the documented status lookup or same-key retry contract if supported, and reconcile the actual order count before another logical create.

Check your solution

  • Timeout is treated as ambiguous
  • The actual effect is reconciled

12. Decide whether to retry a timed-out create with a new idempotency key.

Show hint

A new key may represent a new logical operation.

Show worked solution

Do not assume a new key is safe: the original order may already exist and the new key may create another. Follow the documented server same-key retry or status lookup contract. Verify the number of actual orders in an isolated test.

Check your solution

  • The original outcome is not assumed absent
  • A new key is not used blindly

13. Describe the required server behavior for a same-key same-payload retry contract. Explain the expected policy and outcome.

Show hint

The server must enforce the documented key semantics.

Show worked solution

The server must associate the key with the logical request and its outcome according to documented scope and retention, then handle the same-key same-payload retry consistently. The client key alone is insufficient. Test actual effects and the returned outcome under the service contract.

Check your solution

  • The server enforces key scope and outcome
  • The same logical retry does not create a duplicate under the contract

14. Test a fake server that times out after creating an order and supports same-key retries.

Show hint

Count actual order effects rather than only client calls.

Show worked solution

Configure the fake to record the first order but hide its response, then retry the same payload with the same key under its stated contract. Assert the returned outcome is consistent and exactly one order exists. Await both attempts and inspect the fake stored effects.

Check your solution

  • Exactly one order effect exists
  • The retry uses the original key and payload

15. A same idempotency key arrives with a different payload. Define a test without inventing service behavior.

Show hint

Consult the documented conflict behavior for the target service.

Show worked solution

Read the service contract for key scope, payload matching, and conflict handling, then assert that documented outcome in an isolated test. Do not assume all services reject or accept the conflict in the same way. Confirm no unintended duplicate side effect occurs.

Check your solution

  • The documented conflict outcome is asserted
  • Actual effects are inspected

16. Explain why a client-generated idempotency key alone cannot guarantee exactly-once effects. Explain the expected policy and outcome.

Show hint

The server must enforce a documented contract.

Show worked solution

A key has no protective effect unless the server associates and enforces it for the relevant logical operation. Scope, retention, payload conflicts, and recovery are service-specific. Test the actual server behavior and reconcile ambiguity rather than claiming universal exactly-once execution.

Check your solution

  • Server enforcement is required
  • Scope and retention are documented

17. An old retrying search finishes after a newer search. Guard the visible result.

Show hint

Check the current generation before applying every outcome.

Show worked solution

Capture a generation for each search and apply success, error, and cleanup only when it still owns the current state. Ignore stale rendering but observe the old promise. Test reversed completion and ensure old finally cannot clear the newer busy indicator.

Check your solution

  • The newer result remains visible
  • Old cleanup cannot clear the newer busy state

18. Explain the relationship between cancellation, generation guards, and idempotency keys. Explain the expected policy and outcome.

Show hint

They address different boundaries and failure modes.

Show worked solution

Cancellation requests supported work to stop; a generation guard prevents obsolete results from updating current state; a server-enforced idempotency key identifies a logical write under its contract. None automatically supplies the others or replaces authorization. Test each boundary independently.

Check your solution

  • Stale rendering is guarded
  • Write deduplication requires server enforcement

19. Design an exhaustion test for a read with two allowed attempts. Explain the expected policy and outcome.

Show hint

Make both controlled attempts fail with retryable errors.

Show worked solution

Inject an operation that fails transiently on both calls and a no-op pause. Await the retry workflow, assert the documented exhaustion error, and verify exactly two calls with no third attempt. Confirm the error remains visible to the caller.

Check your solution

  • Exactly two calls occur
  • The caller observes exhaustion

20. Explain what a passing local idempotency fake proves and what remains to be verified.

Show hint

A fake implements a model, not the deployed server itself.

Show worked solution

The fake supports the modeled same-key behavior for its synthetic cases, such as recording one order after an ambiguous response. It does not prove the production service key scope, retention, conflicts, or recovery. Verify the documented contract using an authorized isolated integration environment.

Check your solution

  • The modeled fixture records one effect
  • The real service contract requires separate verification

Key takeaways

  • Retry only classified failures within a bounded budget.
  • Separate UI result ownership from server-side write deduplication.
  • A timeout does not prove a write had no effect.
  • A retry limit counts total attempts including the first call.
  • A client key alone does not guarantee a server-side idempotent effect.

Official references