DDD-Driven Microservice Splitting: 3 Key Steps to Avoid Coupling Pitfalls

This article explains how Domain-Driven Design (DDD) guides microservice splitting through three steps: enforcing high cohesion and low coupling principles, dividing systems into core, supporting, and generic domains via bounded contexts, and using message queues for asynchronous event-driven decoupling, illustrated with an online food ordering example.

Code Farming
Code Farming
Code Farming
DDD-Driven Microservice Splitting: 3 Key Steps to Avoid Coupling Pitfalls

Many teams learn microservice architecture and confidently start splitting, only to discover services become tightly interdependent — changing one requires modifying three others, making maintenance harder than a monolith. The root cause is not technical complexity but incorrect splitting principles. Domain-Driven Design (DDD) provides a solution. This article outlines three key steps to apply DDD for effective microservice decomposition.

Step 1: Enforce "Small and Focused" — High Cohesion and Low Coupling

The core principle of microservice splitting is five characters: small and focused. This expands into two iron laws:

High cohesion = single responsibility. All code in a microservice must change for the same reason. Modifying this service should not affect others; it must be independently deployable. For example, when a user places an order, the order service needs user information, but "querying users" is not the order service's responsibility. You should not join the user table inside the order service; instead, call the user service's API.

Low coupling = interface calls + service registry. Services must not depend directly on implementations. They communicate via a service registry by name. The user registration service can have multiple implementations; whichever registers with the registry gets called.

Industry data shows over 90% of microservice transformations fail because these two principles are violated. Remember: high cohesion means one change is enough; low coupling means changes don't affect each other.

Step 2: Divide into Three Domain Types Using Bounded Contexts

With principles established, how to split concretely? The answer: split by bounded contexts. First, conduct event storming for domain modeling, dividing the system into multiple subdomains. Each subdomain centers on an independent business scenario; the involved objects and relationships form bounded contexts and context maps.

The critical step is classifying subdomains into three categories:

Core domain — the core business scenario itself. In online food ordering, "user ordering" is the core domain; it is the primary event driver.

Supporting domain — provides data support for the core domain. "User registration" supplies user info; "restaurant management" supplies menu data. These are supporting domains.

Generic domain — reusable cross-scenario capabilities like notifications and payments.

Once divided, each bounded context maps to one microservice. The context map defines service interfaces and call relationships. Services split this way are naturally highly cohesive and loosely coupled.

Step 3: Use Message Queues for Event Notification Decoupling

After splitting services, a remaining challenge: how to notify domain events? After a user places an order, the restaurant must receive order details promptly to accept it. Polling the order service wastes resources and creates coupling. The optimal solution is asynchronous notification via a message queue.

Implementation: the order service saves the order, then publishes order details as a message to the queue. The restaurant order-acceptance service runs a daemon process that continuously listens to the queue; upon receiving a new message, it triggers the acceptance flow.

The elegance: the sender only sends, unaware of receivers; the receiver only receives, unaware of the sender. The two microservices have zero knowledge of each other — complete decoupling. The same pattern applies when the restaurant marks meals ready, notifying the rider service via the queue. This mechanism should be pushed down to a technical middleware layer for unified provision.

Complete Path from DDD to Microservices

Connecting the three steps yields the full DDD-guided microservice splitting pipeline:

Event Storming → Domain Modeling → Bounded Context Division → Microservice Splitting → Domain Layer + Database Design

First, hold event storming workshops for domain modeling. Then, based on the model, partition bounded contexts. Split microservices along bounded context boundaries; define interface relationships via the context map. Finally, within each service, design Services, Entities, Value Objects, and databases according to the domain model.

Frontend microservices are divided by role: the user app aggregates registration, ordering, and browsing; the restaurant web handles order acceptance and menu management; the rider app manages dispatch. The frontend acts as an aggregation gateway, routing requests by type to different backend microservices.

One-Sentence Summary

Microservice technical architecture isn't hard; the difficulty lies in splitting principles. DDD's answer: use bounded contexts to define boundaries, message queues for decoupling, and event-driven collaboration for coordination. Master these three, and microservice splitting ceases to be a problem.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

microservicesmessage queueDDDevent-drivenbounded contextdomain modelinglow couplinghigh cohesion
Code Farming
Written by

Code Farming

Senior engineer at a top internet giant, sharing Java, AI, tech knowledge, growth insights, and interview experiences.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.