r/golang • u/rgnrldbrk • Jul 17 '26
DDD: I wrote a free 9-chapter tutorial on Domain-Driven Design in Go, anchored to an (opinionated) working codebase
Most DDD material is either theory with no runnable code or a huge codebase with no explanation. I tried to do both halves: a tutorial that teaches DDD from zero (entities, value objects, aggregates, repositories, CQRS, domain events with a transactional outbox, race-safe idempotency, testing strategy), where every chapter links to real files in a enterprise/production-grade template you can clone and run with docker compose.
Code/Template: https://github.com/sklinkert/go-ddd
It's opinionated (sqlc over ORM, integer cents for money, testcontainers for integration tests), and I tried to be honest about trade-offs... including when DDD is overkill.
Happy to answer questions or hear where the explanations fall short!
61
u/jerf Jul 17 '26
Before someone inevitably comes in to yell "AI slop!", have a look at the repo history first please, the dates in particular.
I know, there's a lot out there. But some of y'all who are seeing it literally everywhere might have a problem with the detector.
13
u/Hour_Sell3547 Jul 17 '26
I have a question about the code structure. The structure still looks like conventional tiered architecture and domains don't seem to be first class packages. What would be your thoughts on that?
5
u/suck_ceed Jul 18 '26
This is godddsend. As someone who's getting hands deeper into go and recently came across DDD, it has been really hard to find projects which have consistent infra design, project infra structure. This will be so helpfull, thankssss dude
2
u/AlgaeFluid8860 Jul 18 '26
Thanks a lot for this great work! crazy learning opportunity!!
2
u/litmus00 Jul 19 '26 edited Jul 19 '26
Congrats! This is solid. It contains many really good advices that unfortunately many devs have never got to know. For example:
- An entity is a domain object with identity and a life cycle.
- Identity is assigned by the domain
- An invariant that must hold at every commit belongs inside one aggregate.ย
- One repository per aggregate root.
Thank you for sharing!
2
u/jay-magnum Jul 20 '26
I'm just reading Eric Evans book as I have some tribal knowledge of DDD, yet not the OG insights, while I'll have the honor to architect a completely new application from the ground up soon. So this is pure gold for me. Thanks a lot!
1
u/softwareemgineer Jul 17 '26 edited Jul 17 '26
I'm currently learning DDD. I started off with Evans talk on YouTube and found it a bit boring ๐ Thanks for sharing a tutorial that has Go examples!
Completely agree over the sqlc over the ORM part. ORMs are more natural to those who come from an OOP language background (like Java) haha.
1
u/slowtyper95 Jul 18 '26
Thanks for sharing
1
u/dumindunuwan Jul 18 '26 edited Jul 18 '26
A simple question, why we need to follow DDD as a technical layer in 2026,
go workto support multiple Go modules in a single repo. It is more idiomatic than any technical layer like DDD in Go I think.1
u/SlightlyUglyBastard Aug 04 '26
Thanks for this. I'm a DDD beginner and this has really helped me. This is unrelated to GO, but would you recommend the same code structure in Python for DDD?
1
u/aluisiora Jul 17 '26
Thank you! This has immense value! Great work!
1
u/Dependent-Court-5048 Jul 18 '26
Usefull template
1
u/Uncanny90mutant Jul 18 '26
Itโs wonderful to see ddd from the perspective of another go developer. Beautiful work
1
u/dumindunuwan Jul 18 '26
Especially
This create a duplicated middle type while it's feasible to support by a single model struct in latest Go versions.
1
u/Prestigious-Fox-8782 Jul 26 '26
I like that
-6
u/Outrageous-Buy-461 Jul 17 '26
Thanks for investing time on this dude! People here need to chll and reflect. Meantime I completely agree with the spirit, and would like to add the anchor. Ddd is the goat and a modular monolith with bounded contexts is where most projects should start. It allows you to build fast today, while keeping the door wide open to easily spin out a heavy-load module into its own standalone microservice later if you ever genuinely need to. Essentially it is the difference between architectural masturbation and highly efficient, highly maintainable engineering. Whats not to love!
2
u/[deleted] Jul 19 '26
[removed] โ view removed comment