# Wallet transfers - the state machine, the hold that expires, and the reversal that cannot

> Teaches how money moves between two accounts in one system without ever being in both places or neither, and what it costs to make every step undoable…

Source: https://tierslate.com/templates/wallet-transfers

Payments & ledgers · System design · starter · 8 step walkthrough · 5 tables

Teaches how money moves between two accounts in one system without ever being in both places or neither, and what it costs to make every step undoable.

**Own this board: 200 credits.** The first act plays on the page. Owned once with credits, never a subscription.

## What this board gets wrong on purpose

The tension: Everything on the happy path is transactional and safe, and the entire risk of the system lives in the one state the transaction cannot cover: PENDING_EXTERNAL, where a hold exists on the sender’s money and the bank rail has been asked to move it. The hold sweeper is the only thing that ever rescues that state, it runs on a clock, and it cannot tell a dead transfer from a slow one - so it will eventually release a hold for a payout the bank is still processing, at which point the sender can spend money that is about to leave, and the wallet goes negative in a way no CHECK constraint prevented because the money was legitimately spent twice by two legitimate paths. Lengthening the expiry makes customers’ money unusable for longer; shortening it makes the race more likely. The second unresolved thing is the reversal, which is drawn as an ordinary transfer in the opposite direction and is therefore subject to every failure the original was - including insufficient funds. A recipient who has already spent the money cannot be reversed, and nothing on this board decides what happens then: the balance would go negative, the CHECK refuses it, and the reversal simply fails with no defined next step other than a human.

## Practise this as an interview

Take Wallet transfers - the state machine, the hold that expires, and the reversal that cannot as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.

## Start here

### Why this design

Moving money between two wallets in one database looks like a single transaction, and interviewers ask it to find out whether you notice where that stops being true. A payout to a bank, a limits check, a notification and a reversal weeks later each add a state the transaction cannot cover. Every fintech and marketplace wallet has this system, and the bugs it produces are regulatory events with a customer’s name on them, not stack traces.

### What you will learn

- How one idempotency key with a UNIQUE index stops a retried request from sending the money twice.
- How a hold makes money unspendable before it moves (spendable = balance_minor - held_minor), and the two CHECK constraints that make the database, not the app, the safety argument.
- Why the 97% internal path is one plain transaction with no saga, and why adding one would be a downgrade.
- Why the 3% with an external leg sit in PENDING_EXTERNAL for up to three days, and hold 99.9% of the 54 MB of contended state.
- Why a reversal is a second transfer and never an UPDATE, and how it can itself fail on insufficient funds.
- The nightly identity check: wallet balances plus live holds must equal the bank float.

### How to read this board

1. Diagram, left to right: THE REQUEST (one key, one transfer), then THE STATE MACHINE (limits, hold, move, spend), then OUTSIDE (the bank rail), then AFTER (events, notifications and the nightly reconciliation). Press play for the eight-step walkthrough.
2. Then the band underneath: WHAT UNDOES A TRANSFER - the hold sweeper and the reversal, drawn under the path because compensation runs backwards.
3. Page 1 · Requirements - the questions that decide whether this is one transaction or a state machine.
4. Pages 2 and 3 · Capacity and Storage - 10M transfers/day, seven writes each, 60 TB over five years, and a holds table that must never grow.
5. Page 4 · Availability - the single points of failure, including a sweeper whose failure has no error message.
6. Page 5 · How it works - one transfer told end to end - then Page 6 · Deployment plan, where wallets are never active-active.
7. The DATA MODEL region between the diagram and these pages: five tables, and the two CHECK constraints that carry the safety argument.
8. Finish on the deliberate weakness: the sweeper is the only rescue for PENDING_EXTERNAL and cannot tell a dead payout from a slow one, and a reversal can fail with no defined next step. That is the conversation to have.

## 1 · Requirements

A wallet transfer looks like the simplest money problem in this collection - two rows, one database, subtract here and add there. The requirements below are all the ways that sentence turns out to be incomplete.

### Ask these before designing

- **Can a transfer leave the system?**If every transfer is wallet-to-wallet, the whole thing is one database transaction and most of this board is unnecessary. The instant a payout to a bank exists, there is a state that can be pending for three days, and that single state is where all the risk lives.
- **Can a wallet go negative?**The honest answer for most products is "never, except for fees and reversals", and those two exceptions are what make it a CHECK with a carve-out rather than a CHECK.
- **Who may reverse, and for how long?**Support reversing a transfer from last Tuesday is a different system from a 30-second undo window. The first needs a reversal that can fail; the second can just cancel.
- **Is the recipient notified before the money is final?**If yes, a later reversal is a conversation with an angry customer. If no, the product feels slow. Most teams pick "yes" without noticing they have chosen the conversation.
- **One currency per wallet?**Multi-currency wallets mean an FX rate at transfer time, a rate that can move between quote and execution, and somebody owning the resulting position. That is a second system, not a column.

### Functional

- Transfer an amount from one wallet to another, atomically, with an idempotency key.
- Hold funds before an external leg, and release the hold if it does not complete.
- Reverse a completed transfer by posting the opposite movement, linked to the original.
- Show a balance that never includes money that is held.
- List a wallet’s transfers with a stable order and a stable page boundary.
- Prove daily that wallet balances plus live holds equal the bank float.

### Non-functional

- **A wallet may never go negative**, enforced by a database CHECK rather than by application logic, because the application will eventually have two versions running at once.
- **No money is ever in both wallets or neither.**The internal leg is one transaction; there is no saga for it, and introducing one would be a downgrade.
- **p99 under 400 ms**for an internal transfer, which is entirely dominated by the limits check.
- **99.95% on the transfer path, 99.99% on balance reads.**People check their balance far more often than they send money, and a balance page that is down feels like the money is gone.
- **Read-your-writes on balances, always.**A sender who sees their old balance after sending assumes it failed and sends again.

### Explicitly out of scope

The underlying ledger (its own board), card issuing, KYC and onboarding, FX, and the bank rail’s internals. This board is about the state machine around a movement, not about the movement itself.

## The rest of this board

This page publishes the question. The answer - 5 more written pages, an 8-step narrated walkthrough and a 5-table schema - is the board itself, and it opens in Tierslate.

- 5 written pages
- 8 walkthrough steps
- 5 tables (32 columns)

5 pages behind this one:

- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan

## Related system design templates

- [Double-entry ledger system design](https://tierslate.com/templates/double-entry-ledger) - Teaches why money is stored as immutable movements and read as a derived sum, and what it costs to never update a total.
- [Fraud detection system design](https://tierslate.com/templates/fraud-detection) - Teaches how a risk decision is split between a synchronous call with a hard deadline and an asynchronous review that is allowed to be right.
- [Payment gateway system design](https://tierslate.com/templates/payment-gateway) - Teaches how a payment system stays correct when its authoritative dependency can fail in a way that tells you nothing.
- [Matching engine system design](https://tierslate.com/templates/stock-exchange) - Teaches why an exchange assigns order with a sequence number instead of measuring it with a clock, and what a single-threaded book buys in return.
- [OTP verification system design](https://tierslate.com/templates/otp-verification) - How a one-time code is issued, rate limited and checked, and why the SMS bill is the attack surface.
- [Subscription billing system design](https://tierslate.com/templates/subscription-billing) - How a recurring charge is driven by a billing clock, proration and dunning, and why plan changes are the hard part.
- [Currency exchange system design](https://tierslate.com/templates/currency-exchange) - Why a quoted FX rate is a short-lived promise with an expiry, and how rounding is a ledger decision.
- [Loyalty points system design](https://tierslate.com/templates/loyalty-points) - Why points are a ledger with expiry and liability, and why a balance column is the wrong answer again.

All 100 system design templates: https://tierslate.com/templates (Markdown: https://tierslate.com/templates.md)
