Scaling a High-Throughput Financial Ledger: Architecture Trade-offs
System DesignModel answerLast updated
Design a transaction ledger handling 50k TPS with ACID guarantees, choosing between monolith and microservices and between sharding and replication.
Scenario
You have just joined a fintech company as a senior engineer. The company is building a new transaction ledger from scratch — a core system that records every movement of funds across millions of accounts.
The requirements are tight:
- Throughput: the system must sustain 50,000 transactions per second at peak load
- Consistency: every transfer must satisfy full ACID guarantees — partial or phantom updates are never acceptable
- Growth: ledger data is expected to accumulate at several terabytes per month as the customer base expands
Engineering leadership is split on approach. One camp wants a monolithic architecture to ship quickly and keep operations simple. Another wants a microservices-based design for independent deployability and team autonomy. Neither camp has settled on a database scaling strategy.
You have been asked to lead the architecture decision.
What you are expected to address
1. Monolith vs. microservices for this specific system Compare the two approaches in the context of a high-throughput financial ledger. What are the concrete risks of adopting microservices when the system must maintain strong consistency at every step?
2. Database scaling strategy Should you scale writes through horizontal sharding, or scale reads through replication? Walk through the trade-offs of each in terms of the 50k TPS requirement and the expected data growth. Propose a concrete strategy.
3. Cross-shard atomicity If you adopt sharding, how do you handle a transfer where the sender's account lives on one shard and the receiver's account lives on another? Describe at least two approaches and explain when you would use each.
Your answer should demonstrate not just knowledge of the options, but sound judgment about which choices fit this specific context — and why.
Hints
Hint 1
Start by stress-testing the 50k TPS number. Is that peak or sustained? Back-of-envelope the actual write rate and check whether a single database primary can absorb it — that conclusion determines whether you even need sharding.
Hint 2
For the monolith vs. microservices question, resist the reflex to say 'microservices are better for scale.' Ask what property you lose the moment you split the ledger core across service boundaries, and whether there is a way to get deployment agility without giving that property up.
Hint 3
For cross-shard atomicity, think about what invariant must hold regardless of failure: money is neither created nor destroyed. There are at least three mechanical ways to enforce that invariant across shard boundaries — one avoids the problem entirely, one uses distributed locking, one uses compensating steps. Name the failure mode and mitigation for each.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
How to approach this
The question is fundamentally about consistency. Every architecture and scaling decision you make should trace back to one invariant: money is never created or destroyed, and no account balance can go below its permitted floor. State that invariant out loud before drawing a single box.
1. Nail the numbers first
Before choosing any architecture, do the math.
"Several terabytes per month" is roughly 100 GB per day. A single ledger transaction involves at minimum two double-entry postings, an idempotency record, and index updates — call it around 1 KB on disk. That implies about 1,200 TPS sustained on average. The 50k figure is a peak, not a baseline.
A well-tuned PostgreSQL or Oracle primary can handle roughly 10–30k small write transactions per second under ideal conditions. Row-level contention on hot accounts (shared wallets, sweep accounts) pushes that ceiling down. So at 50k TPS with headroom, you will need to distribute writes across multiple primaries. That conclusion is what drives the rest of the design.
2. Monolith vs. microservices
| Dimension | Monolith | Microservices |
|---|---|---|
| ACID scope | One DB transaction, one commit point | Cross-service invariants require 2PC or Sagas |
| Latency | In-process function calls | At least one network hop per service boundary |
| Failure model | Fails as a whole; easy to reason about | Partial failures, retries, message duplication |
| Team autonomy | Coupled releases | Independent deploy and scale |
| Observability | One log, one transaction ID | Requires distributed tracing and reconciliation |
Major risks of microservices for a strongly consistent ledger:
- No single commit point. Splitting Accounts and Ledger into separate services means a transfer can no longer be wrapped in one database transaction. You immediately need a distributed coordination protocol.
- Dual-write bugs. If you write to a database and then publish an event to a message queue, those two writes are not atomic. A crash between them creates inconsistency. The fix is the transactional outbox pattern — write the event as a row in the same database transaction, then relay it asynchronously.
- Sagas allow intermediate visibility. Unlike 2PC, a Saga lets other transactions observe an account in a partially-settled state. You need explicit holds or semantic locks to prevent overdrafts.
- Non-idempotent retries cause double-postings. Every message consumer must be idempotent, keyed by a stable transaction identifier.
- Regulatory incidents are harder to investigate. Each service boundary adds latency and a new failure mode to trace under time pressure.
Recommendation: split by bounded context, not by entity. Keep the ledger core — accounts, balances, and postings — as a single internally modular service that owns its own data. Place surrounding concerns (fraud scoring, notifications, statements, FX rates) as separate services that consume ledger events asynchronously. Scale the core vertically and by data sharding, not by fragmenting its domain logic across services.
This gives agility at the edges and ACID guarantees at the center. It is not a monolith; it is a deliberate boundary decision.
3. Sharding vs. read replication
Read replication copies the primary to N replicas. It scales reads and provides failover — but writes still funnel through one primary. Asynchronous replicas are stale, making them unsafe for the balance check before a debit. Synchronous replicas add commit latency. Use replicas for statements, analytics, and history queries. Never use them for authorization.
Horizontal sharding partitions accounts across independent primaries. Sixteen shards at roughly 5k TPS each gives 80k TPS of write capacity with room to grow. The costs are cross-shard transactions, rebalancing complexity, and operational overhead.
Proposed design:
- Shard key =
account_id, mapped through a lookup table to a fixed set of virtual buckets (e.g., 4,096). Map buckets to physical shards separately. This lets you move buckets between shards during rebalancing without rehashing every account. - Replicate each shard with a synchronous standby for failover and durability, plus asynchronous read replicas for query workloads.
- Tier storage. Keep hot data — current balances and recent postings — in the OLTP shards. Use time-based partitioning within each shard's postings table. Archive cold partitions to columnar or object storage. This is how you absorb terabytes per month without bloating your primary storage tier.
- Enforce idempotency at the database level. Every transfer carries a client-generated
idempotency_keystored under a unique constraint per shard.
4. Cross-shard atomicity
Suppose the sender is on shard 1 and the receiver is on shard 7. You have three real options.
Option A — Avoid the problem. Co-locate accounts that transact with each other frequently (a customer's own sub-accounts, for example) on the same shard. Route those transfers through a single local ACID transaction. No coordination protocol needed. This should be your default wherever it is feasible.
Option B — Saga with a suspense hold. This is how most production payment ledgers work.
- In one local transaction on shard 1: debit the sender and write an outbox row "credit receiver, transaction T."
- A relay delivers the message. Shard 7 credits the receiver idempotently, keyed by T.
- If the credit permanently fails, a compensating reversal is posted on shard 1.
The key invariant: funds move from the sender's account to an explicit in-flight suspense account before shard 7 is touched. Money is conserved at every step; the sender cannot overdraw. The receiver's credit is visible slightly later than the sender's debit — that is an acceptable trade-off for most transfers.
Option C — Two-phase commit. The coordinator sends PREPARE to both shards. Each shard locks the relevant row, validates (sufficient funds, no fraud hold), and durably records its vote. The coordinator then issues COMMIT or ABORT. This is genuinely atomic and isolated, but locks are held across a network round-trip. If the coordinator crashes after PREPARE, both participants are blocked in an uncertain state. Mitigate this by replicating the coordinator log with Raft. Accept roughly 2× commit latency compared to a local transaction. Use this only where the business explicitly requires simultaneous atomic visibility on both sides — regulatory settlement finality, for example.
Summary of choices:
- Option A where accounts can be co-located
- Option B for the majority of cross-shard transfers
- Option C only where strict atomic visibility is a hard requirement and the latency cost is accepted
Common mistakes to avoid
- Recommending microservices as a default without acknowledging what you give up on consistency
- Assuming read replicas solve the 50k TPS write problem
- Designing sharding with
hash % Nas the partition mapping — this makes rebalancing painful - Forgetting idempotency on retry paths, which is how double-postings happen in production
- Treating Sagas as "eventually consistent" in a hand-wavy sense — a well-designed Saga with a suspense account is money-conserving at every intermediate state, not just at the end