The Payments Engineer Playbook

The Payments Engineer Playbook

CQRS Is Just Balances And Records

Ledgers are hard because you're forced to separate reads from writes

Alvaro Duran's avatar
Alvaro Duran
Sep 24, 2025
∙ Paid
Share

It’s been a couple thousand years now; we should’ve nailed ledgers already.

[Synapse] filed for Chapter 11 bankruptcy protection in April 2024. Following the bankruptcy declaration, "tens of thousands of U.S. businesses and consumers" lost access to Synapse's services, leaving questions as to the location of funds. In May 2024, former FDIC Chair Jelena McWilliams, appointed as bankruptcy trustee, said there was a shortfall between Synapse’s records and those of the banks, estimated at $65 million to $96 million.

— Synapse Financial Technologies

Ledgers aren’t complicated because they’re conceptually difficult. Otherwise, the Medicis would’ve never grown rich and sponsored the works of Boticelli and Michelangelo.

Ledgers are hard because our world has made them harder.

In Renaissance-era Florence, the Medici family was able to grow rich, first from textile trade, then from banking, using paper-based ledgers. Money was physical. Records weren’t even typed; they were handwritten.

But since ERMA, money has evaporated. We’ve abstracted what it means to have money into a pile of transactions acknowledged by those companies we call “financial”. There is no need for coins and notes; all that matters is that someone inputs the right amount under your name.

Say what you want about this system, but one thing is undisputable: money moves so much faster.

This means that we create records way more often than we used to, while at the same time we’re way more preoccupied about our current balances. We need instant pay ins and pay outs, and we need down-to-the-penny, down-to-the-milisecond balance retrieval.

This is a world in which we buy and sell from everywhere, and in which we use dollars, euros and pounds less and less often.

Ledgers are both indispensable and shaky.

As our financial world has begun to spin out faster and faster, we’ve spent more time and energy into making ledgers work at greater precision and at greater scale. But the fundamentals of bookkeeping remain the same:

  • We record any movement of money (both its source and its destination)

  • We display the latest balance, on demand, with speed and accuracy

The hard thing about these two is that getting good at one comes at the expense of the other.

Naive engineers keep track of balances:

The very first thing that many engineers do when they want to track money is to do that within their domain models. I call that the balance as property approach: when the Order has a price attribute, or when the expenses table has an amount column, you’re doing exactly that.

Like many bad designs, this approach works best when you’re starting out. It lets you go fast. But, over time, reporting becomes more sophisticated and slow, and payment processing and analysis becomes more difficult.

If your overnight report job takes multiple hours to run, using the balance as property approach is probably the underlying cause.

Engineers Do Not Get To Make Startup Mistakes When They Build Ledgers

Engineers Do Not Get To Make Startup Mistakes When They Build Ledgers

Alvaro Duran
·
September 11, 2024
Read full story

Smarter engineers keep track of records. But the cost is straightforward: calculating the current balance is an O(n) operation. And, as records pile up over time, displaying the latest balance on demand turns harder, and harder.

Naturally, we’ve developed a technique to tackle this very problem, called Command Query Responsibility Segregation.

This article will cover exactly that. So let’s dive in.

Keep reading with a 7-day free trial

Subscribe to The Payments Engineer Playbook to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Alvaro Duran Barata
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture