Before You Build a Payments Platform, Understand Ledgers

·22 min read
ledgerssoftwareengineering

Why are we talking about ledgers?

When we think about building a payments platform, the first things that usually come to mind are the activities the platform needs to support. We think about deposits, transfers, withdrawals, merchant payments, fees, and settlements. We think about how money moves from one place to another, how quickly transactions can be processed, and how to make these operations reliable as the number of customers increases.

These are important concerns, but there's another question that deserves just as much attention: How does the platform keep track of the financial effects of everything happening within it?

Consider a financial platform that offers digital wallets. Customers can deposit money, transfer funds to other customers, and withdraw money to their bank accounts. As the platform grows, it might introduce merchant payments, transaction fees, and settlement services. Each of these products has its own workflows and business requirements, but they share something fundamental: they all involve financial activities that need to be accurately recorded and accounted for.

For example, when a customer deposits $100 into a wallet, the platform needs to recognize that it has received funds and that it now has an obligation to the customer. When that customer makes a payment, the platform needs to account for the financial effects of that payment. When a merchant is charged a processing fee, the platform needs to record the fee and its impact on the relevant accounts.

These activities may look different from the perspective of the products that initiate them, but from an accounting perspective, they introduce related problems. We need to know which financial positions have changed, by how much, and why. We also need to preserve enough information to explain those changes later.

This is where ledgers become important.

The purpose of this article is to help you understand what a ledger fundamentally is, what it records, how its different concepts relate to one another, and why ledger infrastructure becomes increasingly important as a payments platform grows.

Eventually, I want to you to see how these capabilities can be made reusable across different financial products. But rather than immediately jumping into microservices, database schemas, or distributed architectures, we'll begin with the underlying concepts and gradually develop the model.

What does it mean to facilitate ledgers?

The word facilitate generally means to make something possible, easier, or more effective. When we talk about facilitating transfers, the meaning is relatively straightforward. A transfer is an activity, and facilitating transfers involves providing the mechanisms that allow that activity to be initiated, processed, tracked, and completed.

But a ledger is different. A ledger is not itself a financial activity. It is a system of financial records.

So when we say we're facilitating ledgers, are we talking about making it easier to create ledgers? Are we talking about recording financial activities? Are we talking about managing financial accounts? Or are we talking about providing ledger capabilities that multiple financial products can use?

I have settled on a combination of the last two broader ideas: facilitating financial recording through ledgers and making those capabilities available as reusable financial infrastructure.

Imagine a company that operates a wallet product, a merchant payments product, and a settlement product. Each product has its own business logic. The wallet product manages customer funds, the merchant payments product processes payments, and the settlement product handles obligations to merchants or financial partners.

However, each product also needs reliable financial records.

If every product independently develops its own way of tracking accounts, recording financial movements, and calculating balances, the platform may end up with several different implementations of similar accounting responsibilities.

That creates additional complexity. The products may use different definitions, follow different posting rules, or produce financial records that are difficult to reconcile with one another.

An alternative is to make common ledger capabilities reusable across these products, while still allowing each product to retain its own business-specific logic.

This brings us to our first working definition:

Facilitating ledgers means providing the mechanisms through which financial activities can be consistently recorded, organized, and accounted for across a payments platform.

What is a ledger?

Now that we understand what we're trying to facilitate, we need to define the ledger itself.

A useful starting point is to think of a ledger as an organized record of financial activities and their effects on accounts.

Let's see this as our Definition 1.0; 'cause this definition is going to evolve over the course of this article:

A ledger is an organized record of financial activities and their effects on accounts.

This definition is simple and it establishes that a ledger has something to do with financial activities, accounts, and the records that connect them.

But there are questions hidden inside it.What exactly counts as a financial activity? What is an account? And what does it mean to record the effect of an activity on an account?

Until we understand those concepts, our definition remains incomplete.

One thing worth recognizing immediately is that a ledger is not simply a table of account balances. A balance tells us the financial position of an account at a particular point in time, but it doesn't necessarily explain how that position came about.

Suppose a customer has a wallet balance of $250. Knowing that the balance is $250 is useful, but it doesn't tell us whether the customer deposited $300 and spent $50, received $200 and then another $50, or experienced some other combination of financial activities.

If we want to explain the balance, investigate discrepancies, or reconstruct the account's financial history, we need records of the activities that contributed to it.

A ledger provides the structure for maintaining those records and relating them to accounts.

This doesn't necessarily mean every balance must be calculated from scratch whenever it is requested. A ledger implementation may maintain balances for efficient retrieval. The important point is that those balances should be explainable through the underlying financial records.

Understanding financial activities

Our definition of a ledger refers to financial activities, so let's examine what that means.

A financial activity is an occurrence that creates, changes, settles, or otherwise affects a financial position or obligation.

This definition is broader than simply moving money between two people.

For example, a customer depositing $100 into a wallet is a financial activity. So is a merchant receiving a payment, a platform recognizing a transaction fee, or a business settling an outstanding obligation.

Although these activities may involve different operational processes, they all have financial implications that may need to be recognized in the platform's records.

Consider a merchant payment. A customer might pay $200 for a product, and the platform might charge the merchant a $5 processing fee. The platform needs to account for the amount payable to the merchant, the fee it earns, and potentially the movement of funds through external payment providers.

The customer may see a single $200 payment, but the financial effects of that payment can involve several accounts and obligations.

This illustrates why we shouldn't define financial activities only in terms of customer-to-customer transfers.

There's another important distinction: an activity being requested is not necessarily the same as its financial effects being recognized.

For instance, a customer might initiate a $100 withdrawal. The platform receives the request, but that doesn't automatically mean the withdrawal has been completed. The request may need to be validated, authorized, processed by an external provider, and eventually settled.

Depending on the platform's accounting model, some of those stages may result in financial postings, while others may only change the operational status of the withdrawal.

This distinction will become important when we discuss ledger transactions. A ledger must represent financial effects according to defined accounting rules rather than treating every operational event as a completed movement of money.

Understanding accounts

The second concept in our definition is the account. When software engineers hear the word account, they often think of a user account. A user signs up for an application, receives an account identifier, and can log in to access the platform.

But in the context of a ledger, an account has a different and broader meaning. An account is a distinct record used to classify, track, and determine a particular financial position within a ledger.

That financial position might represent an asset, a liability, revenue, an expense, or another accounting classification. For example, a platform may maintain an account representing the funds it holds at a bank. It may also maintain accounts representing the amounts it owes individual customers. Other accounts might represent revenue earned from processing fees or amounts owed to merchants awaiting settlement.

These are all accounts, even though they don't necessarily correspond to users who can log in to the application.

Let's make this more concrete.

Suppose a customer deposits $100 into a wallet operated by a financial platform. For simplicity, assume the platform receives the money into a bank account it controls and has an obligation to repay or make that amount available to the customer.

From the customer's perspective, the result is straightforward: their wallet balance increases by $100.From the platform's accounting perspective, however, two financial positions have changed.

First, the platform's bank asset has increased by $100 because it now controls additional funds. Second, its liability to the customer has increased by $100 because it now owes the customer that amount.

The same financial activity has therefore affected two different accounts.

This is an important observation because it demonstrates that an account is not simply a container for a customer's money. Accounts are also used to represent the platform's financial relationships and obligations.

The exact accounting treatment depends on the legal and operational arrangements of the platform, but the conceptual lesson remains useful: one financial activity may affect multiple financial positions.

Bringing ledgers, accounts, and financial activities together

Now we can return to our original ledger definition with a better understanding of its components.

A financial activity occurs. That activity may produce financial effects that need to be recognized. Those effects relate to one or more accounts. The ledger organizes and preserves the records of those effects.

Consider the $100 deposit again.

The activity is the customer's deposit. The financial effects are the increase in the platform's bank asset and the increase in its liability to the customer. The accounts are the records used to track those two financial positions.

The ledger provides the structure through which these effects can be recorded and subsequently explained.This relationship reveals something that wasn't explicit in our first definition.

A ledger doesn't merely contain a list of activities. It must also provide a way to connect recognized financial effects to the accounts whose positions they change.

That leads us to Definition 1.1:

A ledger is a structured system of accounts and records that captures the recognized financial effects of activities and allows those effects to be traced to the resulting financial positions.

This definition is more precise than our original one because it emphasizes the relationship between activities, records, and financial positions. However, it still leaves an important question unanswered. If one financial activity affects multiple accounts, how should those effects be represented so that they remain connected and financially consistent?

That question leads us to the next stage of our model.

What exactly does a ledger record?

Let's continue using the $100 customer deposit. We've established that the activity affects two financial positions: the bank asset and the customer liability.

Imagine we build a simple recording system that creates one record for each effect. The first record states that the bank asset increased by $100. The second record states that the customer liability increased by $100. At first, this seems reasonable. We know which accounts changed, and we know the amounts involved.

But suppose we inspect these records several days later. How do we know that both records belong to the same deposit?

One possible solution is to introduce a shared identifier. We could assign the deposit an identifier such as DEP-001 and attach it to both records. Now, whenever we inspect either record, we can identify the activity that produced it and find the related record.

We've improved our model, but we've only solved the problem of associating records but we haven't established whether the records are complete or whether they were saved together.

Imagine that our application saves the first record successfully but crashes before saving the second. Our records would show that the platform's bank asset increased by $100, but they would not show the corresponding increase in the liability to the customer. The financial event would be represented incompletely.

The deeper problem is that we've treated related financial effects as independent changes without establishing the rules governing their relationship. We need a way to represent the entire financial event as one logical unit. This is where ledger transactions become useful.

Stay with me...

Introducing ledger transactions

Now, a ledger transaction is a logical unit that groups the related ledger entries representing the financial effects of an event.

This is our Definition 2.0.

Instead of storing the effects of the $100 deposit as unrelated records, we can create one ledger transaction containing the records associated with that deposit.

For example, we could create a ledger transaction with the identifier TXN-001. That transaction would contain the record affecting the bank asset and the record affecting the customer liability. The important distinction is that the transaction represents the financial event as a whole, while the individual records represent its effects on particular accounts. This separation gives us a more expressive model.

We can now ask questions about the transaction itself. Which financial activity produced it? Which accounts were affected? Which records belong to it? Has the transaction been posted? And do its entries satisfy the accounting rules of the ledger?

However, grouping records into a transaction is not enough to guarantee correctness. A transaction can contain related records and still be financially inconsistent. It could contain incorrect amounts, omit a required record, or fail to commit all its records together.

So although the transaction gives us a logical unit, we still need to define the records inside it and the rules they must follow.

Introducing ledger entries

An individual record within a ledger transaction is called a ledger entry.

Our Definition 2.1 is:

A ledger entry is an individual accounting record that represents a debit or credit to an account as part of a ledger transaction.

This introduces an important distinction between transactions and entries. A ledger transaction groups the related financial effects of an event while a ledger entry records an individual accounting effect on a particular account. Therefore, one ledger transaction can therefore contain multiple entries.

For example, the $100 deposit can be represented by a transaction containing two entries: one associated with the bank asset and another associated with the customer liability.

More complex activities may require more than two entries. A payment involving processing fees, taxes, or settlement obligations may affect several accounts. All the related entries can be grouped into a single ledger transaction when they represent one accounting event.

This is why transactions and entries should not be treated as interchangeable concepts. A transaction provides the logical grouping and entries describe the individual accounting effects.

But we still need a way to determine whether those effects have been represented correctly.

So far, we've described changes using the words increase and decrease. To introduce accounting consistency, we need a more formal representation.

That brings us to debits and credits.

Understanding debits and credits

Debits and credits are fundamental concepts in double-entry accounting. One common source of confusion is assuming that debit always means money leaving an account and credit always means money entering it.

Rather, the meaning of a debit or credit depends on the type of account involved.

For asset accounts, a debit increases the account balance and a credit decreases it. For liability accounts, the relationship is reversed: a credit increases the liability, while a debit decreases it. Revenue and equity accounts generally increase with credits, while expense accounts generally increase with debits.

This becomes clearer when we return to our deposit example.

The platform receives $100 into its bank account. Because the bank account represents an asset, we record a debit of $100 to that asset account.

At the same time, the platform's obligation to the customer increases by $100. Because the customer account represents a liability, we record a credit of $100 to that liability account.

Our ledger transaction therefore contains a $100 debit and a $100 credit. The two entries represent different financial effects, but they belong to the same accounting event. And something important has happened: the total amount debited equals the total amount credited.

This is the fundamental balancing principle of double-entry accounting.

Plain text
Total Debits=Total Credits

In a balanced ledger transaction, the total debit amount must equal the total credit amount within the relevant accounting context. This principle allows us to detect certain types of incomplete or inconsistent financial postings.

For example, suppose we attempt to record a $100 debit to the bank asset but only a $90 credit to the customer liability. The transaction would not balance. A properly designed double-entry posting system should reject that transaction rather than accept an inconsistent set of entries.

It's important to understand what this rule does and doesn't guarantee. A balanced transaction is not automatically a correct transaction. We could debit and credit the wrong accounts for equal amounts, and the transaction would still balance mathematically.

Balancing establishes a necessary accounting constraint, but the ledger also needs appropriate business rules, account validation, and posting controls.

What makes a ledger transaction financially consistent?

We've now introduced a transaction, its entries, and the balancing rule.

This leads us to Definition 2.2:

A balanced ledger transaction is a ledger transaction whose debit and credit entries balance according to the accounting rules of the ledger.

This is a meaningful improvement to our model. Instead of merely grouping financial effects, we can now validate that the entries satisfy a fundamental accounting requirement.

But another problem remains. Suppose we construct a perfectly balanced transaction containing two entries. The first entry is saved successfully, but the second fails because of a database error. Even though the transaction was balanced before we attempted to save it, our stored records are now incomplete.

This reveals a distinction between accounting correctness and the technical guarantees required to preserve it. We need the entries to balance, but we also need them to be committed together.

In database and transaction-processing terminology, this requirement is called atomicity.

Atomicity means that a group of related operations is treated as a single indivisible unit: either all the required operations succeed, or none of them take effect.

For our $100 deposit, that means the debit to the bank asset and the credit to the customer liability must be posted together. The ledger should not commit one while leaving the other missing.

This requirement is one of the reasons ledger engineering is more involved than simply storing transaction records. The system must preserve accounting invariants even when software fails, requests are interrupted, or multiple operations occur concurrently.

We'll explore the mechanisms for achieving this in our next stage, but for now, the important lesson is that a financially correct model must be supported by an implementation that preserves its rules.

How our definition of a ledger has evolved

Breathe...

So let's consider how far we've progressed.

  • We began by describing a ledger as an organized record of financial activities and their effects on accounts. That gave us a useful starting point, but it didn't explain the relationship between activities, accounts, and records.
  • We then refined the definition to describe a structured system of accounts and records that captures recognized financial effects and makes them traceable.
  • From there, we discovered that a single financial activity may affect multiple accounts. We needed a way to group those related effects, so we introduced ledger transactions.
  • We then introduced ledger entries to represent the individual accounting effects within a transaction.
  • Finally, we introduced debits, credits, and the balancing principle to establish a fundamental consistency rule.

These discoveries led us to our proposed Definition 2.3:

A ledger is a structured system of accounts and balanced financial transactions, where each transaction consists of entries that record the financial effects of an event.

This definition is more precise than the one we started with.

It tells us that a ledger is not simply a history of activities or a collection of account balances. It is a structured accounting system in which financial events are represented through transactions and entries governed by defined accounting rules.

There is an important qualification: this definition describes the double-entry ledger model we're developing for the presentation. Other ledger models exist, but double-entry accounting gives us a particularly useful foundation for financial infrastructure.

Even this refined definition isn't the end of our journey.

We've established what the ledger should represent, but we haven't yet explained how those records become authoritative, how they are maintained safely, or how they can support many financial products simultaneously.

Those questions will eventually lead us toward ledger infrastructure and scalable system architecture. (In another post).

Why this matters when building a payments platform

At this point, it may be tempting to treat everything we've discussed as accounting theory. But these concepts have direct implications for software architecture.

Consider a payments platform that supports wallets, merchant payments, and settlements. Each product has its own responsibilities. A wallet product may manage customer-facing balances and transfer requests. A merchant payments product may manage payment authorization, capture, and merchant obligations. A settlement product may coordinate payouts to financial partners.

These products may all generate financial effects that need to be recorded. If each product independently implements its own financial recording logic, the platform must maintain multiple systems responsible for accounting correctness.

Each implementation may need to solve similar problems: managing accounts, creating entries, balancing transactions, preventing duplicate postings, maintaining balances, and providing financial histories.

As the number of products grows, maintaining consistency across these separate implementations can become increasingly difficult. This is where our earlier interpretation of facilitating ledgers becomes relevant.

Instead of requiring every financial product to implement its own accounting engine, a platform can provide common ledger capabilities through reusable infrastructure. The products can retain responsibility for their business workflows, while the ledger infrastructure provides mechanisms for recording the resulting financial effects.

For example, a wallet service might determine that a customer transfer is valid and should be processed. The ledger infrastructure would be responsible for recording the appropriate accounting effects according to its rules.

A settlement service might determine that a merchant is owed a particular amount. The ledger infrastructure would record the financial positions and changes associated with that obligation. This separation doesn't mean that every business process can be reduced to a single ledger API call. Payment workflows can involve external providers, asynchronous processing, authorization stages, and other operational concerns.

The ledger's role is to provide reliable financial recording within that larger system.

Why scalability introduces new questions

So far, our examples have been relatively simple. We've discussed individual financial activities and how their effects can be represented through balanced ledger transactions. But payments platform may need to process many financial activities simultaneously.

Suppose an account has an available balance of $100. Two payment requests arrive almost at the same time, each attempting to spend $80. If both requests independently read the $100 balance before either updates it, both might conclude that sufficient funds are available. Without appropriate concurrency controls, the system could allow the account to spend $160 despite having only $100 available.

This is not fundamentally a problem with double-entry accounting. Both payment transactions could be balanced and still violate the platform's rule against overspending. The problem is that balancing entries and enforcing available-balance constraints are different responsibilities. A ledger system must consider both.

Similarly, imagine a payment service sends a ledger posting request, but the network connection fails before the service receives a response. The service doesn't know whether the posting succeeded. If it retries the request, how does the ledger prevent the same financial movement from being recorded twice?

This is where idempotency becomes important. Idempotency allows a system to recognize repeated requests representing the same intended operation and avoid applying the financial effect multiple times.

These are examples of the problems that emerge when we move from a conceptual accounting model toward a production financial system.

Other challenges include maintaining accurate balances under heavy workloads, preserving financial history, handling reversals, recovering from failures, and supporting reconciliation.

Eventually, we must also consider how the ledger's read and write workloads can scale without compromising financial correctness.

Conclusion: The bigger idea we're developing

The central lesson so far is that a ledger is much more than a place to store balances.

A ledger provides a structured way to represent financial activities through accounts, transactions, and entries. It allows us to explain how financial positions change and provides accounting rules that help ensure those changes are recorded consistently.

But the value of a ledger doesn't end with accurate record-keeping.

As a payments platform grows, different financial products begin to encounter similar financial accounting requirements. Wallets, payments, fees, settlements, and other financial operations all need reliable ways to represent and account for their effects.

Rather than treating those requirements as separate problems to solve within every product, we can begin thinking of ledger capabilities as shared financial infrastructure.

That is the larger idea behind this article.

Facilitating ledgers is about making reliable financial accounting capabilities available to the systems that need them, so that a payments platform can grow without every financial product independently reinventing its accounting foundation.

We've established what the ledger needs to represent. Next, we need to understand how it can preserve the correctness of those records when the system is actually operating. This would be in another post.

Subscribe so you don't miss out.

Comments

I’d like to hear your thoughts. No sign in needed.

0 comments

Subscribe

If this resonated with you, join my bi-weekly notes. I share new posts and videos, one thing I'm learning, one inspiring find, and one quote. No spam, unsubscribe anytime.

5 readers received the last newsletter, 2 months ago. Join the fun.