Microservices and Domain Driven Design (DDD): a practical approach to software architecture
As has been said on countless occasions, although it may sound a little cliché, in the world we live in, changes are occurring at an ever-increasing speed, where corporations tend to have changing needs that allow them to adapt and shape their business to the evolution of the market. In addition, we are also observing that new technologies are appearing daily that are able to bring new benefits and capabilities and therefore help us to offer greater value in the market, differentiating us from our competitors.
In the fast-paced, yet exciting landscape that software development has become, building scalable, flexible, and maintainable systems is a challenge for many organisations. In this regard, two approaches have emerged as fundamental pillars for the construction of complex systems: Domain Driven Design (DDD) and Microservices. The union of the two is a powerful combination that enables the creation of highly scalable, flexible, and maintainable systems aligned to changing business needs.
Two approaches for the construction of complex systems: Domain Driven Design (DDD) and Microservices.
Microservices offer several key advantages. Unlike a monolithic architecture, where a single component is available for the entire system, the system is divided into small services that run independently but work together to cover the entire functionality. Because microservices are autonomous, each of them can be updated, deployed, and scaled without affecting the others, which gives the application a high capacity to evolve as technical or business needs arise. Microservices also allow development teams to work autonomously, which accelerates development and continuous delivery.
DDD is based on the idea that the heart of any software system is the business domain, focusing on understanding and modelling it in a deep way, promoting the use of a ubiquitous language shared between domain experts and development teams, which forges a deep knowledge and understanding of business processes. This domain design methodology, where complex and also less changeable business domain logic is protected, helps to abstract the complexity of the use case domain, allowing for evolution and controlled change in the software. This perspective based on isolating the domain fits perfectly with the philosophy of the Ports and Adapters design pattern also known as hexagonal architecture.
The focus on context boundaries, another key feature of DDD, leads to modularisation of the system into smaller, cohesive components, which not only improves maintainability, but also provides a solid conceptual basis for future implementations of microservices-based architectures.
To reflect how domain-driven design and microservices can be effectively intertwined, let's consider the case of a very simple application where we have to manage customers and orders. In addition, customers have associated addresses and a customer's orders are composed of products.
In this case we can see that on the one hand we have the management of the orders themselves and on the other hand we also have the management of the customers, both blocks forming bounded contexts within the same domain.
This division into different contexts provides a very good basis for proceeding to break down what might initially be seen as a unit into smaller services that are easier to maintain and scale, resulting in customer and order microservices.
In conclusion, by applying DDD principles to microservices design, organisations can leverage the benefits of both methodologies and build highly adaptable and flexible systems. At Izertis we help organisations combine these approaches with all the necessary pieces to find the solution that best fits their business needs.