Bounded context is a group of subdomains. It’s a logical boundary for domains and subdomains. DDD divides a large business system to small bounded contexts; each bounded context has its own model. A microservice is a bounded context; there could be multiple microservices inside the same bounded context but not vice versa. The same data model may have different meanings for different microservices. In the following diagram, there are two bounded contexts: Sales and Inventory. Sales Bounded Context has two subdomains such as Order and Payment and Inventory Bounded Context has the Inventory domain. The Catalogue sub-domain represents different things in each bounded context. It’s like the fruit apple is Apple in English and Manzana in Spanish. The sub-domain takes on different behaviour and characteristics depending on the bounded context such as the Catalogue domain that is common with Sales and Inventory Bounded Contexts:
Now, let’s discuss the insight of DDD. As per the modern cloud native microservice design, all microservices should be loosely decoupled. Every microservice module should work on a single responsibility principle. We will need a logical and meaningful way to split an application into smaller microservices. These services will work in a bounded context model in isolation. These are two standard ways to decompose applications into smaller domains:
Based on business process: Applications can be decomposed based on the business processes of the organization like customer service, catalogue service, order service, and so on. Sometimes, microservices can be divided into business domains/departments like finance, HR, inventory, delivery, sales, and so on.
Based on business function or model: Some application modules are common and spread across multiple business use cases like an order service can be divided into multiple modules like order management, order packing, delivery, and so on. These related subdomains can be combined within a single order service.
Advantages The advantages are as follows: Business centric Loosely coupled Easy to modify, upgrade, and unit test Easy to understand and debug Easy to deploy with CI/CD pipeline Limitations
The limitations are as follows: Difficult to do integration testing for end-to-end business use cases. Identifying and understanding subdomains is a little complex exercise.