Implement An Idempotent Wallet Transfer Endpoint

Last updated: November 29, 2026

Quick Overview

Implement transfer(client_id, idempotency_key, src, dst, amount) for an in-memory wallet service so that retries with the same key never double-debit, a key reused with a different payload is rejected, and failures are replayed consistently.

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

0

0

0 solved


Implement transfer(client_id, idempotency_key, src, dst, amount) for an in-memory wallet service so that retries with the same key never double-debit, a key reused with a different payload is rejected, and failures are replayed consistently.

Circle's developer APIs ask clients to send an idempotency key with every money-moving request, because networks time out and clients retry. The interviewer checks that you store the outcome with the key atomically, compare request fingerprints, and scope keys per client.

What the Interviewer Expects
  • Stores the result and the request fingerprint atomically with the balance change
  • Replays the original response, including failures, on retry
  • Rejects reuse of a key with a different payload
  • Scopes keys per API client
  • Makes the check-and-apply step atomic under concurrency
  • Discusses key expiry and storage in a real database
Key Topics to Cover
Idempotency keys
Atomicity
Concurrency control
API design
Ledgers
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 would you implement this on Postgres with multiple API servers?
  • Should an insufficient-funds failure be cached, or should a retry be allowed to succeed later?
  • How long do you keep idempotency records, and what happens after they expire?
  • The request is accepted but the downstream chain transaction is still pending; what does the retry return?
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 retry with the same (client_id, key) and same payload returns the first response and moves no money.
  • Same key, different payload: reject with a conflict error (HTTP 409 or 422), because the cl...
High-Level Design

Hold one lock around lookup, apply and store so two concurrent retries cannot both apply. The fingerprint is the canonical request body (here a tuple; in production a hash of the normalised JSON). In ...


Submit Your Answer
Markdown supported

Related Questions