Part 11 · 1 chapters · ~8 min

Capstone: The Ledger API in Rust

The shared ledger capstone in Rust with Axum, sqlx and Tokio: newtypes for money and ids, a typestate payout machine, idempotent transfers, compile-time checked SQL, proptest invariants, criterion benchmarks and a flame graph, compared with the Go and Java implementations.

15

The build

code
ledger-rust/   (a cargo workspace)
  crates/domain/     Kobo, AccountId newtypes; Payout<S> typestate; LedgerError (thiserror); no IO
  crates/store/      sqlx queries (compile-time checked); post_entry: transaction, FOR UPDATE ordered by id, balanced check
  crates/api/        Axum router, extractors, ApiError → problem details, Idempotency-Key handling
  crates/worker/     payout submission and enquiry with tokio::time::timeout → unknown state
  tests/             100 concurrent identical requests → one entry (tokio::test, testcontainers)
                     proptest: Σ postings = 0 after random operation sequences
  benches/           criterion: posting throughput; cargo flamegraph of the hot path
acceptance: identical to every language course (Go course part 10); compare binary size, RSS at idle and p99 under load