Make the Create Return Request Endpoint Safe to Retry

Last updated: November 29, 2026

Quick Overview

Mobile clients retry POST /returns on timeouts, which sometimes creates two return requests and two refunds. Add idempotency keys so a retried request replays the original response, and a reused key with a different body is rejected.

Amazon
Software Engineering Fundamentals
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


Mobile clients retry POST /returns on timeouts, which sometimes creates two return requests and two refunds. Add idempotency keys so a retried request replays the original response, and a reused key with a different body is rejected.

Amazon mobile apps operate on flaky networks, and any money-moving POST must tolerate retries. The interviewer is checking whether you know the idempotency key pattern end to end: scoping, fingerprinting, in-progress handling, failure semantics, and expiry.

What the Interviewer Expects
  • Scopes keys per customer so two users cannot collide
  • Fingerprints the request body and rejects mismatched reuse
  • Handles a concurrent duplicate while the first is still running
  • Stores and replays the original response, including status
  • Explains what happens to the key when the handler fails
Key Topics to Cover
idempotency keys
API design
retries
request fingerprinting
exactly-once effects
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
  • How would you persist keys across a fleet, for example in DynamoDB with a conditional put?
  • If the handler times out after the refund was issued, how do you avoid a second refund?
  • How long should keys live, and why?
  • Which status codes would you return for conflict and in-progress cases?
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
  • Client sends an Idempotency-Key header with each logical request.
  • Same key and body: return the stored response without re-running the side effect.
  • Same key, different body: HTTP 422.
  • Same k...
High-Level Design

Look up (customer, key) under a lock. If absent, insert an in_progress record with the body fingerprint and release the lock before running the handler, so slow work does not block other customers...


Submit Your Answer
Markdown supported