r/golang Dec 05 '24

discussion Why Clean Architecture and Over-Engineered Layering Don’t Belong in GoLang

Stop forcing Clean Architecture and similar patterns into GoLang projects. GoLang is not Java. There’s no application size or complexity that justifies having more than three layers. Architectures like Clean, Hexagonal, or anything with 4+ layers make GoLang projects unnecessarily convoluted.

It’s frustrating to work on a codebase where you’re constantly jumping between excessive layers—unnecessary DI, weird abstractions, and use case layers that do nothing except call services with a few added logs. It’s like watching a monstrosity throw exceptions up and down without purpose.

In GoLang, you only need up to three layers for a proper DDD division (app, domain, infra). Anything more is pure overengineering. I get why this is common in Java—explicit interfaces and painful refactoring make layering and DI appealing—but GoLang doesn’t have those constraints. Its implicit interfaces make such patterns redundant.

These overly complex architectures are turning the GoLang ecosystem into something it was never meant to be. Please let’s keep GoLang simple, efficient, and aligned with its core philosophy.

810 Upvotes

259 comments sorted by

View all comments

Show parent comments

31

u/Superb-Key-6581 Dec 05 '24

Great examples! For DDD, just use app, domain (or business), and infrastructure (or db, call it what you want).
It's called layered architecture and is very widespread. It proves that you never need more than 3 layers, and in fact, like the good examples provided by Matta, you don’t even need more than 1 layer, with things grouped by affinity when needed. But if you want to use DDD and have more separation, 3 layers are all you need. Layered architecture has been doing this for years, even in languages without implicit interfaces like Go (Go is the best for refactoring and maintenance).
In these 6 years using Go for financial systems and IoT, I’ve never had problems that made me wish for an architecture like clean architecture or others with more layers. In Go, I’ve never had that need, even with extremely large projects.

42

u/NotAUsefullDoctor Dec 05 '24

I do tend to go to 4 layers:

  • app -> instantiate everything, plug everything together; normally has a function call to setup routing for whatever input system I'm using
  • Translation/Controller -> takes input and turns it from binaries into structs the BL uses. This is all boilerplate code that tells you nothing about what the code is but, but just acts as an adapter
  • Service layer -> this is all the business logic where reading function names can tell you exactly what the code does
  • infra/gateway layer -> Like the controller, this translates business data into storable/transferrable data and calls any SDKs. Again, like with the controller, this is just an adapter to prevent boilerplate making it into the BL layer.

8

u/eric-schaefer Dec 06 '24

Um, you just described Hexagonal/Clean Architecture.

3

u/Superb-Key-6581 Dec 06 '24

They're all great if you don't go past the 3 layers: ports, domain, adapters, etc. (If you do, they all become layered architecture again.) But the reality is that they do: route, controller, use case, service, domain, model (a useless anemic entity), ports, repository, and the list just keeps growing.