Make a Purchase API Call Safe to Retry With Idempotency Keys

Last updated: November 29, 2026

Quick Overview

A client charges a customer through a remote payment API, and timeouts sometimes lead to the customer being charged twice when the client retries. Explain the failure and implement a retry policy and a server-side mechanism that make retries safe.

Microsoft
Software Engineering Fundamentals
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

0

0

0 solved


A client charges a customer through a remote payment API, and timeouts sometimes lead to the customer being charged twice when the client retries. Explain the failure and implement a retry policy and a server-side mechanism that make retries safe.

Microsoft Store, Xbox purchases, and Azure resource creation all face the same distributed systems problem: a timeout does not tell you whether the operation happened. Interviewers check that you understand at-least-once delivery, idempotency keys, and backoff with jitter, which the Azure SDK retry policies implement.

What the Interviewer Expects
  • Explains that a timeout is ambiguous: the request may have succeeded
  • Introduces a client-generated idempotency key reused across attempts
  • Stores the key and result atomically with the side effect on the server
  • Retries only transient errors, with capped exponential backoff and jitter
  • Bounds total attempts or total time and surfaces final failure clearly
  • Discusses key expiry and concurrent duplicate requests
Key Topics to Cover
Idempotency
Retry policies
Exponential backoff
Jitter
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
  • Two retries with the same key arrive at the same time on different servers: what happens?
  • How long should the server keep idempotency keys, and what if a retry arrives after expiry?
  • Why does jitter matter when thousands of clients fail at the same moment?
  • Which HTTP status codes would you treat as retryable?
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

A charge must happen at most once per user intent, even if the client retries after timeouts, connection resets, or 503s. Non-transient errors (declined card) must not be retried. Retries must not sta...

High-Level Design

The double charge happens because the first request succeeded on the server but the response was lost; the client saw a timeout and sent a brand new request. The network gives at-least-once delivery, ...


Submit Your Answer
Markdown supported