Make The Pledge Charge Endpoint Idempotent Under Client Retries

Last updated: November 29, 2026

Quick Overview

Mobile clients retry the 'join tier' request on flaky networks, sometimes causing duplicate charges. Implement an idempotency layer for the charge endpoint that replays the original result for a repeated key, rejects a reused key with a different body, and handles in-flight duplicates.

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

0

0

0 solved


Mobile clients retry the 'join tier' request on flaky networks, sometimes causing duplicate charges. Implement an idempotency layer for the charge endpoint that replays the original result for a repeated key, rejects a reused key with a different body, and handles in-flight duplicates.

Patreon's checkout runs on web and mobile apps where retries on bad connections are common, and a duplicate charge is the worst possible first experience for a new patron. This question checks practical API design: idempotency keys, request fingerprints, concurrency, and what to do when the downstream outcome is unknown.

What the Interviewer Expects
  • Scopes keys per user so one fan cannot collide with another
  • Stores a fingerprint of the request body and rejects mismatches
  • Handles a second request that arrives while the first is still running
  • Replays the stored response for completed requests without calling the processor again
  • Distinguishes definite failures (free the key) from unknown outcomes (keep it and reconcile)
  • Explains how this maps onto a database unique constraint in production
Key Topics to Cover
idempotency keys
API design
concurrency
payments safety
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 long should keys live, and what happens if a client retries after expiry?
  • How would you implement the in-progress lock across many app servers?
  • Should a 4xx validation error be stored and replayed, or recomputed?
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

The client generates a UUID per checkout attempt and sends it as Idempotency-Key. Same key and same body: return the first response. Same key and a different body: error (client bug). Same key while...

High-Level Design

A record per (user_id, key) holds the body fingerprint, a status (in_progress or done) and the stored response. Claiming the key is atomic: in production, an INSERT into a table with a unique ...


Submit Your Answer
Markdown supported

Related Questions