Payments backend in Go: microservices, built from scratch
The code from the YouTube course Build a Production-Grade Payments Backend with Go Microservices. Every line was typed on camera and every decision is explained in the videos.
Follow along: one branch per episode
Each episode ends with a commit, and each episode has its own branch holding the code as it is at the end of that episode. To start an episode where the video starts, check out the previous episode's branch:
git clone https://github.com/dev-marker/payments.git
cd payments
git checkout ep05 # the code at the end of episode 5, where episode 6 begins
main holds the latest episode plus this README.
The Go module is named github.com/fiston-user/payments, as typed in the videos. It's only a name: everything builds and runs from this clone as is.
The system
Six Go services in one module, with one PostgreSQL database per service, talking over HTTP, gRPC and NATS JetStream:
Infrastructure (Docker Compose): PostgreSQL 17, Redis, NATS JetStream, Mailpit, Jaeger, Prometheus and Grafana.
Some rules the code never breaks:
- Money is an
int64 count of minor units (cents), never a float.
- Balances are derived from ledger entries, and every transaction's entries sum to zero per currency.
- Every write that moves money is idempotent, and events leave through a transactional outbox.
Run it
You need Go 1.26, Docker, and make. The golang-migrate, sqlc and buf CLIs are only needed to create migrations or regenerate code.
make keys # throwaway signing keys for local development, in secrets/
docker compose --profile app up -d --build --wait # infrastructure, migrations and all six services
Then open the .http files in api/ with the VS Code REST Client extension and send the requests, starting with api/gateway.http.
To run a single service from source while you work on it, start the infrastructure with docker compose up -d, then make run-wallet (or run-auth, run-transfer, run-notification, run-gateway, run-webhook).
Tests
make test # unit tests only, fast
make test-integration # against real PostgreSQL, Redis and NATS in throwaway containers (needs Docker)
make test-race # the same with the race detector
make loadtest # a k6 load test of transfers through the gateway (the app profile must be running)
License
MIT. This is teaching code: read it, run it, build on it. Treat it as a starting point rather than a drop-in system for moving real money.