Evolution of Domain-Driven Design
Since the birth of software development in the 1960s, developers strived to create better applications to deal with the complexity of the world. During the following 20 years, many reports emerged pointing out the inefficiency of software systems and their design processes. We also went through the infamous software crisis that led to many incidents, such as the Therac-25 ( https://en.wikipedia.org/wiki/Therac-25 ).
One of the main problems during that time was that software development followed a “code-and-fix” approach. That is, developing software without a clear view of the project and the problem to solve. This led to incomplete software that quite always went over budget and missing deadlines seemed to be normal.
The turning point arrived in 1968 during the NATO conference where the issue was acknowledged, and people started laying the groundwork for software engineering as a formal discipline ( https://docslib.org/doc/9230794/crisis-what-crisis-reconsidering-the-software-crisis-of-the-1960s-and-the-origins-of-software-engineering ).
In this chapter, we will delve into the following main topics:
- Progression of the software development approaches
- The story so far
- What is domain-driven design ( DDD )?
- How it changes the approach to the problem
Your purchase includes a free PDF copy + exclusive extrasYour purchase includes a DRM-free PDF copy of this book, 7-day trial to the Packt+ library (no credit card required), and additional exclusive extras. See the Free benefits with your book section in the Preface to unlock them instantly and maximize your learning. |
Progression of the software development approaches
Between the 1980s and 1990s, the awareness of the software crisis led to the rise of various “silver-bullet” approaches that did not, however, provide a definitive solution. The famous article, No Silver Bullets , written by Fred Brooks, took the problem head-on and brought to the attention of the reader that there are mainly two different kinds of complexity; essential and accidental (you will read in depth about them in Chapter 2 ).
In Steve McConnell’s book, Software Estimation: Demystifying the Black Art , there is a really interesting concept called “cone of uncertainty,” which exposes part of the problem with a simple diagram ( Figure 1 .1 ). This diagram points out that estimates created early in the project are subject to a high degree of error. As you can see, these estimates can be off by a factor of four both in high and lower ends. The application of this concept was in the estimate process, but it maps very well to the problem that DDD tries to solve. A deep understanding of the domain leads to stronger models, greater project resilience, and more accurate estimates. This could be only obtained by investing time in understanding the problem. As also stated in the book itself,” The reason the estimate contains variability is that the software project itself contains variability. ”
Figure 1 .1 – Cone of uncertainty
As a result of this awareness, as predicted by F. Brooks, and the evolution of development methods, such as object-oriented programming, we assisted in the rise of new development tools called RAD (e.g., Delphi, Visual Basic, Paradox, Visual FoxPro), which provided solutions to the accidental complexity of the problem, while still leaving room for improvement to essential complexity.
The summary of these inefficiencies put the roots for the birth of DDD.
The story so far
Back in 2003, Eric Evans, through his popular book, Domain-Driven Design: Tackling Complexity in the Heart of Software (often referred to as “the blue book” because of its distinctive blue hard cover), introduced an innovative approach to software design and development. Since then, an ever-growing slice of the software community has begun to shift their approach to software design by applying what he suggested.
This new way of developing software was driven by the need to find a new and more efficient way to tackle the intricacies of an already complex world. What Evans tried to put down in his seminal book is a completely novel approach to what is defined as E-programs of Lehman’s law ( https://en.wikipedia.org/wiki/Lehman%27s_laws_of_software_evolution ).
What he realized was that the traditional approach in software design was focused on translating the complexity of the business flows with just technical solutions (DB first, anyone?).
His proposal was to first do a deep exploration and modeling of the problem space (we will delve into it in Chapter 2 ) and only then try to find an acceptable solution. This approach could only be achieved by involving a continuous collaboration between developers and domain experts.
As paradoxical as it seems, DDD has reached widespread acceptance and use with the advent of microservices. As with every tremendous change, it takes time for the community to understand and refine these concepts. In fact, the early adopters started to slowly implement it circa 2004-2006. The landscape has shifted significantly since that time. During this period, the first use cases started to appear in various developers’ communities and mostly in complex systems, such as telecommunication and healthcare.
In 2006, Jimmy Nilsson authored the book titled Applying Domain-Driven Design and Patterns with Examples in C# and .NET . The book’s approach was very practical and the first one with a fully-fledged application so that the readers could see a method for implementing the main concepts of DDD. This book contributed heavily to further popularizing the approach.
Soon after, Floyd Marinescu and Abel Avram published Domain-Driven Design Quickly , where they tried to “ concisely summarize the essence of DDD .” Their work was based mainly on Evans’ and Nilsson’s books but also used other communities’ forums to try to organize and simplify the fundamental concepts of DDD.
After a period of relative calm, in 2009, Greg Young came up with the term Command Query Responsibility Segregation ( CQRS ) (You can learn more at https://cqrs.wordpress.com/wp-content/uploads/2010/11/cqrs_documents.pdf ), which is built upon Bertrand Mayer’s CQS (as described in his book Object-Oriented Software Construction ) and further powered by event sourcing ( ES ) to handle complex domain logic (the famous CQRS + ES). This is a pattern that strongly complements DDD by separating read and write operations. But another big push to DDD arrived around 2012 when its patterns influenced in a way the emerging microservices architecture ( https://en.wikipedia.org/wiki/Microservices ) with bounded contexts offering a natural way to define service boundaries, leading to a resurgence in DDD interest.
Just a year later, two big things happened simultaneously. Vaughn Vernon published Implementing Domain-Driven Design (the so-called “red book”), a book which, like Evans’, we have studied at least three times during the years. This publication provides great guidance on applying DDD concepts and patterns in real-world projects, bridging the gap between theory and practical implementation. This book introduced a concrete example of the use of events in a complex domain (we will see how they can help our refactoring process in Chapter 11 ). The second massive thing that will heavily influence the community in the coming years was Alberto Brandolini’s first post on EventStorming ( http://ziobrando.blogspot.com/2013/11/introducing-event-storming.html ). This workshop format has been widely adopted for collaborative domain modeling since it helps create better communication and understanding between domain experts and developers. As we will see in Chapter 2 , staying in the problem space as long as possible is a good thing.
As if the preceding year were not full of things to study and reflect upon, the following year, another interesting book saw the light, Patterns, Principles, and Practices of Domain-Driven Design by Scott Millett and Nick Tune. This book offers an in-depth exploration of DDD patterns and practices, enriched with case studies, and has become a key resource for experienced developers and architects.
Then, in 2016, the first big conference on DDD was born. The first edition of DDD Europe was held in Bruxelles with an already impressive number of participants as a testimony of the unstoppable interest that DDD has created. Since then, the conference moved to Amsterdam and every year, more than 700 participants attend, with tons of talks and workshops.
In the following years, lots of other communities and conferences were born and we are sure today you can find at least one local meetup near your town with other passionate developers willing to share their struggles and successes with DDD.
In 2019, Alexey Zimarev published Hands-On Domain Driven Design with .NET: Tackling complexity in the heart of software by putting the DDD principles to practice , a well-structured book with a plethora of examples in C# with .NET Core.
Finally, in 2021 another terrific book was published, Learning Domain-Driven Design: Aligning Software Architecture and Business Strategy by Vlad Khononov. This incredible book focuses on providing a modern perspective of DDD by giving the reader practical implementation practices for modern complex software development.
Last but not least, in 2024, we were lucky enough to be part of the celebration of the 20th anniversary of the Explore DDD Conference held in Denver, CO.
These milestones highlight the growth and adaptation of DDD principles in response to evolving software development challenges, proving the enduring relevance and impact of DDD in the field. We surely forgot some other important events that contributed to the definition of what is today DDD, but they are the ones that we lived through personally and shaped us as developers still trying to find the light in a fast-paced world continuously growing in complexity.
What is domain-driven design (DDD)?
First, we can say what DDD is not. It is not a framework, or a library, to be installed on our computers to guide us in the development of software systems.
At the heart of DDD are two interconnected principles: ubiquitous language and bounded context.
Ubiquitous language is a shared vocabulary consistently used by all stakeholders, including domain experts, developers, and business teams. It eliminates ambiguities in communication, ensuring that everyone involved speaks the same language when discussing the domain. This shared understanding directly influences the accuracy and clarity of the software model, aligning it closely with the business domain.
Bounded context defines the boundaries within which a specific domain model and its associated ubiquitous language apply. These boundaries prevent overlaps or inconsistencies between different parts of a system, enabling teams to work independently within their assigned contexts. This modular approach simplifies the management of complex systems and ensures that changes within one context do not unintentionally affect others.
As an example, you can think of the game that many Agile coaches use, the broken telephone. The game points out how with each hand-off of information from one person to another, the information is always altered due to the interpretation of each individual.
In human conversations, context is naturally developed as people engage in dialog. When someone enters the discussion midway, they often ask, “Who or what are you talking about?” rather than directly inquiring, “What is the context?”
Without context, meaning can be ambiguous, distorted, or even completely lost. A lack of context when joining a conversation can lead to misunderstandings, as the newcomer may make incorrect assumptions about the subject at hand. Similarly, an abstraction can only be as accurate as the shared understanding of the context among all participants in the communication.
As stated before, one of the main goals of DDD is to reduce as much as possible this phenomenon by establishing a common language to make explicit the implicit.
Figure 1 .2 – The broken telephone applied to a project
Communication is key to understanding the problem we need to solve. DDD wants to be an alternative to an anemic list of requirements and delivery of the software. This can be achieved by starting by trying to understand the problem instead of defining a list of requirements. We should not start with one, or more, ready-made solutions, because requirements are in fact a solution to the problem and are given to us at the beginning of the project exactly when we do not know anything about the domain. This means that we are unable to clearly understand whether they really are the solution or not. Requirements capture a stakeholder’s perspective of the system at a particular point in time and are subject to change.
DDD aims to help create software more aligned with the business goals, more adaptable to change, and easier to maintain over time. To ease the conversation, DDD focuses on the business domain , so it is necessary to clarify its meaning right from the start.
Throughout this book, you will evolve an Enterprise Resource Planning (ERP) system that handles production, shipping, and orders of a brewery (yes, we love beer). You will start from a legacy system and by applying all the patterns that DDD gives us we will refactor and improve it.
What you will do, exactly, is better understand the business domain, which is the main area of activity of our brewery, and refactor your way toward a more resilient and scalable application using baby steps instead of a “big bang change” (or nuclear option, as we call it).
Now that we know what “domain” is, why “ driven ”? By the book, the term implies that the design of the software is guided by someone or something. In our case, it is based on a deep understanding of the domain, and only after understanding a domain, we’ll introduce technical considerations or implementation details.
Finally, “ design ” simply refers to the process of creating a solution.
Refactoring is a crucial part of the DDD approach. It involves restructuring existing code without changing its external behavior to improve nonfunctional attributes. In the context of DDD, refactoring is not just about code; it’s about refining the model to better reflect the domain as your understanding deepens.
This continuous alignment of the software model with the evolving understanding of the business domain is one of the key principles of DDD. Regularly revisiting and refining the model ensures it accurately represents the current state of the domain. This iterative process of refining and improving the model is where refactoring comes into play.
In practice, refactoring with DDD involves several steps:
- Understanding the Domain : Before any refactoring, you need a deep understanding of the business domain. Engage with domain experts to gather insights and ensure the model accurately reflects the domain knowledge.
- Identifying Areas for Improvement : Look for parts of the code where the domain model is not well represented or where technical debt has accumulated. These are prime candidates for refactoring.
- Applying DDD Patterns : Use DDD patterns, such as aggregates, entities, value objects, and services, to restructure the code. Ensure that these patterns are applied in a way that enhances the clarity and integrity of the domain model.
- Maintaining Functionality : Refactor in small steps to ensure that the system remains functional throughout the process. Use automated tests to verify that existing functionality is preserved.
- Continuous Integration : Integrate changes frequently to catch issues early and ensure that the refactored code works well with the rest of the system.
- Feedback Loop : Regularly review the changes with domain experts to ensure that the refactoring aligns with their understanding of the domain. Use their feedback to further refine the model.
This iterative process ensures that the software remains adaptable to changes in business requirements and it is easier to maintain and extend over time.
How DDD changes the approach to the problem
DDD fundamentally transforms the approach to software development by placing the business domain at the heart of the development process. Traditional software development methodologies often start with technical considerations, such as data modeling, database design, or user interface wireframes.
While these aspects are essential, DDD shifts the focus from technical priorities to aligning software design with fundamental business concepts, resulting in more relevant, flexible, and maintainable systems.
DDD emphasized the importance of explicitly defining context to ensure the precise interpretation of an abstraction. It advocates for a mindset shift where the primary focus is the alignment between all the members of the team and avoiding misunderstanding. This is one of the primary ways DDD is used to change the approach to problem-solving. This common language is something shared between the stakeholders, domain experts, developers, and end users and is as strict as a programming language. The good thing is that it is a vocabulary that is understood by each party and its consistent use allows every team member to easily refactor parts of the code that do not align with business requirements. It also strongly reduces misunderstandings and ensures that the code base evolves in harmony with the business.
DDD encourages developers to immerse themselves in domain knowledge and collaborate closely with domain experts (e.g., business analysts, end users, etc.). This deep exploration of the domain allows developers to gain a comprehensive understanding of the concepts, rules, processes, and behaviors that govern the real-world problem space. Obviously, this is not something that is achieved easily, but requires exploration and experimentation with several iterations with a lot of the time spent, as we will see in the next chapter, in what is called the problem space.
Just as in human conversations, fully grasping a model requires establishing the appropriate context and clear boundaries. A model, as we have noted, is a structured system of abstractions. Beware that a model remains an oversimplification of reality as defined by Rebecca Wirfs-Brock ( https://weave-it.org/blog/overcoming-additive-bias-software-design ):
A model is a simplified representation of a thing or phenomenon that intentionally emphasizes certain aspects while ignoring others. Abstraction with a specific use in mind.
These contexts help manage the complexity of large software systems by allowing different parts of the system to evolve independently. Each bounded context contains its own domain model, which is consistent and isolated from other contexts. This modularization is crucial for refactoring as it allows changes to be made within one context without impacting others, thus reducing the risk of introducing errors and improving the system’s overall maintainability.
In addition to bounded contexts, DDD leverages tactical patterns such as entities, value objects, aggregates, repositories, and services. These patterns provide a structured approach to encapsulating domain logic, ensuring that changes can be implemented cleanly and systematically. For example, entities represent objects that have a distinct identity and life cycle, while value objects encapsulate attributes and behaviors without identity. Aggregates are clusters of related entities and value objects that are treated as a single unit for data changes, ensuring consistency and integrity within the model.
Repositories abstract the data access layer, providing a clean interface for storing and retrieving aggregates. As described in Martin Fowler’s book, Patterns of Enterprise Application Architecture , ( https://martinfowler.com/eaaCatalog/repository.html ) a repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection.
Domain services encapsulate domain logic that does not naturally fit within an aggregate, promoting a clear separation of concerns. Its main use is to coordinate one or more aggregates removing as much as possible the coupling between them.
These patterns not only facilitate cleaner and more maintainable code but also make it easier to refactor and extend the system in response to the ever-changing business requirements.
Furthermore, DDD encourages iterative development and continuous refactoring. This iterative process allows teams to incrementally improve the system, making small, manageable changes that collectively lead to significant enhancements in the code base’s quality and functionality. These concepts do not apply to a green field project but are also true for the refactoring of a legacy system.
To close, by placing the domain at the center of the design process, DDD helps bridge the gap between the technical and business perspectives. As already stated, it significantly changes the approach to problem-solving in software development by prioritizing a deep understanding of the business domain, fostering clear communication through a ubiquitous language, and structuring the system using bounded contexts and well-defined design patterns. This methodology not only makes the refactoring process more efficient and effective but also ensures that the software evolves in alignment with the business’s needs, resulting in more robust and maintainable systems.
Summary
Since Evans’ 2003 book, Domain-Driven Design: Tackling Complexity in the Heart of Software , the software community has increasingly adopted the DDD approach. Evans’ emphasis on understanding and modeling the problem space before implementing technical solutions marked a significant shift from traditional methodologies, especially in refactoring.
This chapter highlights the evolution of DDD and its influence on refactoring practices. Key contributions include Nilsson’s practical applications, Greg Young’s CQRS pattern for complex domain logic, and the resurgence of DDD with microservices architecture. Vaughn Vernon’s work gave practical examples, while Alberto Brandolini’s EventStorming improved communication between domain experts and developers.
In conclusion, DDD transforms refactoring by prioritizing domain understanding and communication, leading to more intuitive, business-aligned, and resilient software solutions.
In the next chapter, you will refresh, or learn if you are new to these concepts, the principal strategic patterns that you need to know foreffective refactoring the DDD way.