Financial infrastructure
Fintech Ledger Engine
A money ledger built so balances stay exact even when two transfers happen at the same instant.
- Role
- Systems design, implementation, concurrency testing
- Stack
- TypeScriptPostgreSQLZodDockerVitest
- The problem
- Most simple apps store an account balance as a single number and change it with basic code. When two transfers hit at the exact same millisecond, they both read the old number and overwrite each other. No error pops up, but money vanishes into thin air.
- The constraint
- Balances must be 100% exact down to the last cent. Transfers running at the same second must never freeze the database. Different customer accounts share one database without data mixing.
- The approach
- I built a double-entry ledger in PostgreSQL. Account balances are never stored as loose numbers: they are calculated by adding up every credit and debit, which must balance to zero. Money is stored as whole integers (cents), never decimals. I lock rows in a fixed order so simultaneous payments can never freeze each other.
- The result
- Atomic transfers that either succeed 100% or roll back completely. Passes strict automated tests for simultaneous payments and high-traffic account contention.
The problem it solves
Storing an account balance as a single editable number is dangerous. When two people send money at the exact same moment, one update overwrites the other with no error log. Using computer decimals also creates tiny rounding bugs that cause accounts to lose pennies over time.
What is interesting here
Balances are calculated from the ledger, never typed in. Every transfer creates two permanent records: one debit and one credit. A user balance is simply the total sum of their records. Because there is only one source of truth, numbers can never silently wander away from real transaction history.
Money is always whole numbers, never decimals. Computers make rounding mistakes with
decimals (in JavaScript, 0.1 + 0.2 equals 0.30000000000000004). In this engine,
10 dollars is stored as 1000 cents. Rounding errors are impossible by design.
Simultaneous payments cannot freeze the database. When two transfers touch the same accounts at once, the engine locks rows in a strict, predictable order based on account IDs. This stops database deadlocks where two tasks get stuck waiting on each other forever.
Crashes never leave half-finished transfers. Every transfer happens inside a database transaction. If the server loses power or a network drops halfway through, the whole transfer rolls back clean. You never get a debit without a matching credit.
Tested under heavy concurrency. Tested with Vitest against simulated attacks: interleaved transfers, multiple clients hitting one account at once, and sudden failures during money movement.
Who this is for
This is backend engineering where mistakes cost real money. If you are hiring for backend, payments, or high-reliability systems, review the code on GitHub to see how concurrency is handled.
Need something like this?
I build web products and the backend systems underneath them, from first commit to live production. Tell me what you are trying to do.