Cover art for the article Event sourced ledger design for payment platforms

Event sourced ledger design for payment platforms

Mutable balance rows cannot say which request moved the money. An append-only, double-entry ledger can, and it answers audit questions from data it already holds.

Engineering NOVEMBER 15, 2026

A payout request retried after a gateway timeout can leave the bank with two transfers and the ledger with one debit. When the balance lives in a single row that each update overwrites, no record shows which request moved the money or why the two systems disagree.

That gap gets expensive under load. In a January 2026 TechRxiv preprint on capital enforcement in financial transaction systems, an optimistic-locking balance implementation accepted $609,300 of orders against $100,000 of available capital, an over-commitment of 509.3 percent. An append-only ledger tested under the same concurrent load recorded zero false acceptances.

A balance stored as a mutable row is the simplest design that works, until a client retries, a downstream call fails halfway, or an auditor asks how an account reached its current value. At that point the system reports the balance and cannot reliably report what happened. An event-sourced, double-entry ledger records every movement of money as an immutable fact and derives balances from those facts. It costs more to build, and the cost lands in the first quarter, but every question that arrives after launch is answered from data the system already holds.

Why mutable balances fail under retries, partial failures and audits

A mutable balance design has one accounts table with a balance column, and each payment runs a read, a check and a write. The sequence works when requests arrive one at a time. Under concurrency, two requests read the same balance and both pass the sufficiency check. Both then write, and the second overwrites or compounds the first, depending on how the update is expressed.

Optimistic locking adds a version number and rejects the second write, which closes the lost update. It does not close the gap between the check and the write when the two run as separate steps, or when retry logic re-applies a write without re-running the check against fresh state. That class of defect is a time-of-check to time-of-use race. The preprint above tested for it directly, along with retry storms and cancel-and-execute races, and the optimistic-locking baseline over-committed under each.

Retries and partial failures create a second class of defects. Message brokers and webhook senders deliver at least once, so every consumer eventually sees a duplicate. A mutable design that applies each delivery as a new update credits an account twice unless every code path remembers what it has already processed. A partial failure does more damage, since a debit that commits while the matching credit fails leaves money that exists in no account.

The audit question has no stored answer

A balance column records the present. An in-place update destroys the information needed to explain how a value came to be. Teams compensate with audit tables, change-data-capture streams and application logs, and each of those is a second system that can disagree with the first.

You can put a price on that disagreement with your own numbers. Multiply the reconciliation breaks per month by the engineer-days spent on each, then by your loaded daily rate. The result is the monthly cost of reconstructing facts that a ledger of immutable entries would have kept in order, and it grows with transaction volume and with every external processor you add.

Regulators and bank partners ask the same question

Regulators and bank partners ask for an explanation of every movement of funds, with a reference to the original instruction. A system that stores only current balances answers by assembling history from logs that were never designed as records of account. Marketplaces holding seller balances and wallets holding stored value face this question during partner onboarding and again at every audit.

What an event-sourced double-entry ledger consists of

The design has four parts. Commands express intent, such as “pay out $4,200 to seller 118”. The write side validates a command against current state and appends events that record what occurred. The events are immutable and ordered, and every balance, statement and report is a projection computed from them.

Flow from command through validation to appended events, then to balance and statement projections. Click to expand
A command is validated against current state and appended as events that feed projections.

The double-entry rule sits on top. Each financial event produces entries that debit one or more accounts and credit others, and the entries of a transaction sum to zero. Event sourcing keeps the full history of money movements, and double entry keeps that history internally consistent. Together they give a ledger that can prove its own arithmetic at any point in time.

TransactionPosted
  transaction_id   txn_01HZX4
  idempotency_key  payout-118-2026-03-02
  currency         USD
  entries
    DEBIT   seller_118_payable      420000
    CREDIT  platform_cash_clearing  420000
  posted_at        2026-03-02T14:07:11Z
  correlation_id   payout_request_7731

Amounts are integers in minor units, here 420000 cents, so no floating-point rounding occurs on the write path. Store the currency with every amount, and remember that minor units differ by currency, with zero decimal places for JPY and three for KWD. A transaction in two currencies posts a balanced entry set in each currency through a conversion account. The zero-sum rule then holds per currency, and foreign exchange gains and losses appear as entries.

Six gates a ledger must pass before it holds customer funds

Score any ledger design against these six gates, whether it is a proposal or a system in production. A ledger that fails a gate carries a known class of defect, and the table shows the test that exposes it.

Six ledger gates scored in turn, from balanced transactions to replayable history, then a single decision between holding funds and hardening first. Click to expand
Score every gate, then hold customer funds only when all six pass.
GateTestPass condition
1. Balanced transactionsPost a transaction whose entries do not sum to zeroThe write is refused before any entry is stored
2. Immutable entriesAttempt to update or delete a stored entryThe database role cannot, and corrections arrive as reversals
3. Idempotent commandsSend the same command ten times, concurrentlyOne transaction exists and nine responses return the original result
4. Serialized account writesRun 50 concurrent writers against one accountNo overdraft, no lost update, every conflict retried or refused cleanly
5. External reconciliationCompare ledger, processor report and bank statementEvery difference is classified within one business day
6. Replayable historyRebuild every balance from the first eventThe rebuilt balances equal the live ones to the cent

Gate 1, balanced transactions

The write path rejects any transaction whose entries do not sum to zero within each currency. Enforce the invariant twice, in the domain code and in the database, for example with a deferred constraint trigger in PostgreSQL that checks the sum at commit. Because every transaction balances, the sum of all entries per currency is zero at all times. Operations gets one query that runs continuously and alerts on any deviation.

Gate 2, immutable entries with reversals

Entries are never updated or deleted. A mistake is corrected by posting a reversing transaction that references the original, followed by a corrected transaction. The application database role holds INSERT and SELECT privileges only on the entry tables, so the database enforces immutability even when the code has a bug.

The history grows longer than an edited row would, and every step of it stays readable. An auditor reading the account sees the original error, the moment it was found and the correction, each with its own timestamp and author.

Gate 3, idempotency across transport and business layers

Delivery is at least once, so every command carries an idempotency key. Stripe’s API documents the same contract, where a retried request with the same key returns the stored result of the first attempt. The ledger stores the key in the same database transaction as the entries it produced. A unique constraint on the key turns a duplicate into a lookup, so the caller receives the original result and no second movement of money occurs.

Use two layers. The idempotency key protects the transport, and a business identifier, such as the payout request ID, protects the money movement with its own unique constraint. A client that generates a fresh key on every retry still cannot produce a second payout for the same request. Both layers are required because they fail independently.

Gate 4, serialized writes per account

Each account has an ordered stream of events, and a write names the version it expects to append after. If another writer has appended first, the write fails with a version conflict, and the server reloads the account and retries. The sufficiency check runs inside the same load, decide and append cycle, after the version is known, so no other writer can slip between the check and the write.

A relational ledger can get the same guarantee from the database. Lock the account row with SELECT … FOR UPDATE, or run the posting under PostgreSQL’s SERIALIZABLE isolation level, which aborts conflicting transactions with SQLSTATE 40001. The application must retry those aborts, because the database documents them as expected behavior under that level. Either route works if the check and the write share one transaction.

Hot accounts break naive conflict handling

Hot accounts expose the limits of per-account versioning. Every write to a hot account competes for the same version number, so under concurrent load most rejections are conflicts on commands that were valid, and clients that retry without backoff add to the contention they are reacting to.

Platform fee accounts, clearing accounts and large merchants receive a share of every transaction, so they run hot from launch. A design that holds at 5 writes per second per account can fail at 50. Split these accounts into sub-accounts that are summed on read, or route their commands through an explicit per-account queue. Load test with 90 percent of writes aimed at 5 percent of accounts before release.

Gate 5, reconciliation against external truth

The ledger records what the platform believes happened. Processors and banks hold their own records, and the three must agree. A three-way match compares the internal ledger, the processor’s settlement report and the bank statement, then classifies each difference as timing, fee, dispute, missing entry or error.

Stripe runs this discipline at its own scale. Its engineering team describes Ledger, an immutable log that serves as the system of record for its money movement, where each fund flow is checked for whether it cleared, whether its data arrived on time and whether the representation is complete. The same questions apply to a platform with one processor and one bank.

Reconciliation is a consumer of the event stream, and it posts its findings as entries. A suspense-account transaction records funds a processor reports before the ledger has them, and a clearing transaction closes the item when the matching report arrives. A platform paying out daily should classify every break within one business day. Automate the match from the start, because breaks that wait a quarter lose their causes.

Gate 6, replayable history and versioned events

Replaying every event from the start must reproduce the live balances exactly. This is the strongest test of the whole design, since it proves that projections contain nothing the events do not. Run it nightly in staging against a copy of production events, and treat any difference as a production defect.

Events live for years, so their schemas change. Each event carries a version, and readers upgrade old versions on read, a technique called upcasting, which leaves stored events untouched. A contract test suite that replays a sample of historical events through the current code catches incompatible changes before release. Rewriting stored events during a schema change destroys the property the ledger exists to provide, and it fails this gate.

Read performance, projections and the cost of the design

Reads are served from projections, which are tables or caches built by consumers of the event stream. A balance projection holds one row per account and updates as events arrive. Statements, daily position reports and dashboards are separate projections, each shaped for its query.

Two mechanisms keep the system fast and correct. Snapshots store the state of an account at a given version, so loading an account replays only the events since. The transactional outbox writes the event and a message record in one database transaction, and a relay publishes the message to the broker. This removes the dual-write failure in which the commit succeeds and the publish does not, leaving projections permanently behind.

Eventual consistency is a product decision

Projections trail the write side by the polling or streaming delay. A read that arrives before the projection catches up can miss a record the client wrote moments earlier, and a shorter outbox poll interval narrows that window without closing it. A payout screen that shows a balance a few hundred milliseconds old is acceptable. A withdrawal check that uses one is unsafe, so checks that decide whether money may move read from the write side, and display screens read from projections.

A projection is never the source of truth. When one is wrong, correct the events by posting a reversal and a replacement, then rebuild the projection. Editing the row either gets overwritten by the next replay or leaves the projection disagreeing with the events.

Throughput meets payment latency requirements

A common concern is that event sourcing runs slower than a CRUD design. A COMSNETS 2026 benchmark of a Kafka-based event-sourcing architecture against a CRUD implementation ran on a dataset of 50,000 banking events, which generated over 150,000 persistent state transitions. The event-sourced system sustained 105.4 events per second, 2.69 times the CRUD baseline, with consistent low-latency reads.

The append-only ledger in the TechRxiv preprint recorded a median order latency of 9.39 milliseconds and a p99 of 33.70 milliseconds. Each result comes from one study on one workload, so benchmark your own before you commit.

Where the cost sits

The costs are engineering time, operational surface and the learning curve. The ledger needs a team that understands streams, versioning and projections, and it adds a broker, relay processes and replay tooling. The table shows where each design fits.

SituationRecommendation
Stored balances only, low volume, no external processors, no audit obligationA mutable balance with an audit table is adequate
Wallets, credits or payouts with retries and one processorAppend-only double-entry ledger, with projections in the primary database
Multiple processors, banks or currencies, or a regulated activityEvent-sourced ledger with full reconciliation and replay testing
Sustained high write concentration on a few accountsEvent-sourced ledger plus sub-account sharding or per-account command queues
Existing mutable system in production with open reconciliation breaksRun the ledger in shadow mode first, then migrate account by account

A 45-day plan for building or migrating to a ledger

The plan below is a planning baseline for a team of three to four engineers with an existing payments flow. Durations shift with the number of money-movement types and external integrations.

Four phase sequence from defining accounts to building the write path, shadowing live traffic, reconciling and replaying, then migrating accounts in cohorts. Click to expand
The plan moves from specification to write path, shadow mode and a cohort cutover.

Days 1 to 10, define accounts, events and invariants

List every type of money movement the product performs, including deposits, payouts, refunds, fees, chargebacks and adjustments. For each one, write the debit and credit entries it produces, and agree a chart of accounts with finance. Fix the currency and minor-unit conventions, the idempotency key format and the event naming and versioning rules.

The output is a written specification that finance and engineering have both signed. It includes the invariants from the six gates, each expressed as a test that runs in the continuous integration pipeline. Record financial facts as events, such as a transaction posted, a reversal posted and a settlement matched. Keep request and workflow events in a separate stream, because events that mirror API calls change whenever the API does.

Days 11 to 25, build the write path

Implement the command handlers, the event store with expected-version appends, the idempotency table and the outbox. Apply database permissions so the application role cannot modify entries. Build the retry loop with a bounded number of attempts and a small randomized delay, and let domain errors such as insufficient funds return immediately.

Write the concurrency tests in this phase. Run 20 to 50 concurrent writers against a single account, replay retry storms and test cancel-and-execute races. These are the cases where the mutable designs in the preprint failed.

Days 26 to 35, build projections and shadow the live system

Build the balance projection and the first statement projection from the event stream. Mirror production traffic into the ledger, so every payment the live system processes is also posted as events while the ledger controls no money. Compare ledger balances with live balances daily and record each difference with a cause.

The shadow period exposes the movements the specification missed, such as manual adjustments by support staff or processor fees that arrive in a separate file. Each one becomes a new event type with its own entries.

Days 36 to 45, reconcile, replay and cut over

Connect the processor settlement files and bank statements, and run the three-way match against the shadowed data. Run the full replay test and confirm balances equal live values to the cent. Migrate accounts in cohorts, starting with internal and low-value accounts, and keep the old system read-only for a defined period.

Opening balances enter the ledger as one balanced transaction per account against an opening-balance account, with a reference to the last statement of the old system. This preserves the zero-sum invariant from the first entry.

Failure modes that show up after launch

Most ledger incidents after launch come from a short list. Each one maps back to a gate, so each gate belongs in the test suite as an automated check.

A projection is used for an authorization decision, and two withdrawals pass against a stale balance. The fix is gate 4 discipline, with every money-moving check reading the write side. A support tool gains a direct UPDATE on a balance table to fix a customer complaint, and the next replay disagrees with production. The fix is gate 2, with the support action becoming a reversal and a corrected transaction.

An event schema changes and an old consumer silently drops a field, so a fee stops posting. The contract tests in gate 6 catch this before release. A processor changes its settlement file format, and breaks accumulate unclassified for weeks. Gate 5 needs an alert on the count and age of unclassified breaks, owned by a named person.

Score your system before the next audit request

Score the current system against each gate, marking each as pass, partial or fail. Mutable-balance systems typically fail gates 2, 3 and 6 and partially meet gate 4 where optimistic locking exists. The scores show whether the right step is a new ledger, a shadow ledger beside the existing system, or hardening of what exists.

Pair the score with the cost of the present design. Count reconciliation breaks per month, the engineer-days spent on each, the duplicate or missing movements found in the last two quarters, and the time taken to answer the last audit or dispute request. Those figures give the business case and the baseline against which the new ledger is judged.

Algorithmic designs and builds production ledgers, payment backends and the data platforms around them, with senior engineers owning the work from architecture through deployment. If your balances live in mutable rows and the next audit or processor integration is on the calendar, send us your ledger schema and start a conversation about scoring it against the six gates.

Have a complex project in mind?Let's talk.

We limit our client roster to keep depth on every engagement. If your project needs senior engineering judgment from the first architectural decision, share it and we'll respond within 48 hours.

Get in touch