Walkthrough: A Payments Ledger

Topics Covered

Requirements and Numbers

The prompt

Scoping the functional requirements

Non functional requirements

The estimate

What has been established

Why correctness is broken into parts

A weaker opening for comparison

Questions that were not needed

Confirming the numbers

The ledger as a platform

API and Data Model

The API

Amounts and money types

Double entry

Balances

Idempotency

Partitioning

The state of the board

Account types and their rules

Transfer types and references

Refunds as transfers

Indexes

Keeping the step focused

Reading the model back

The High Level Design

The core path

Publishing events reliably

Reads

Walking one transfer

Asynchronous work around the ledger

Checking in

What the design avoids

Why not a key value store

Isolation level

Lock ordering

Where calls to banks happen

The shape of the design

Deep Dive: Retries and Hot Accounts

The retry problem

How long keys live

Idempotency beyond the API

Hot accounts

Another option

What the deep dive showed

A deeper follow up

Measuring contention

What the interviewer is listening for

Testing the invariants

Summarising the deep dive

Failures, Reconciliation and Wrap Up

Database failures

Service and relay failures

Reconciliation

The trade offs

Extensions

The close

Looking back at the session

What made it strong

Common mistakes on this problem

Closing the course

Monitoring

Questions the interviewer might still ask

Practising this walkthrough

One last habit

The final walkthrough is a payments ledger: the system at the heart of a wallet, a marketplace or a payments company that records every movement of money between accounts. It is a common senior and staff level prompt because the scale is moderate but the correctness bar is extreme. Losing a tweet is unfortunate; losing or duplicating a payment is a regulatory and financial incident. The problem tests whether a candidate can design for correctness first and performance second, and whether they know the standard techniques that make money systems safe: double entry, idempotency, transactional outboxes and reconciliation.

As with the other walkthroughs, the dialogue shows one good path through the problem. Your session will differ, but the order of decisions and the way each is justified should look similar.

The prompt

The interviewer says: design the ledger for a payments platform. Users and merchants have accounts. Money moves between them when people pay, get refunds or withdraw. We need to know every account's balance and the history of how it got there. The prompt is about a ledger, not a whole payments company, and the candidate's first job is to keep it that way.

Scoping the functional requirements

Interview Dialogue

CandidateLet me confirm the core. The ledger records transfers between accounts: a payment from a user to a merchant, a refund back, a payout from a merchant to their bank. For each account we need the current balance and the full history of entries. Is that right?
InterviewerClick to reveal answer
CandidateAround a real payments platform there is a lot more: card network integration, fraud scoring, currency exchange, merchant onboarding, statements. I would like to treat those as other systems that call the ledger or read from it, and focus on recording transfers correctly, serving balances and history, and staying consistent with the banks we settle with. Does that work?
InterviewerClick to reveal answer
CandidateCan balances go negative?
InterviewerClick to reveal answer
Show all answers
Scope the ledger to transfers, entries and balances.

In about a minute the candidate has drawn a clear boundary: the ledger is the system of record for money movements, and everything else is a client of it. The question about negative balances produced a rule, no overdrafts for users, that will shape the write path, because the ledger must check a balance and move money atomically.

Non functional requirements

Interview Dialogue

CandidateThe most important requirement is correctness. Money is never created or destroyed by the system: every transfer debits one account and credits another by the same amount. No transfer is applied twice, even if a client retries. And no user balance goes below zero. I would rather reject or delay a transfer than get any of those wrong.
CandidateSecond, durability: once we tell a client a transfer succeeded, it must survive any single failure, including losing a data centre. Third, auditability: every balance must be explainable from an immutable history of entries, which auditors and support teams will read. Fourth, availability: high, but where it conflicts with correctness, correctness wins. Fifth, latency: a transfer should complete within a few hundred milliseconds, since it often sits inside a checkout.
InterviewerClick to reveal answer
Show all answers

The candidate made the ordering explicit and stated the conflict resolution rule, correctness over availability, out loud. That one sentence settles a whole class of later questions, such as whether to accept writes during a network partition, before they are asked.

The estimate

Interview Dialogue

CandidateLet me size it. Say fifty million accounts and a hundred million transfers a day. That is about twelve hundred a second on average, and with peaks around four times average, about five thousand a second. Each transfer writes at least two entries, so ten thousand entry writes a second at peak, plus balance updates.
CandidateStorage: an entry is maybe two hundred bytes with its metadata, so a hundred million transfers a day is two hundred million entries, about forty gigabytes a day, fifteen terabytes a year. Entries are kept for years for audit, so after five years we have under a hundred terabytes. That is large but manageable, and old entries are rarely read.
CandidateThe detail that matters most is distribution. Most accounts see a few transfers a month. But a large merchant on a sale day might receive hundreds or a thousand payments a second. If its balance is one row, every one of those transfers wants to update the same row.
InterviewerClick to reveal answer
CandidateNot throughput, which a partitioned relational database can handle. The hard parts are correctness under retries and failures, and hot accounts that concentrate writes on a single row.
Show all answers
Moderate throughput; the risk is correctness and hot accounts.

The estimate shows that raw throughput is modest, a few thousand transfers a second, and points at the real difficulties: correctness and hot accounts. That framing prevents the common mistake of reaching for an exotic high throughput store and then struggling to make it transactional.

What has been established

About seven minutes in, the board shows the scope (transfers, balances, history, reconciliation), the requirements in order with correctness first, and the key numbers: five thousand transfers a second at peak, ten thousand entry writes, under a hundred terabytes over five years, and hot merchant accounts. The candidate has also named the two hard parts, which tells the interviewer where the deep dive will go.

Why correctness is broken into parts

Notice that the candidate did not just say the system must be correct. They split correctness into three testable properties: money is conserved, no transfer is applied twice and user balances never go negative. Each property maps to a mechanism later: double entry for conservation, idempotency keys for no duplicates and a conditional balance check for no overdrafts. Breaking a vague requirement into concrete properties is one of the most useful habits in any interview, because it turns a slogan into a checklist the design can be measured against.

A weaker opening for comparison

A weaker opening would treat the ledger as a balances table with an update balance endpoint, estimate only throughput and choose a store for its speed. The interviewer would then have to ask how retries are handled, how history is kept and how balances are audited, and each answer would be a patch on a design that started from the wrong place. Starting from correctness avoids all of that.

Questions that were not needed

The candidate did not ask how many countries the platform operates in, what the user interface looks like or which card networks are supported. None of those affects how a ledger records a transfer. Each opening question either narrowed the scope or produced a rule the design must follow, such as one currency and no user overdrafts.

Confirming the numbers

Before moving on, the candidate could check the scale with one question: does a hundred million transfers a day with peaks around five thousand a second match what you have in mind? If the interviewer says it is ten times larger, the conclusion barely changes. Fifty thousand transfers a second still fits a well partitioned distributed SQL database, and the hard parts are still correctness and hot accounts. Saying that the conclusion is robust to the exact number is itself a useful signal, because it shows the candidate knows which numbers drive the design and which do not.

The ledger as a platform

It also helps to say early that the ledger is a platform for other teams. Checkout, refunds, payouts and billing all call it, and none of them should be able to break its rules. That framing explains why the API is narrow and why the rules live inside the ledger rather than in its callers.

Split a vague requirement into checkable properties

Saying the ledger must be correct is a slogan. Saying money is conserved, no transfer applies twice and user balances never go negative is a checklist. Each property then maps to a mechanism, which makes the design easy to explain and easy for the interviewer to evaluate.

For a ledger, the data model is the design. Most of the important decisions, how money is represented, how history is kept and how duplicates are prevented, are made here. The candidate keeps the API short and spends most of this step on the tables.

The API

Interview Dialogue

CandidateThe core write is POST transfers, with a source account, a destination account, an amount, a type such as payment or refund, a reference to the business object, like an order id, and an idempotency key. It returns a transfer id and a status. Then GET accounts slash id slash balance and GET accounts slash id slash entries with pagination for history, and GET transfers slash id.
CandidateThere is no endpoint to set a balance. Balances only change as a result of transfers.
InterviewerClick to reveal answer
CandidateBecause it is the rule that keeps the ledger auditable. If anything can set a balance directly, the history no longer explains it. Corrections are made with new transfers, such as an adjustment from a correction account, so they are visible in the history too.
Show all answers

That small statement, no endpoint to set a balance, says a great deal about the candidate's understanding. It turns auditability from a requirement into a property of the API.

Amounts and money types

Interview Dialogue

CandidateAmounts are stored as integers in the smallest unit, cents, never as floating point numbers, so there are no rounding errors. Each amount carries its currency code even though we have one currency today, because adding currencies later is much easier if every amount already knows its currency.

Integer minor units and an explicit currency are details that interviewers often look for in payments problems, and the candidate mentioned them in two sentences without being asked.

Double entry

Interview Dialogue

CandidateThe core table is entries. Each transfer creates at least two entries: a debit on the source account and a credit on the destination, with amounts that sum to zero. An entry has an entry id, the transfer id, the account id, a signed amount, the currency and a timestamp. Entries are append only: never updated, never deleted.
CandidateA transfers table records the transfer itself: id, type, reference, status, idempotency key and the time. Accounts have an id, an owner, a type such as user, merchant or internal, and a flag for whether they may go negative.
InterviewerClick to reveal answer
CandidateBecause the invariant, that all entries for a transfer sum to zero, and all entries in the whole ledger sum to zero, can be checked at any time. If a bug ever creates money, the sum stops being zero and we find it. It also makes every movement symmetric: there is always a from and a to, including fees, which are just a third entry crediting a fee account.
Show all answers
Every transfer is two entries that sum to zero.

Double entry is the centuries old answer to exactly this problem, and the candidate justified it with the property that matters most in a software system: a cheap, global invariant that detects bugs. Mentioning that fees are just more entries shows how the model extends without special cases.

Balances

Interview Dialogue

CandidateIn principle, a balance is the sum of an account's entries. But summing years of entries on every balance read is too slow, and the overdraft check needs the balance on the write path. So I keep a balances table, one row per account with the current balance and a version number, updated in the same transaction as the entries.
CandidateThe entries remain the source of truth. A background job periodically recomputes balances from entries and alerts on any difference.

The candidate kept the materialised balance for performance but made it clearly derived, with a check that it matches the entries. That pattern, a fast derived view verified against an immutable log, appears throughout good financial systems.

Idempotency

Interview Dialogue

CandidateThe idempotency key is stored with a unique constraint, scoped to the client, together with the request's hash and the resulting transfer id. If a request arrives with a key we have seen, we return the stored result rather than creating a new transfer. If the same key arrives with a different request body, we reject it, since that is a client bug.

Partitioning

Interview Dialogue

InterviewerClick to reveal answer
CandidateBy account id for entries and balances, so an account's history and balance live together. The awkward part is that a transfer touches two accounts, which may be on different partitions. I will come back to that in the high level design, because it decides how the transaction works.
Show all answers

The candidate chose the partition key from the main read pattern and immediately named the problem it creates, cross partition transfers, deferring the answer to the next step. Naming a weakness before the interviewer does is a strong signal.

The state of the board

About fourteen minutes in, the board has a short API with no balance setter, integer amounts with currency, the entries, transfers, balances, accounts and idempotency tables, and a partition plan with one open question. The model already enforces conservation and auditability by construction.

Account types and their rules

The accounts table carries a type and a flag for whether the account may go negative. User accounts may not. Merchant accounts usually may not, although some platforms allow a small negative balance after a refund, recovered from future sales. Internal accounts, such as the platform's clearing account, its fee account and a correction account for adjustments, can go negative because they represent the platform's own position. Putting the rule on the account, rather than hard coding it per transfer type, keeps the write path simple: the transaction looks up the source account's flag and applies the non negative condition only when it is set.

Transfer types and references

Every transfer carries a type, such as payment, refund, payout, fee or adjustment, and a reference to the business object that caused it, such as an order or a refund request. The type makes reporting easy, since finance teams want totals by type. The reference makes support easy, since an agent looking at an order can find every transfer linked to it. Neither field affects correctness, but both make the ledger far more useful, and naming them takes a sentence.

Refunds as transfers

A refund is not an edit to the original payment. It is a new transfer in the opposite direction, from the merchant to the user, with a reference to the original payment. The original entries stay as they were. This keeps the history complete: anyone reading the user's account sees the payment and then the refund, with times and reasons, rather than a payment that silently disappeared. The same rule applies to every correction, which is why the candidate said there is no balance setter.

Indexes

Entries are read by account and time for history, so the primary index is account id plus timestamp or sequence. Transfers are read by id and by reference, so the reference needs a secondary index. Idempotency keys need a unique index scoped to the client. Stating these briefly confirms that every read in the API is efficient.

Keeping the step focused

Even though the data model took longer than in the other walkthroughs, each decision here is used later: the balances table in the overdraft check, the idempotency table in the retry deep dive, the account flag in the hot account discussion and immutable entries in reconciliation.

Reading the model back

A quick read back confirms the model covers the requirements: conservation by double entry, no duplicates by the idempotency key, no overdrafts by the account flag and conditional balance update, and auditability by immutable entries and visible corrections.

Make the rules properties of the model

No endpoint sets a balance, entries are append only and every transfer's entries sum to zero. When rules like these are built into the API and the tables, the system cannot violate them by accident, and auditing becomes a query rather than an investigation.

With the model in place, the candidate draws the system. The design is intentionally conservative: a small number of well understood components, arranged so that every transfer is one database transaction and every side effect is reliable. Most of the interesting decisions are about how to keep it that way.

The core path

Interview Dialogue

CandidateClients, such as the checkout service or the refunds service, call a transfer API. It is stateless, behind a load balancer. For each request it opens a transaction on the ledger database that does four things: inserts the idempotency key, failing if it already exists; checks and updates the source balance with a condition that it stays non negative; updates the destination balance; and inserts the transfer and its entries. If any step fails, the whole transaction rolls back.
CandidateThe ledger database is a relational database with synchronous replication to a second zone, so an acknowledged transfer survives losing a zone.
InterviewerClick to reveal answer
CandidateRight. There are two options. One is a database that supports distributed transactions across partitions, such as a distributed SQL store; that keeps the transfer atomic at the cost of some latency. The other is to keep each transfer single partition by design. At our scale, five thousand transfers a second, I would start with a distributed SQL database and accept the cross partition cost, because atomic transfers are the core correctness property and building my own two phase protocol is where bugs come from.
Show all answers
One transaction writes entries, balances and the outbox.

The candidate faced the cross partition question directly, compared the two approaches on the deciding concern, correctness risk, and chose the one that keeps the hardest property in the database rather than in application code. That is a mature judgment: use the boring, proven mechanism for the part that must never be wrong.

Publishing events reliably

Interview Dialogue

CandidateOther systems need to know about transfers: notifications, analytics, merchant dashboards. The tempting approach is to commit the transaction and then publish an event, but if the service crashes between the two, the event is lost, and if we publish first, the event might describe a transfer that rolled back.
CandidateSo I would use a transactional outbox. The transaction also inserts a row into an outbox table. A relay reads the outbox in order and publishes to an event stream, marking rows as sent. Because the outbox row commits with the transfer, every committed transfer produces exactly one event row, and consumers deduplicate by transfer id in case the relay publishes twice.

The outbox is the standard answer to the dual write problem, and the candidate explained both failure cases that make the naive approach wrong. Noting that consumers must still deduplicate shows an understanding that at least once delivery is what the outbox provides.

Reads

Interview Dialogue

CandidateBalance reads go to the balances table, from the primary for anything that will be acted on, like a withdrawal screen, and from a replica for dashboards where a second of staleness is fine. History reads page through entries by account and time, which the partitioning makes efficient. Old entries, older than a year or two, can move to cheaper storage with a pointer, since they are read only for audits.

Separating reads that will be acted on from those that are only displayed is a small but important distinction in money systems, and the candidate made it in a sentence.

Walking one transfer

Interview Dialogue

CandidateLet me walk a payment. Checkout calls POST transfers with key k7. The API starts a transaction, inserts k7, which succeeds because it is new, updates the user's balance from five thousand to one thousand cents with the non negative condition, which passes, updates the merchant's balance, inserts the transfer and its entries and inserts an outbox row. It commits, replicated synchronously, and returns the transfer id. The relay then publishes the transfer event.

Asynchronous work around the ledger

The ledger itself stays small and synchronous. Everything that does not need to be in the transaction, sending receipts, updating analytics, notifying merchants, moving money to banks, happens downstream of the event stream. This keeps the transaction short, which matters for latency and for contention on busy accounts.

Checking in

Interview Dialogue

CandidateThat is the design: a stateless transfer API, one transaction per transfer covering the key, balances, entries and outbox, a distributed SQL database replicated across zones and an event stream fed by the outbox. I would like to go deep on correctness under retries and on hot merchant accounts. Which would you prefer?
InterviewerClick to reveal answer
Show all answers

The candidate is about twenty two minutes in, with a clear plan for the deep dive.

What the design avoids

The design avoids several common traps. It does not update balances without entries, which would destroy auditability. It does not publish events outside the transaction, which would lose or invent events. It does not build its own distributed transaction protocol. And it does not put slow work, such as calling a bank, inside the ledger transaction. Each of these traps is easy to fall into under time pressure, and avoiding all four is a strong signal.

Why not a key value store

An interviewer might ask why not use a high throughput key value store for balances. It would be fast, but most such stores lack multi row transactions, so debiting one account and crediting another atomically would need custom coordination. Any bug in that coordination creates or destroys money. At five thousand transfers a second, the throughput of a key value store is not needed, so its speed does not buy anything worth that risk. The candidate can say this in two sentences, and it reinforces the theme of the session: choose infrastructure by the correctness property it provides, not by raw speed.

Isolation level

Inside the transaction, the conditional balance update does the critical work. Writing it as update balances set amount equals amount minus forty where account is A and amount is at least forty means the check and the change are a single atomic statement, so two concurrent debits cannot both pass the check, whatever the isolation level. If the update affects zero rows, the transfer is rejected for insufficient funds. Mentioning that the condition lives in the update itself, rather than in a read followed by a write, shows the candidate understands where races come from.

Lock ordering

A transfer updates two balance rows. If two transfers move money in opposite directions between the same pair of accounts at the same time, each might lock one row and wait for the other, a deadlock. Updating balance rows in a fixed order, such as by account id, prevents this. The database would detect and break a deadlock anyway, but avoiding it keeps latency predictable.

Where calls to banks happen

Payouts to merchants' banks are slow and can fail for reasons outside the platform's control. They never happen inside the ledger transaction. Instead, a payout is recorded as a transfer from the merchant's account to a pending payouts account; the payouts service, reading events, calls the bank with the transfer id as its idempotency key and, on confirmation, records a second transfer from pending payouts to a settled account. If the bank rejects the payout, a reversing transfer returns the money to the merchant. Every step is visible in the ledger.

The shape of the design

The result is deliberately unexciting: a stateless API, one relational transaction per transfer and an event stream. For a ledger, boring is the goal, because every component is well understood and its failure modes are known.

Interviewers at payments companies tend to reward exactly that restraint.

Never dual write

Writing to a database and then publishing to a queue, or the reverse, will eventually lose or invent an event when a process crashes between the two. Put the event in an outbox table in the same transaction and let a relay publish it. Consumers then deduplicate by id.

The interviewer asked for both deep dive topics briefly, starting with retries. The candidate spends about seven minutes on each, keeping both at the level of mechanisms rather than slogans.

The retry problem

Interview Dialogue

CandidateThe dangerous case is this. Checkout sends a transfer. The ledger commits it, but the reply is lost because of a network timeout. Checkout does not know whether money moved, so it retries. Without protection, the retry moves money a second time.
CandidateWith the idempotency key, the retry's transaction tries to insert key k7, hits the unique constraint and rolls back. The API then reads the stored result for k7 and returns it, the same transfer id and status as the first call. The client cannot tell the difference between the first reply and the replayed one, which is exactly what we want.
InterviewerClick to reveal answer
CandidateThen the first transaction holds the key row. The second blocks on the unique index until the first commits or rolls back. If the first commits, the second sees the key and returns the stored result. If the first rolls back, the second proceeds as a new request. Either way, money moves at most once.
Show all answers
A retry with the same key returns the first result.

The candidate described the normal retry and then the concurrent retry, at the level of what the database does with the unique index. That second case is where many answers become vague, and handling it precisely is a strong signal.

How long keys live

Interview Dialogue

CandidateKeys are kept for a window long enough to cover any realistic retry, say seven days, and then archived. Clients are told to use a new key for a genuinely new transfer and the same key for any retry of the same one. The key is scoped to the calling service, so two services cannot collide.

Idempotency beyond the API

Interview Dialogue

CandidateIdempotency matters downstream too. When the payouts service consumes a transfer event to send money to a merchant's bank, it might see the same event twice. It uses the transfer id as its own idempotency key with the bank. So every hop that can retry carries a key derived from the original transfer.

Extending idempotency across the event stream and to the external bank shows the candidate sees retries as a property of the whole system, not one endpoint.

Hot accounts

Interview Dialogue

InterviewerClick to reveal answer
CandidateEach payment updates the merchant's balance row inside the transaction. Row level locking means those transactions queue on that row, one at a time. If each holds the lock for a millisecond, the ceiling is about a thousand a second, and latency climbs sharply as we approach it.
CandidateThere are a few options. The simplest is to split the merchant into several sub accounts, say eight or sixteen. Each incoming credit picks a sub account at random, so the writes spread across rows. The merchant's balance is the sum of the sub accounts, which is a cheap read of a few rows. Since the merchant is receiving money, there is no overdraft check on the credit path, so spreading credits is safe.
CandidateDebits from the merchant, such as refunds and payouts, are less frequent. They can take from whichever sub account has enough, or a periodic sweep can consolidate sub accounts into a main account.
Show all answers
Split a hot account so credits do not queue on one row.

Sub accounts are a well known technique, and the candidate explained why it is safe here: credits need no overdraft check, so they can go to any sub account. That reasoning, rather than the technique alone, is what the interviewer is evaluating.

Another option

Interview Dialogue

CandidateA second option is to stop updating the merchant's balance synchronously at all. Write the entries in the transaction, and let a separate process aggregate credits into the merchant's balance every second. The balance is then up to a second behind, which is fine for an account that only receives money. I would use sub accounts first because the balance stays exact, and keep asynchronous aggregation for the most extreme accounts.
InterviewerClick to reveal answer
CandidateBecause user accounts need an exact balance on the write path for the overdraft check. Asynchronous aggregation is only safe where nothing on the write path depends on the current balance.
Show all answers

The candidate compared two options and gave the rule for when each is safe. The follow up answer, that asynchronous balances are only safe where no write depends on them, is a precise statement of the trade off.

What the deep dive showed

In about fourteen minutes, the candidate showed exactly how duplicates are prevented, including the concurrent retry case, extended idempotency across the system, and handled hot accounts with two techniques and a clear rule for when each is safe. Every answer was tied back to the requirements: no duplicates, no overdrafts, conservation.

A deeper follow up

Interview Dialogue

InterviewerClick to reveal answer
CandidateIn a sense the ledger is already event sourced: entries are the events and balances are a projection. Dropping the materialised balance would make the overdraft check expensive, since we would need to sum entries on every debit, or keep a running balance in memory per account with a single writer. I would keep the balance row as the projection, updated transactionally, because it gives the overdraft check for free.
Show all answers

The candidate recognised that the design already had the essence of the suggestion and explained precisely what would be lost by going further, which is how to handle a challenge that is partly right.

Measuring contention

How would the team know a merchant account has become hot? The ledger can track lock wait time and transaction latency per account. When an account's lock waits rise above a threshold, it is a candidate for splitting. Splitting can be done online: create the sub accounts, start routing new credits to them and leave the existing balance in the main account, which still counts in the sum. Mentioning this operational path shows that the technique is not just a whiteboard idea.

What the interviewer is listening for

In this deep dive, the interviewer is listening for whether the candidate understands why each technique is safe, not just what it is. Sub accounts are safe because credits need no check. Asynchronous balances are safe only where no write needs the exact balance. The concurrent retry is safe because the unique index serialises it. Each of those reasons is a short sentence, and together they are the evidence of depth that a strong rating requires.

Testing the invariants

The candidate could add how the invariants are tested. Property based tests run random sequences of concurrent transfers, retries and failures against a test ledger and check after each run that all entries sum to zero, no key produced two transfers and no user balance went negative. Running these continuously catches bugs that ordinary tests miss.

Summarising the deep dive

Before moving on, the candidate summarised in one sentence: retries are safe because a unique key serialises them and every hop carries a key, and hot merchants are handled by sub accounts because credits need no balance check, with asynchronous aggregation reserved for receive only extremes. A clear summary marks the end of the deep dive and gives the interviewer a sentence to write down.

This walkthrough by level

A mid level answer reaches double entry, a balances table and idempotency keys with guidance. A senior answer adds the transactional outbox, handles the concurrent retry precisely and splits hot accounts with a reason it is safe. A staff answer also chooses where atomicity lives across partitions, extends idempotency to the bank, designs reconciliation and explains which accounts may use asynchronous balances and why.

The final stretch covers what happens when parts of the system fail, how the ledger stays consistent with the outside world and how the candidate closes the session.

Database failures

Interview Dialogue

InterviewerClick to reveal answer
CandidateWith synchronous replication to another zone, every acknowledged transfer is on the replica. The database promotes it, usually within tens of seconds. During that time, transfers fail with a retryable error, and clients retry with the same keys, so nothing is duplicated when the new primary comes up. We choose to be unavailable for those seconds rather than accept writes we cannot replicate, which matches the correctness over availability rule.
InterviewerClick to reveal answer
CandidateThen the side without a quorum stops accepting writes. A distributed SQL store does this by design. Again, unavailable is better than inconsistent for a ledger.
Show all answers

The candidate applied the conflict rule from the first section directly, which shows that the early requirement was not decoration but a decision tool.

Service and relay failures

Interview Dialogue

CandidateThe transfer API is stateless, so instances can die freely; any in flight transaction either committed or rolled back, and the client retries. If the outbox relay fails, events pile up in the outbox table but none are lost; when it restarts it continues from the last sent row. Downstream systems see a delay, not missing data. If a consumer fails, it resumes from its offset in the event stream and deduplicates by transfer id.

Every failure is described in terms of what is delayed and what is preserved. For a ledger, the important message is that no failure loses or duplicates money; at worst, it delays it.

Reconciliation

Interview Dialogue

CandidateThe ledger is only correct if it agrees with the outside world. Every day, banks and card processors send settlement files listing the money they actually moved. A reconciliation job matches each external record with a ledger transfer by reference, and compares totals per account and per day.
CandidateMost records match. Mismatches fall into a few kinds: a transfer in the ledger that the bank never settled, one the bank settled that the ledger never recorded, or an amount difference. Each mismatch becomes a case for the operations team, and fixes are made with new correcting transfers, never by editing entries.
CandidateInternally, the same job checks that all entries sum to zero and that balances match the sum of their entries.
Reconciliation compares the ledger with the outside world.

Reconciliation is the part of payments design that many candidates forget, and it is often the one interviewers at payments companies care about most. The candidate explained what is compared, what kinds of mismatches occur and how they are fixed in a way that preserves auditability.

The trade offs

Interview Dialogue

CandidateThe main trade offs are three. First, correctness over availability: a few seconds of failed transfers during failover rather than any risk of inconsistency. Second, distributed SQL transactions over custom cross partition logic: a little more latency per transfer in exchange for atomicity we do not have to build. Third, sub accounts for hot merchants: slightly more complex balance reads in exchange for removing the single row bottleneck.

Extensions

Interview Dialogue

CandidateWith more time, I would look at multiple currencies, where each currency is its own set of balances and conversion is a transfer through a currency exchange account; holds and authorisations, where money is reserved before capture, modelled as a transfer to a pending account; and regional deployment for data residency, keeping each region's accounts in that region.

Each extension is described as a reuse of the existing model, which shows that the design was built on the right abstraction.

The close

Interview Dialogue

CandidateTo summarise: every movement of money is a transfer recorded as double entry entries that sum to zero, in one transaction with balance updates, an idempotency key and an outbox row. That makes money conserved, transfers apply at most once and user balances never go negative. The database replicates synchronously and chooses unavailability over inconsistency. Events leave through an outbox, so they match the ledger exactly. Hot merchants use sub accounts. And daily reconciliation checks the ledger against the banks and against itself.
InterviewerClick to reveal answer
Show all answers

Looking back at the session

The time split was roughly seven minutes on requirements and numbers, seven on the API and data model, eight on the high level design, fourteen on the deep dive and eight on failures, reconciliation and the close. The data model took a little longer than in the other walkthroughs because, for a ledger, it carries most of the design.

What made it strong

The candidate broke correctness into checkable properties and mapped each to a mechanism. The data model made auditability and conservation properties of the system rather than promises. The high level design kept atomicity in proven infrastructure and avoided dual writes. The deep dive handled the concurrent retry and hot accounts with reasons for safety. The failure discussion applied the correctness rule consistently, and reconciliation closed the loop with the outside world.

Common mistakes on this problem

Common mistakes include storing only balances with no entries, using floating point amounts, updating a balance and publishing an event as two separate writes, retrying transfers without idempotency keys, ignoring hot accounts, building a custom two phase commit and forgetting reconciliation altogether. Each one is a real source of incidents in production payment systems, which is why interviewers probe for them.

Closing the course

This walkthrough ends the course. Across the three walkthroughs, the problems were very different, a flash sale, a live editor and a ledger, but the shape of each session was the same: scope tightly, let the numbers name the hard part, define the interface and data, draw a design with reasons, go deep where the difficulty lives, cover failures in terms of what users experience and close with the trade offs. That shape is the framework, and with practice it becomes the natural way to run any system design interview.

Monitoring

A few signals tell the team the ledger is healthy: transfer success and error rates by reason, transaction latency, lock waits on the hottest accounts, outbox lag between commit and publish, the age of the oldest unsent outbox row and, most important, the results of the internal invariant checks and reconciliation. A non zero ledger sum or a balance mismatch is a top priority alert, because it means money has been created or destroyed somewhere.

Questions the interviewer might still ask

How would you support a hold, as when a hotel reserves money before charging? Record a transfer from the user to a holds account; capture is a transfer from holds to the merchant, and release is a transfer back. How would you produce monthly statements? Read entries by account and month, which the index already supports, and store the generated statement. How would you handle a merchant disputing a payment? A dispute is a transfer from the merchant to a disputes account, reversed if the merchant wins. Each answer reuses the transfer as the single primitive, which is the clearest evidence that the model is right.

Practising this walkthrough

Try the problem yourself without the dialogue, then compare. Check whether you split correctness into properties, whether you avoided a dual write and whether you remembered reconciliation. Then try a variation, such as multiple currencies or holds before capture, and see how much of the model carries over unchanged. If the answer is almost all of it, the model is right.

One last habit

Notice that in every walkthrough the candidate checked in after the high level design, summarised the deep dive and closed with the trade offs. Those small habits make a session easy to follow and easy to score, whatever the problem.

Reconciliation closes the loop

A ledger can be internally consistent and still wrong about the world. Daily reconciliation against bank and processor settlement files, plus internal checks that entries sum to zero and balances match entries, is how real payment systems catch the errors no design fully prevents.