CQRS in Go — Part 2: side-effect-free command handlers
The Handle(ctx, state, cmd) (Events, error) signature makes handlers testable without mocks, without DB, without Docker. The secret: zero side effects.
Lessons learned, problems and solutions
The Handle(ctx, state, cmd) (Events, error) signature makes handlers testable without mocks, without DB, without Docker. The secret: zero side effects.
How to structure a CQRS aggregate in Go: value struct, Transition() returning a new state, mandatory Clone() for collections. The shared slice trap.
Idempotent commands with idempotency key, optimistic locking on aggregates, idempotent projections and outbox pattern. The 4 idempotency layers of a production Event Sourcing system.
What idempotency is, why it's crucial (retries, double-click, at-least-once), and how to implement it in Go: HTTP middleware, unique DB constraint, concurrency handling.
Complete security audit of a Debian 12 server after a brute force attack: custom fail2ban, SSH/SFTP chroot, auditd, permissions, automated AI audit, Docker, HTTP headers.
Complete method for diagnosing a slow PostgreSQL query: EXPLAIN ANALYZE, missing indexes (B-tree, GIN, BRIN), stale statistics, pg_stat_statements. From diagnosis to production fix, no fluff.
How to implement a per-IP rate limiter in Go using the token bucket from golang.org/x/time/rate: sync.Mutex, cleanup goroutine to prevent memory leaks, X-Forwarded-For, middleware targeted at POST /api/v1/jobs.
slog, errors.Join, context.WithoutCancel, iter.Seq2, testing/synctest, go tool — what has settled as standard in the best Go projects in 2025.
How I built ClaudeGate: an HTTP gateway in Go that wraps Claude Code CLI with an async job queue, SSE streaming, webhooks, and SQLite persistence — single static binary, no CGO.
EventSource doesn't support custom headers — no way to send X-API-Key. How to replace it with fetch + ReadableStream for authenticated SSE streaming, with a manual parser and AbortController.