Part 10 · 1 chapters · ~8 min
Capstone: The Ledger API in Rails
The shared ledger capstone in Rails 8: models with constraints, a posting service with ordered locks, idempotent transfers, a payout state machine with Solid Queue jobs and enquiry, Minitest concurrency tests, Bullet and strict loading, rack-mini-profiler measurements, and a Kamal deployment.
11
The build
code
ledger-rails/ app/models/account.rb, journal_entry.rb, posting.rb, payout.rb validations + DB check constraints app/services/ledger/post_entry.rb transaction, ordered lock, balanced check (Σ postings = 0) app/controllers/transfers_controller.rb Idempotency-Key, problem responses app/jobs/submit_payout_job.rb, enquire_payout_job.rb state transitions; unknown on timeout test/integration/idempotency_test.rb threads posting the same key → one entry test/models/invariant_test.rb random operation sequences keep Σ = 0 config/deploy.yml Kamal to two servers acceptance: identical to every language course (Go course part 10); compare lines of code and time to first working version
Rails usually wins on time to a working, secure first version and loses on raw throughput per server; for most products the first matters far more, and YJIT has narrowed the second.