Idempotent Payment Creation API That Survives Client Retries

Last updated: November 29, 2026

Quick Overview

Design and implement POST /v1/payments for checkout so that a client retrying after a timeout never charges the customer twice, a key reused with a different body is rejected, and a duplicate arriving while the first is in flight gets a clear response.

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

0

0

0 solved


Design and implement POST /v1/payments for checkout so that a client retrying after a timeout never charges the customer twice, a key reused with a different body is rejected, and a duplicate arriving while the first is in flight gets a clear response.

Flipkart's mobile app retries requests on flaky networks, and a double charge on a UPI or card payment is a support and trust problem. Interviewers in the API design portion want an idempotency contract, correct HTTP semantics for each case, and awareness that the downstream gateway must dedupe as well.

What the Interviewer Expects
  • Require a client-generated Idempotency-Key and explain its scope
  • Store a request fingerprint and reject mismatched reuse
  • Replay the original response for completed duplicates
  • Handle the concurrent in-flight duplicate
  • Propagate the key to the payment gateway and set a retention TTL
Key Topics to Cover
idempotency keys
HTTP status semantics
retries
exactly-once effects
API contracts
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
  • The process crashes after charging but before saving the response. How do you recover?
  • Where would you store keys when there are 50 API pods, and what unique constraint do you need?
  • How long should keys be retained and why?
  • How does this differ from making the order id itself the dedupe key?
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 Idempotency-Key (UUID per checkout attempt) with {order_id, amount_paise, method}.
  • First request charges and returns 201.
  • Same key and same body returns the saved response witho...
High-Level Design

An idempotency table keyed by (merchant_id, idempotency_key) with a unique index holds fingerprint, state and the serialized response. begin is an atomic insert-if-absent; in SQL this is `INSE...


Submit Your Answer
Markdown supported

Related Questions