close
22 Chapters·5 Parts·Companion Repo

Hexagonal Architecture in Go.

Ports, Adapters, and Services That Last.

The Go-native guide to building services that are easy to test, easy to change, and hard to break. No frameworks. No DI containers. Just interfaces and a main() function.

Kindle · Paperback · PDF · EPUB

Hexagonal Architecture in Go
“Your Go service's business logic should have zero knowledge of HTTP, databases, or message queues — and Go's implicit interfaces make this not just possible, but natural.”
Gabriel Anhaia

Gabriel Anhaia

Senior Software Engineer · Berlin

Sound familiar?

Your Go services start clean but become unmaintainable in 6 months?
You've read about clean architecture but it feels like Java patterns forced into Go?
Testing requires spinning up Docker and a real database for every unit test?
Changing the database means rewriting half the service?
New team members take weeks to understand the codebase?

This book fixes that — the Go way.

What's inside

22 chapters. 5 parts. Zero filler.

From the pain of spaghetti code to a production-ready hexagonal service. Every chapter builds on the last. Every concept is backed by tested code in the companion repo.

Part I — The Problem

3 chapters

The spaghetti service. Architecture buzzwords demystified. Why Go and hexagonal are a natural fit.

Part II — Thinking in Hexagons

4 chapters

The domain at the center. Ports as Go interfaces. Adapters as the bridge. The dependency rule.

Part III — Building It

6 chapters

Project layout. Domain modeling. Port design. HTTP adapters. Outbound adapters. Wiring in main().

Part IV — Production Patterns

5 chapters

Testing at every layer. Error handling across boundaries. Transactions. Events. Observability.

Part V — Evolution

4 chapters

When hexagonal is overkill. Migrating existing services. Splitting into multiple hexagons. The complete service.

After reading

You'll be able to:

Structure new Go services with clear boundaries from day one
Test domain logic in microseconds with zero infrastructure
Swap databases, message brokers, or APIs by changing one line in main()
Add new transports (gRPC, CLI, Kafka) without touching business logic
Migrate existing tangled services incrementally, without a rewrite
Handle errors, transactions, and events without leaking infrastructure into the domain
Add logging, metrics, and tracing via decorators — the domain stays pure
Know when hexagonal architecture is overkill and skip it confidently

Tested code, not toy examples

Companion Repository

Every code example in the book lives in a public repo. A complete order processing service with domain, ports, adapters, tests, and working main(). Clone it. Run it. Break it. Learn from it.

github.com/gabrielanhaia/hexagonal-go-examples
Gabriel Anhaia

About the author

Gabriel Anhaia

Senior Software Engineer building production Go services every day at Monta in Berlin. 10+ years of experience scaling backend systems for fintechs and high-growth companies.

Also the author of The Complete Guide to Go Programming and creator of Hermes IDE, an open-source AI-native terminal.

Build services that last

Stop fighting your codebase.
Structure it.

22 chapters that take you from spaghetti to hexagonal. Every concept backed by tested Go code.

amazonEnglish

Kindle · Paperback · PDF · EPUB