Part 10 · 1 chapters · ~8 min
Capstone: The Ledger API in Go
The shared capstone for every language course: the ledger API from Ledgers part 9 (accounts, balanced postings, idempotent transfers, a payout state machine against a simulated rail) built in Go with Gin, pgx, sqlc and errgroup, with tests, a benchmark and a profile.
16
The build
code
ledger-go/ cmd/ledger/main.go wiring, config, graceful shutdown internal/ledger/post.go PostEntry: balanced check, ordered row locks, funds check, append (one transaction) internal/transfers/http.go Gin handlers with Idempotency-Key, problem responses internal/payouts/machine.go state machine; rail client with success / failure / timeout; enquiry worker internal/db/queries.sql sqlc queries; migrations with goose internal/ledger/post_test.go table-driven tests; testcontainers-go Postgres bench/ go test -bench: transfers per second; pprof the hot path acceptance (identical in every language course, so implementations can be compared) - 100 concurrent identical requests with one key → one entry, one response - Σ postings = 0 per currency after a 10,000-operation fuzz run (go test -fuzz) - a timed-out payout never completes without rail confirmation - report: requests/s at p99 < 50 ms on this machine, binary size, image size, memory at idle