All posts
Fintech
4 min read• 10/26/2026

Deterministic Ledgers for Sub-Second Rails: Why Microservices Corrupt Balances

Moving money over instant networks like FedNow and RTP requires rethinking the distributed microservice model. Here is why event-sourced, append-only ledgers are non-negotiable for modern fintech infrastructure.

Share X LinkedIn

Tip: use ← / → to browse posts.

Deterministic Ledgers for Sub-Second Rails: Why Microservices Corrupt Balances
## The Illusion of Two-Phase Commits in Modern Banking When money moved over ACH, engineering teams enjoyed a comfortable buffer. You had days to batch transactions, identify settlement discrepancies, run end-of-day reconciliation scripts, and patch corrupted states with manual journal entries. Modern instant rails like FedNow, RTP, and SEPA Instant eliminate that safety net. Settlement occurs in under two seconds, 24/7/365, with absolute finality. If your architecture relies on distributed microservices updating balances via REST APIs and two-phase commits, you are running on borrowed time. In high-concurrency environments, distributed transactions fall prey to network partitions, out-of-order execution, and optimistic locking retries. These issues cause balance drift, double-spends, and phantom deposits. If two instant transfers hit a ledger simultaneously for an account with a $100 balance, naive locking leads either to thread starvation or illegal overdrafts. To survive modern settlement rails, your core banking layer must abandon mutable record updates. You need a single-writer, deterministic, append-only ledger. ## Core Principles of Immutable Financial Ledgers An enterprise fintech engine must be governed by three foundational rules: * **Balances are Computed Views, Not Source Truth**: You never run an `UPDATE accounts SET balance = balance - 100` statement. A balance is merely the materialized aggregate of every immutable journal entry since account inception. * **Immutable Double-Entry Completeness**: Every movement of value consists of at least one debit and one credit across corresponding internal accounts. The sum of all legs in a financial transaction must equal zero. * **Total Deterministic Ordering**: Transactions must be processed sequentially through a single serialization boundary. This guarantees that balance verification and journal creation occur in a strictly ordered, repeatable sequence. ### The Single-Writer Architecture Instead of letting dozens of microservices write directly to a relational database, funnel all incoming transaction requests through a durable log (such as Apache Kafka or AWS Kinesis) partitioned deterministically by Account ID. A dedicated, in-memory state-machine processor consumes this log. Because a single partition processes operations sequentially, the state machine can validate funds, perform risk checks, and append balanced entries entirely in memory without distributed locks. ```sql -- The only balance-altering table needed in your ledger core CREATE TABLE ledger_entries ( entry_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), transaction_id UUID NOT NULL, account_id UUID NOT NULL, direction VARCHAR(2) NOT NULL CHECK (direction IN ('DB', 'CR')), amount NUMERIC(18, 4) NOT NULL CHECK (amount > 0), currency VARCHAR(3) NOT NULL, sequence_number BIGINT NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(), CONSTRAINT unique_account_sequence UNIQUE (account_id, sequence_number), CONSTRAINT zero_sum_check_marker FOREIGN KEY (transaction_id) REFERENCES transactions(id) ); CREATE INDEX idx_ledger_account_seq ON ledger_entries (account_id, sequence_number DESC); ``` ## Handling Instant Rail State Machines Instant payment networks introduce complex state machines. A transfer is not merely "successful" or "failed"; it occupies transitional states such as `PENDING_SETTLEMENT`, `ACCEPTED_TECHNICAL`, and `SETTLED`. Misinterpreting these states can lock up liquidity or expose your system to unrecoverable losses. ### The Ledger Hold Pattern Never subtract funds directly when a payment is initiated. Instead, execute a two-step balanced hold: 1. **Authorization Phase**: Debit the customer’s available balance and credit an internal liability hold account (`Liability:Customer:Holds`). The customer's total balance remains unchanged, but their available spendable balance drops instantly. 2. **Settlement Phase (RTP ACK received)**: Debit the internal liability hold account and credit the central bank clearing account (`Asset:Settlement:FedNow`). 3. **Failure Phase (RTP NACK received)**: Reverse the initial hold by crediting the customer’s available balance and debiting the liability hold account. By keeping every state transition within the double-entry boundary, your internal accounts always reconcile with the external central bank settlement account, down to the cent. ## Real-Time Snapshotting and Cache Hydration Calculating account balances by summing millions of rows on every request does not scale. The solution is not reverting to mutable balances, but generating deterministic snapshots. After every *N* transactions (e.g., every 100 entries), the ledger engine emits a snapshot record storing the balance and the latest processed `sequence_number`. When an account balance query arrives: * Fetch the latest snapshot from an in-memory cache (Redis or local memory). * Query only the entries appended *after* that snapshot’s sequence number. * Sum the difference and return the verified balance. If the cache crashes or loses state, it can be rehydrated from zero by replaying historical entries from the append-only table. The database log serves as the absolute source of truth. ## Stop Outsourcing Ledger Correctness Trying to solve financial discrepancies through distributed caching and retroactive cron reconciliation creates brittle systems that break under load. When an instant network confirms a transfer, that money is gone; you cannot roll back an HTTP request once settlement clears. By enforcing deterministic append-only ledgers and managing balance holds explicitly, your system remains robust under high load, ensuring every cent is accounted for.
fintech
distributed-systems
event-sourcing
database
rails
Share X LinkedIn

What clients say

Real reviews from founders and teams we've shipped with.

5.0 · 6 reviews
"The trading store is fast, secure, and converts. Hashim genuinely understands fintech."
Daniel O.
CEO, FX TradeStore
"ChatGPT, GPT-5.5 and Codex integrations shipped clean — Hashim wired our copilots end-to-end with production-grade guardrails."
OpenAI Integration
ChatGPT · GPT-5.5 · Codex · Sora · DALL·E
"Traffic, retention, monetization — every metric moved after the redesign. Highly recommend."
Alex W.
Founder, RobloxWAP
"Design, engineering, growth — Hashim's team owned every layer. We finally look enterprise."
Arjun P.
COO, Bangalore Stays
"Our Next → TanStack migration cut TTFB in half. Hashim's diagnosis was surgical."
Lena K.
Staff Engineer, Northloop
"GitHub Actions, preview environments, semantic releases — the DX Hashim set up is chef's kiss."
Julian F.
Platform Engineer, Codewave