Implement an Idempotency Key Store for Payment Requests
Last updated: November 29, 2026
Quick Overview
Build an in-memory component that wraps a payment handler so a request retried with the same merchant and idempotency key returns the original response instead of charging twice, while a reused key with a different body is rejected.
Adyen
November 29, 20260
0
0 solved
Build an in-memory component that wraps a payment handler so a request retried with the same merchant and idempotency key returns the original response instead of charging twice, while a reused key with a different body is rejected.
Merchants calling the Adyen API retry on timeouts, and the platform must guarantee a shopper is never charged twice for one intent. The interviewer is checking that the candidate scopes keys per merchant, fingerprints the payload, handles in-flight duplicates and expiry, and knows what changes when this moves from memory to a shared database.
What the Interviewer Expects
- Scope keys by merchant account, not globally
- Store a fingerprint of the request to detect key reuse with a different body
- Handle a duplicate that arrives while the first request is still running
- Expire entries after a TTL and explain how to choose it
- Explain the persistent version with a unique constraint
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you implement this across many application servers with PostgreSQL?
- If the handler times out talking to the card network, should the key be released or kept?
- Which fields belong in the fingerprint and which should be excluded?
- How long should keys be retained and what does that cost in storage?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
execute(merchant, key, body, handler) runs handler(body) at most once per (merchant, key) within a TTL. A repeat with the same body returns the stored response. A repeat with a different body is a...
High-Level Design
A dictionary keyed by (merchant, key) stores the body fingerprint, a status (IN_PROGRESS or DONE), the response and an expiry. A lock guards the check-and-reserve step so two threads cannot both reser...