Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Domain-Driven Design with Golang
Domain-Driven Design with Golang

Domain-Driven Design with Golang: Use Golang to create simple, maintainable systems to solve complex business problems

Arrow left icon
Profile Icon Matthew Boyle
Arrow right icon
Mex$516.99 Mex$738.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4 (19 Ratings)
eBook Dec 2022 204 pages 1st Edition
eBook
Mex$516.99 Mex$738.99
Paperback
Mex$922.99
Subscription
Free Trial
Arrow left icon
Profile Icon Matthew Boyle
Arrow right icon
Mex$516.99 Mex$738.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4 (19 Ratings)
eBook Dec 2022 204 pages 1st Edition
eBook
Mex$516.99 Mex$738.99
Paperback
Mex$922.99
Subscription
Free Trial
eBook
Mex$516.99 Mex$738.99
Paperback
Mex$922.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Table of content icon View table of contents Preview book icon Preview Book

Domain-Driven Design with Golang

A Brief History of Domain-Driven Design

Welcome to this book on domain-driven design (DDD) using Golang. If you have never heard of DDD before, I hope that by the end of this book, you will have a good understanding of what it is, where it came from, how it can be applied, and how to implement some of the patterns popular among DDD proponents using Golang.

You might be surprised to discover that a large part of the first half of this book will be defining terms and discussing patterns on how to work with others to build systems that represent the real world. At its core, this is what DDD is about. Don’t worry though; there will be plenty of Golang examples, and in Part 2, we will dive deeper into building out DDD-based systems.

In this chapter, we will explore how DDD emerged and gained popularity. I find this context particularly valuable as we delve deeper into the topic as it helps you understand why to use it, not just how.

In this chapter, we will cover the following topics:

  • The world before DDD
  • Eric Evans and DDD
  • Three pillars of DDD
  • Adoption of DDD
  • When should you use DDD?

The world before DDD

Before 2003 and the inception of DDD, engineers and architects were thinking about how to organize their software and systems in a way that represented the problem space (domain) they were trying to model. As software became more and more complicated, it became apparent that the closer your system was to the domain, the easier it was to make changes. More importantly, it was easier for other stakeholders to converse with engineers as there was less of a disconnect between the real-world model of the problem space and the system model.

This was the issue that Eric Evans, a software engineer, was facing—the increased complexity of systems and failures in creating and maintaining them. This led him to write the book Domain-Driven Design: Tackling Complexity in the Heart of Software, Addison-Wesley Professional, in 2003—the first book on the subject of DDD.

“...(The) book Domain-Driven Design was an attempt to capture for people the successful practices that I had seen or used, some of which have been around for a long time and some of which are relatively new, and put together into a coherent set of practices with clear names so that maybe we can have broader success than we have in the past… a great deal of domain-driven design comes straight out of good old-fashioned object-oriented design patterns.” (Evans, in an interview with Software Engineering Radio, 2019, Episode 8: https://youtu.be/7yUONWp-CxM)

What does Evans mean when he refers to object-oriented design (OOD) principles? It used to be a given that everyone would write some object-oriented (OO) code as they began their journey into software development, but that is not necessarily the case anymore. If you are reading this book and Golang is your first programming language, it might be that you have never written traditional OO code. 

OO programming (OOP) is a way to write programs that allows us to organize our code around objects rather than functions. We give these objects attributes and methods that define behavior.   

OOP is particularly popular for large complex code bases as OOP is much easier to reason about. One of the most popular OOP languages is Java.

If we were building a human resources (HR) system, we might want to model an employee. If we were using Java, we might write this as follows:

public class Employee {
    private String firstName;
    private String lastName;
    public Employee (String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }
    public String getFirstName() {
        return this.firstName;
    }
    public String getLastName() {
        return this.lastName;
    }
   
       public String toString() {
        return "Employee(" + this.firstName + "," + this.lastName + ")";
    }
}

As you can see from this basic example, the code is readable, and we can easily model an employee in the system. When the business requires us to print a list of all employees or add the ability to store an employee’s location in their profile, you can hopefully see how our current Employee class forms the basis to add such functionality.  

Now that we have learned what OO code looks like, we can review some of the design patterns that are commonly used and that inspired DDD.

So, what are OOD patterns?

Design patterns were first described in 1977 in a book titled A Pattern Language: Towns, Buildings, Construction, by Christopher Alexander, Oxford University Press. This book has nothing to do with software engineering, yet it inspired one of the most influential books on OOP design, called Design Patterns, Elements of Reusable Object-Oriented Software, by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, Addison-Wesley Professional. This book was released in 1995 but still features at the top of computer science students’ reading lists in 2022. You may have heard of this book by its colloquial name, the Gang of Four (or GoF), in reference to its four authors. 

In the GoF book, 23 design patterns are outlined for what the authors believe lead to scalable, maintainable OO software. Going through each pattern is beyond the scope of this book (the GoF book comprises ~400 pages).

However, if you have read the GoF book, as you proceed to learn more about DDD, it is worth taking a pause and seeing whether you can see where Evans’s inspiration came from. The GoF patterns are split into the following sections, which are equally important when considering DDD: 

  • Creational patterns are patterns concerned with creating objects instead of creating objects directly. This gives more flexibility to the program in deciding which object type to create, given the current context.
  • Structural patterns are concerned with how you compose objects within your program to achieve certain functionality.
  • Behavioral patterns are concerned with how objects communicate.

Now that we have learned a little about what inspired DDD, let’s talk about the book that started it all.

Eric Evans and DDD

Evans’s book (sometimes called the Big Blue Book) has become a must-read title for all software engineers and architects. Whenever we talk about DDD, this is the book that started it all. In the book, he gave a common language and a set of principles to design systems that have been refined and clarified over the years by members of an ever-growing community.

The Big Blue Book has sold over 100,000 copies and consistently remains in the top 10 computing books on Amazon. Martin Fowler, a famous thought leader in the software engineering space, describes the book as “an essential read for serious software engineers” (in his martinFowler.com blog, 2020: https://martinfowler.com/bliki/DomainDrivenDesign.html).

However, the book is not without flaws. It has received criticism for being hard to read. In his review, Matt Carroll states: “The book is written in a dialect approaching that of academia. Big words, long sentences, and introduction to concepts that are so abstract that they would be unintelligible without the accompanying examples. In fact, some parts continue to be unintelligible even with the examples” (in his Medium blog, 2016: https://mattcarroll.medium.com/book-review-domain-driven-design-42c96a75a72).

Regardless of the criticism, the book is still as relevant and celebrated as it was years ago when it was published. One reason is that the book outlined three pillars that can be used independently or together to improve complex software projects. In the next section, we will review these pillars.

Three pillars of DDD

In this book, Evans introduced three main concepts (sometimes called pillars) of DDD. These are ubiquitous language, strategic design, and tactical design. We have summarized them in this section, but we go into each in more depth later in this book.

Ubiquitous language

Ubiquitous language is the term we use to describe the process of building a common language we can use when talking about our domain. This language should be spoken by everyone in the team—developers and business folk alike. It unites the team by ensuring there is no ambiguity in communication.

As with real languages, the ubiquitous language should evolve as your team’s understanding of the domain increases. It should never be imposed by domain experts, for it is not a business language. We will discuss how to develop a ubiquitous language in Chapter 2.

Strategic design

Strategic design is a phase of the DDD process in which we map out the business domain and define bounded contexts.

The goal of strategic design is to ensure that you architect your system in a way focused on business outcomes. We do this by first mapping out a domain model, which is an abstract representation of the problem space. If you were working on a shipping system, your domain model might look like this:

 

Figure 1.1 – A domain model diagram representing a shipping domain

Figure 1.1 – A domain model diagram representing a shipping domain

Notice how shipping is at the center of the diagram? This is part of the core domain, and all the surrounding points are there to support shipping. 

There is more work to be done here to create bounded contexts, but even at this very early stage of the DDD process, you can start to think about how your system might look.

We will talk about bounded contexts in much more detail in Chapter 2

Tactical design

Tactical design is where we begin to get into the specifics of how our system will look. In the tactical design phase, we begin talking about entities, aggregates, and value objects, which also happens to be the title of Chapter 3 of this book. We will use these patterns to help us define software boundaries.

Adoption of DDD

DDD has remained popular since its inception, as depicted in the following screenshot, which shows a trend line in a Google Trends graph.

Figure 1.2 – Google Trends graph of searches for DDD

Figure 1.2 – Google Trends graph of searches for DDD

Indeed, it is just as valuable to learn DDD (maybe more so) now as in 2004 (as far back as Google Trends goes).

Although Evans laid the foundation for DDD, it has remained relevant for nearly 2 decades because, in Evans’s own words, “smart and innovative people have shaken things up repeatedly.” These people have taken the fundamentals outlined in a DDD and created new concepts, which have enabled DDD to remain relevant, even though the way we write software has changed quite dramatically.

Some of the books highlighted by Evans are listed here:

  • Greg Young and his work on Command Query Responsibility Segregation (CQRS): CQRS is a pattern that emerged to capture all application changes as a sequence of events. It allows the segregation of read and write events from the database and can help maximize application performance, scalability, and security. This is particularly popular in large enterprise software.
  • Domain-Driven Design Quickly: This book was released in 2006 and was (and still is) free; you can read it here: https://www.infoq.com/minibooks/domain-driven-design-quickly/. Evans likes this book as its simple and succinct nature made DDD accessible to everyone.
  • Vaughn Vernon and his book Implementing Domain-Driven Design: Evans described Vernon’s book as “the most ambitious book since my own.” The community has affectionately called this book the Big Red Book. This book refreshed a lot of the ideas that Evans outlined originally and focused more on how you can implement DDD.

Big companies such as Microsoft, Amazon, and IBM use DDD internally and guide how you can use it too. It is, therefore, still a great time investment to learn about DDD today.

Is DDD always applicable though? Just because big companies use it, it does not necessarily mean it is a good fit for your side project. In the next section, we explore this in more detail.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Explore Domain-driven design as a timeless concept and learn how to apply it with Go
  • Build a domain-driven monolithic application and a microservice from scratch
  • Leverage patterns to make systems scalable, resilient, and maintainable

Description

Domain-driven design (DDD) is one of the most sought-after skills in the industry. This book provides you with step-by-step explanations of essential concepts and practical examples that will see you introducing DDD in your Go projects in no time. Domain-Driven Design with Golang starts by helping you gain a basic understanding of DDD, and then covers all the important patterns, such as bounded context, ubiquitous language, and aggregates. The latter half of the book deals with the real-world implementation of DDD patterns and teaches you how to build two systems while applying DDD principles, which will be a valuable addition to your portfolio. Finally, you’ll find out how to build a microservice, along with learning how DDD-based microservices can be part of a greater distributed system. Although the focus of this book is Golang, by the end of this book you’ll be able to confidently use DDD patterns outside of Go and apply them to other languages and even distributed systems.

Who is this book for?

This book is for intermediate-level Go developers who are looking to ensure that they not only write maintainable code, but also deliver great business value. If you have a basic understanding of Go and are interested in learning about Domain-driven design, or you’ve explored Domain-driven design before but never in the context of Go, then this book will be helpful.

What you will learn

  • Get to grips with domains and the evolution of Domain-driven design
  • Work with stakeholders to manage complex business needs
  • Gain a clear understanding of bounded context, services, and value objects
  • Get up and running with aggregates, factories, repositories, and services
  • Find out how to apply DDD to monolithic applications and microservices
  • Discover how to implement DDD patterns on distributed systems
  • Understand how Test-driven development and Behavior-driven development can work with DDD

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 16, 2022
Length: 204 pages
Edition : 1st
Language : English
ISBN-13 : 9781804619261
Category :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning

Product Details

Publication date : Dec 16, 2022
Length: 204 pages
Edition : 1st
Language : English
ISBN-13 : 9781804619261
Category :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Mex$85 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Mex$85 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Mex$ 2,810.97
Domain-Driven Design with Golang
Mex$922.99
Microservices with Go
Mex$861.99
Event-Driven Architecture in Golang
Mex$1025.99
Total Mex$ 2,810.97 Stars icon

Table of Contents

12 Chapters
Part 1: Introduction to Domain-Driven Design Chevron down icon Chevron up icon
Chapter 1: A Brief History of Domain-Driven Design Chevron down icon Chevron up icon
Chapter 2: Understanding Domains, Ubiquitous Language, and Bounded Contexts Chevron down icon Chevron up icon
Chapter 3: Entities, Value Objects, and Aggregates Chevron down icon Chevron up icon
Chapter 4: Exploring Factories, Repositories, and Services Chevron down icon Chevron up icon
Part 2: Real -World Domain-Driven Design with Golang Chevron down icon Chevron up icon
Chapter 5: Applying Domain-Driven Design to a Monolithic Application Chevron down icon Chevron up icon
Chapter 6: Building a Microservice Using DDD Chevron down icon Chevron up icon
Chapter 7: DDD for Distributed Systems Chevron down icon Chevron up icon
Chapter 8: TDD, BDD, and DDD Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Most Recent
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4
(19 Ratings)
5 star 52.6%
4 star 36.8%
3 star 10.5%
2 star 0%
1 star 0%
Filter icon Filter
Most Recent

Filter reviews by




Mike Bell Aug 25, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book provides a practical explanation for Domain Driven Development that can actually be learned and used.There is also a good portion towards the end that helps one yo understand how TDD and BDD can augment it and work together rather than be considered its own separate concern.
Amazon Verified review Amazon
Matthew Mar 08, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Anyone looking for a super advanced/senior level book, this is probably not the one for you. However, that being said, it has a great set of examples that show practical real world concrete implementations. I feel like that aspect is always missing in books like this and they end up being far too academic. I'd consider myself more of an intermediate looking to graduate to advanced in the Go ecosystem and I can say this did definitely teach me a few things I never knew before. In general it was a peaceful read and I would recommend it if you're looking to go a bit further in your learning journey.
Amazon Verified review Amazon
Nema Pojma Dec 24, 2023
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
I give a 3 stars because nothing in this book is harmful, but you should read probably anything else before this one.If you are an expert of DDD trying to learn the best ways to apply GOlang to DDD patterns, this book will NOT help you. Actually, you will probably use golang better than what the book shows. So this book is better if you already know GOlang and want to learn a little bit of DDD. But in that case you'd be way better by reading the main DDD books, (Eric Evans and Vaugh Vernon books, that the author of this book did clearly NOT read). Because this book is a weak guide to DDD at best and it has quite some misunderstandings on some of the patterns.Here are some examples: the definition of Aggregate roots is missing one important thing, the aggregate roots rules, explained in the Vaugh Vernon book, that the author clearly didn't read. Value Object should be immutable, if you want to know golang tricks to achieve that, keep searching. The most interesting confusion is the CQS vs CQRS, (the first one being just a separation of commands and queries and the second one being the architecture, with read models, and / or projections using different persistence mechanism and commonly build with domain events). The confusion is understandable. Just that CQRS was NOT credited to Bertrand Meyer, but to Dr Young. Bertrand Meyer could be credited with CQS, and honestly the book could have introduced commands and queries way earlier, because the first examples of the books make for a very awkward and confusing code where basically you pass the exact entity attributes to create the entity, why don't you explain the command pattern? It's not even explained.More things: the author keeps writing interfaces where the function signatures have the first parameter the context, without explaining why and most of the time not even being used, giving the impression of junior developer code (unused anything is really confusing in any situation). Or instantiating services with the NewXXService named constructor, setting the attributes private (good), but why doesn't he make also the whole service private? this way the rest of the code is forced to use the named constructor, making sure that the service is in a valid state. The way it is in the book somebody could still instantiate the service bypassing the named constructor, therefore having an invalid service. If you expect some tricks and explanation about that, keep searching. And why isn't the book using the power of types to apply to value objects? and the same named constructors. Value objects should be self validating, but the book is very often bypassing value objects pattern all together and using just primitives. Or the minimizing of domain events which is the basic foundation of event driven architecture, and also of CQRS (I am sure the author never attempted to apply either of these architecture for real). And the approach to microservices, well, the assumption of the author are quite painful (I'd recommend the "building microservices" form Sam Newman 2nd edition too have some clarity)I am quite surprised somebody felt expert enough to write a book like this. I was hoping to learn how to best implement ddd patterns in golang but I found a bunch of weak code examples and some definition that are close to being incorrect.Still I go for 3 stars, it's better this than spegheti code, or Golang community code without any patterns, and it can be the entry point of Go developers.
Amazon Verified review Amazon
Hana Mohan Dec 01, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Feefo Verified review Feefo
Andrew W. Aug 10, 2023
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
The book is clear and helpful with great examples to follow. Easy to read and informative this is an excellent primer for those looking to understand domain driven design especially as it relates to coding with the Go language.If following along with code I’d recommend the GitHub repo over the included snippets which occasionally don’t compile. Finally I’d skip the TDD chapter at the end, which seems to be added as an after thought and isn’t as well researched as the rest of the book.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.