Design an Idempotent Ledger Service
Design an append-only balanced ledger whose posting API returns one durable outcome across retries, races, and lost responses.
Problem statement
For this exercise, assume authenticated internal clients post immutable single-currency transfers. Each accepted transfer creates balanced debit and credit entries, exposes transaction status, and updates account balance and ordered history.
Every posting request carries an idempotency key scoped to the authenticated client and retained for 30 days. An identical retry must return the original transaction and outcome; reuse with a different canonical request fingerprint must conflict.
Committed entries are never edited or deleted, every transaction balances to zero within one currency, and corrections use linked reversing transactions. Currency conversion, external processor or bank settlement, fraud scoring, credit limits, interest, disputes, and customer-facing statements are outside scope.
What to build
- For this exercise, an authorized client can idempotently post one balanced single-currency transfer and receive a stable transaction ID and durable outcome.
- For this exercise, a client can recover a committed, rejected, conflicting, pending, or unknown posting outcome after retries or a lost response.
- For this exercise, an authorized client can read an account's balance and cursor-paginated immutable entry history with an as-of ledger position.
- For this exercise, an authorized client can idempotently create one linked reversing transaction without changing the original entries.
At scale
- For this exercise, assume 50 million accounts and peaks of 20,000 posting requests and 200,000 balance or history reads per second.
- For this exercise, target 500 milliseconds p95 for a healthy durable posting outcome and 200 milliseconds p95 for a healthy balance or first-history-page read.
- For this exercise, assume a small number of accounts are hot and may receive thousands of concurrent posting attempts per second.
- For this exercise, retain ledger entries and audit evidence for seven years, keep committed postings available through a single-zone failure, and allow derived balances or indexes to rebuild from immutable entries.