Make a Google Pay Charge Endpoint Safe to Retry With Idempotency Keys
Last updated: November 29, 2026
Quick Overview
Implement a server-side idempotency layer for a payment charge RPC so that client retries after timeouts never double charge, and a reused key with a different payload is rejected.
0
0
0 solved
Implement a server-side idempotency layer for a payment charge RPC so that client retries after timeouts never double charge, and a reused key with a different payload is rejected.
Payments teams at Google care deeply about retries because mobile clients on flaky networks resend requests after timeouts. The interviewer checks that you separate the in-flight, completed and conflicting cases and that the key store is updated atomically with the side effect.
What the Interviewer Expects
- Store the request fingerprint alongside the idempotency key
- Return the saved response for a replay with the same payload
- Reject the same key with a different payload
- Handle a concurrent duplicate while the first is in flight
- Discuss key expiry and storage cost
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 do you make the key insert and the charge atomic across two systems?
- What TTL would you choose and why?
- Should a failed charge be cached or retried on replay?
- How do you scope keys so two merchants cannot collide?
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
charge(key, merchant, request)performs the charge at most once per(merchant, key).- Same key and same body: return the original response, do not charge again.
- Same key, different body: retu...
High-Level Design
Keys are scoped by merchant so they cannot collide across tenants. The store row holds state, a SHA-256 fingerprint of the canonical request, and the final response. The first request claims the key...