From domain-driven design to microservices

How the domain-driven design development philosophy can be suited to microservices

digital transformation devops primary
Thinkstock

As many of you may recall, the software design and architecture style known as service-oriented architecture (SOA) emerged in the mid 1990s. Since then, we have discovered better ways to build systems, including advances in cloud-based virtualization, continuous integration and delivery, and microservices. In the process, these technologies have made SOA and all the associated benefits a reality.

In November, I delved into explaining how microservices can be introduced into a large organization with well-established legacy systems. In this post, I cover domain-driven design (DDD) and how this development philosophy can be used to represent the real world in code while being well-suited to a microservices implementation.

Domain-driven design

Cohesion is an early tenet of software design and refers to the degree of functional relatedness that exists inside a module or class. In this context, cohesion was first described in the late 1970s by Tom DeMarco and has come to mean grouping and keeping together those things that change for the same reasons and separate the functionality that changes for different reasons. 

DDD provides an avenue to facilitate the development of highly cohesive systems through bounded contexts. Microservices is an implementation approach that encourages you to focus your service boundaries on the business domain boundaries. DDD and microservices can be used together as you move your organization to a service-oriented design and reap the benefits of continuous integration and delivery.

The seminal work in DDD was defined in a 2003 book by Eric Evans called Domain-Driven Design: Tackling Complexity in the Heart of Software. The overarching philosophy of DDD is to use the notion of bounded contexts which form protective layers around models that define the business domain. Bounded contexts are analogous to departments in a company—the legal department has certain specific responsibilities (contexts) that are different than the IT department and those responsibilities are enforced by rules (boundaries) for interaction and obtaining services from the departments. 

This is the same for bounded contexts that you model using DDD. To facilitate a common understanding of the problem domain and translate that domain knowledge into a computer system, the business and technical team must develop a common language. In DDD this common language is called the ubiquitous language (UL). As the technical staff develops its models and code, it uses the UL to decrease the risk of misunderstanding between the business analysts and the engineering staff as the project progresses. 

This also serves to provide an additional layer of documentation of the systems and enhances the organization’s understanding of how a system was designed and intended to work. The analysis models that are used to understand and define the domain are tied to the code models that are used to create software by the UL.

Other key principles of DDD include:

  • Iterative creation of the analysis and code models. As the team learns more about the domai, it iterates on its analysis and code models, keeping both in sync. DDD does not specify tools, databases, or languages, but I have used UML (Universal Modeling Language) to create analysis models, and my code or implementation models were done in C++ and Java.
  • Collaboration of the business and technical teams requires close, face-to-face collaboration to create the relevant models. This is a heavy commitment for all parties to develop the UL, use it to define the domain, iterate through the definition of the domain, and focus on the problem instead of jumping directly to a solution.
  • Focus on the core domains. The core domains are those domains that will make the product a success. It is a core domain if it is absolutely essential to the success of the business. You should be asking yourselves how this domain increases revenue, cuts costs, or increases efficiency, and why and how this domain is critical to the business.
  • The problem you are solving must be substantial. There is no use in implementing DDD for problems that are insignificant, won’t move the needle for the business, or are better solved with a commercial off-the-shelf solution.

After you have begun to understand the business problem and developed models to define it you will have to think about how to integrate bounded contexts. In their book Enterprise Integration Patterns (Addison Wesley Signature Series), Gregor Hohpe and Bobby Woolf define four integration styles: file transfer, shared database, remote procedure invocation, and messaging. In most applications of substantial size and for reasons of cohesion your DDD and technical team will most likely settle on remote procedure invocation and/or messaging for integration.

From domain-driven design to microservices, pairing these two approaches to solve large and complex problems makes good business sense.

This article is published as part of the IDG Contributor Network. Want to Join?