Dec 1, 2026
Splitting and Merging Domains in DDD
An introduction to common scenarios for splitting and merging domain contexts in DDD, with real cases from e-commerce and enterprise office, plus practical guidance at the code, architecture design, and interface and documentation levels.
1. Background
I once discussed a domain service splitting problem with a friend in a DDD discussion group. It also touches on code-level operations and design: a domain service containing several subdomains, and as the business grows or iterates, one of those subdomains needs to be split out and iterated on its own. Many programmers run into this situation sooner or later, especially under a distributed microservices architecture, so this article focuses on the splitting and merging of domain contexts in DDD.
2. DDD Patterns Related to Domain Splitting and Merging
Before getting into the topic, let’s review the DDD patterns that relate to it: Abstract Core, Segregated Core, Shared Kernel, Generic Subdomain, Continuous Integration, and Evolutionary Order. The most relevant one here is Segregated Core. Patterns such as Evolutionary Order and Continuous Integration are not directly about this topic, but a lot happens during a domain split or merge anyway. The domain context changes as subdomains are split out or merged, which drags domain services and interfaces along with it, and that produces a series of problems such as data migration and interface compatibility.
3. Scenarios for Domain Splitting
3.0 Overview
Domain splitting is actually very common, and it is not only about domains: service splitting, database table splitting, and architecture splitting all show up too. The goals differ from case to case. Here are some common splitting scenarios:
- Turning a monolithic application into a microservices architecture
- Splitting subdomain modules out of a core domain service
- Splitting a subdomain module into a domain service
- Replicating a generic domain across business lines as supporting services
- Splitting out generic subdomains shared by several core domains
- A domain service being coupled to an architectural style, causing a subdomain or context to become a service on its own
- Splitting caused by unclear positioning of multiple subdomain services under a core domain
If you have run into other domain or service splitting scenarios, feel free to discuss them with me. Below I use two scenarios from different industries to describe what domain splitting looks like and what work sits behind it to make the split go smoothly.
3.1 E-commerce: the Product Center
Let’s start with the e-commerce product center. My department has been sorting out the product and inventory centers recently, so I know a little about this area. For the last few months I have been responsible for iterating on the trading center, and given how our business works, trading does not have much to do with products or inventory. Overall, I have spent roughly two years accumulating knowledge in e-commerce. Now let’s assume we are building an e-commerce company that needs a product trading center centered on a vertical product line. Here is a domain context diagram I drew.

From a monolithic service point of view, a product trading center that supports around 2,000 orders per day is really just a re-skinned purchase-sales-inventory system. Now suppose we want to split it up. The boss says the company just raised funding and can finally go to battle with e-commerce companies like Alibaba. Acquire users, run ads, do promotions, and move from vertical e-commerce into platform e-commerce. We programmers get busy along with everyone else: hiring, reworking systems… and so on.
Assuming we currently have around 50,000 users, the first push should bring that to at least 2 million, with a daily order volume in the tens of thousands. Since staffing and scheduling will not let us split every subdomain of the product center out at once, which one goes first? Let’s say priority puts the order subdomain first. That gives us the first domain splitting scenario: turning a monolithic application into a microservices architecture.
If there is a project owner or an architect, they will definitely do some work to keep the split from requiring downtime. Here is roughly what needs to be done:
- Rework the database tables: create new tables and add fields to meet business needs
- Create new projects for the business: frontend, backend, search, admin side, C side, and so on
- Check whether order and trading features in the old product center have direct relationships with other subdomains, and assess the risk of changing them
- Data migration and dual writes
- Stop the dual writes and establish the upstream and downstream relationship between the product center and the order trading center (MQ, async, and so on)
- Maintain the order trading center independently, and take the product-center side of order and trading features offline
Once the order trading center is independent, the next step is to keep splitting, because the product center, being a core subdomain, cannot stay in this monolith either. Since it is a core domain, it cannot simply be carved out the way the order and trading subdomain was. So in the second phase we extract the search context as an independent subdomain of the product center and maintain the search service separately, then gradually switch search off in the old product center. That gives us the third splitting scenario: splitting a subdomain module into a domain service. Search should not be a hard split, so let’s keep going.
After search is split out, we can build a new product center that maintains product SKUs, SPUs, product details, and search independently. Product details need to be supported on the C side first, so their requirement priority is high, and the product detail context starts to stand out. That gives us the second splitting scenario: splitting a subdomain module out of a core domain service. Product details can sit in the old product center as a temporary solution while the new product center’s detail pages are wired up, with the old product detail page acting as a fallback.
Making the product center self-contained inevitably pulls in permissions, logging, and operations management, so that roadmap also relates to splitting scenarios 4, 5, and 6. I won’t go through them one by one.
Finally, here are the two relatively painful and messy scenarios. Scenarios 6 and 7 tend to happen after many domain services are already built and live. Take the product center above: once all of its features are taken offline, the new picture is a pile of domain services and projects supporting the company’s business together. Iteration inside some domains or contexts is never perfect, and there are always new systems and features filling in on top, so the fate of an existing domain service comes down to two outcomes: either it limps along half-dead or it goes offline. At that point, looking at all the domain services and projects globally, you will feel that some of them are duplicated, some are redundant, and some were split too finely and need to be merged.
3.2 Enterprise Office: the OA System
Next, let’s look at the enterprise office scenario. I spent more than three years at a company in Beijing, working in the enterprise office domain the whole time, so scenarios 6 and 7 above are something I felt deeply. Once microservices and distributed systems carry the business, the granularity of service splits and the cost of maintaining them become extremely difficult. How do new services and old services coordinate? From a domain context point of view, a domain service, or a standalone microservice process or project, is really just a submodule or a context that has not been aggregated into one large project, which is why there are so many Git addresses and repositories. I covered enterprise service architecture evolution in an earlier post, so let me simplify things here and look at it through domain context maps.

There are still contexts and subdomains not listed in the diagram above, such as meeting room reservations. Each of these subdomains is served by at least two projects. Very often, after a microservice split, our grasp of domain service capability only looks better on paper; once the number of services and interfaces grows, it does not actually improve much. Especially once new services appear, coordinating contexts and services inside a domain starts to feel awkward. Take the employee core domain: employees are the core of enterprise office, so a lot is built around them, including an HR system, external API projects, and a database shared with the user subdomain where the models are largely shared too. As business requirements change and people come and go during this evolution, those situations end up forcing domains to be split, made independent, or taken offline.
4. Scenarios for Domain Merging
4.0 Overview
Domain merging is actually rare, but if you spend a few years in software development you will certainly run into it: old systems going offline, overlapping projects, large-scale refactors that come with partial domain merging, new domains being born, and so on. Behind domain merging there are also drivers, such as forward-looking architecture design sorting out domain services early. During a merge, plenty of code becomes dead code or zombie code, because whoever maintains it would rather not touch it than go looking for trouble. Here are some domain merging scenarios, and if you have hit others I would be glad to discuss them with you:
- Features or domain capabilities in a monolith need to be replaced or taken offline for other reasons, such as integrating a third-party interface
- Features or domain capabilities in a monolith get repositioned as new iterations land, and are merged into another domain
- Several microservice projects with similar functionality are refactored and merged
- Many supporting domain services in a microservices project are extracted or taken offline, and their capabilities converge into a separate core domain and service
- Supporting or core domain services in a microservices project that were not built around domains or a business mid-platform are consolidated into a unified service cluster; product and order capabilities, for example, are pulled back from each business line into a product center and an order center
- A merger or restructuring between group companies may cause domains across the two groups to merge
- Groups that partner with large internet companies to get traffic and orders need their related domains to adapt and merge as well
4.1 E-commerce: the Order Center
Honestly, I find the order center harder to think about than the product center. From the order center’s point of view, an order needs state control on one hand, and on the other it has to link to users, products, discounts, payment, and refunds, with more complex cases involving the trade itself. Some orders are never paid, some orders are never refunded, and so on. So carving an order center into domain contexts is fairly involved, and order centers end up looking almost nothing alike from one scenario to the next. Below, assume the order center is the core domain; this is roughly what its subdomains and contexts look like:

Assume you work at an e-commerce company that is growing fast. Early on, each business party built its own order domain, more or less with its own services and database supporting the business. Now the company has decided to build its own mid-platform following the methodology of the mid-platform heavyweights like Alibaba. One thing to do is pull the management of the entire order flow into the order center of the mid-platform project. If you are the project manager or a participant, here is what you might need to do:
- Sort out the current state of order data, order tables, order models, order requirements, and order management platforms across the business lines
- Consolidate, from the differing order characteristics of each business line, what features the order center in the mid-platform project should have
- Pull people in or hire for the order center requirements in the mid-platform project, and gradually consolidate the order management flows of the different business lines
- Data migration, dual writes, taking each business line’s order features offline, and decommissioning their order databases
- Coordinate the business lines to migrate their order features into the order center under the mid-platform project
- Plan iterations according to the new order center’s requirements
The musings above are actually quite similar to scenarios 3 and 5. I won’t discuss domain merging in monoliths here; the points worth watching and the relevant details are covered in section five. Let’s continue with domain merging in the microservices scenario: suppose this e-commerce company develops well mid-way through, raises funding, and acquires a similar e-commerce company. The acquired company also has its own engineers and order center, and to make a bigger push in e-commerce its orders, products, operations team, and services need to be integrated, raising volume and efficiency. This merging of same-business domain services from two different companies is much like scenario 6.
A far more common situation is that this kind of e-commerce company also partners with big platforms such as Tmall, Douyin, and Pinduoduo to get order traffic. The domains and services owned by its own engineering team then have to adapt to those platforms’ domain services. Strictly speaking this is not merging, it is association or adaptation. But for a small or mid-sized e-commerce company, adapting to and tying into a big platform is not easy either.
4.2 Enterprise Office: the Permission System
In permission domains, and in ERP and CRM systems, permission is almost always a generic supporting domain service platform, and most developers have taken part in building permission features or systems to some degree. As for how permission capability services evolve, every company and every developer has a tale of woe, because permission models and permission features really do differ a lot from company to company.
In a permission module or system, whether monolithic or microservice, you will see domain splitting and merging. I worked at a company in Beijing for a bit over three years and built four versions of the permission system, with multiple versions running online at the same time, while systems such as recruiting and HR still had their own permission management features and were never fully pulled back into the permission system. The merging scenarios for permission systems are much the same as those above, so I won’t dig deeper here; if you are interested, let’s discuss them together.
5. How to Handle Domain Splitting and Merging
From the discussion above we can see that splitting and merging domains happens all the time. Nothing in a software system is permanent, especially on the internet, where systems and services get pushed around by product and development teams again and again. As the saying goes, you just jump from one pit into another. The essence is the same whether or not you look at the problem through domain services or DDD. Below, let’s look at how to face the problems a domain or service split produces.
5.1 Code Level
At the code level the changes show up mainly in business logic and models. When splitting, business logic and models may be copied into different projects; when merging, leftover models and method interfaces are never deleted. For projects built from zero to one this is less of an issue. For projects that already exist, or ones you inherit and keep iterating on, code is often just left in place after a domain split, and that easily leads to problems.
The best approach is to add comments and documentation, or mark things as deprecated, and to spell out the model and database table changes version by version, with each version saying what changed. For example, if a system needs to migrate its permission features, or needs to integrate with a new permission system, the permission-related features, models, and database tables can all be kept as a backup and then removed in a later iteration.
Another kind of case is that a subdomain or context in the current domain service needs to move out into an independent service while keeping its upstream and downstream relationships, so some adapter work is needed. Deleting code here needs care. The BOs, DTOs, and VOs inside the domain all have to be deleted, and the related business interfaces and methods have to move out; after that you can add some adapter code. If you cannot do it in one shot, take a smaller step first: put the subdomains or contexts that need to move into their own package so they are clearly marked, leave the surrounding business code where it is, and have it interact with the new domain service instead. Then gradually delete all the code belonging to the outgoing domain context.
5.2 Architecture Design Level
There is quite a lot involved at the architecture design level. Projects such as jobs and APIs usually call core services, but in some cases they access the database directly and build their own entities, BOs, and DTOs, which has a big impact on both project design and business iteration, since adding one field means changing it in many places.
When splitting or merging domains at this level, stability and availability come first: database migration, taking services up and down, feature switches, traffic routing, and so on, each with a fallback when something goes wrong. Next, think through the model evolution for upstream and downstream calls. Splitting and merging domains always involves code changes, so domain models and services both need updating, and every object that does not belong in your own business domain has to be moved out.
After a split or a merge, the collaboration relationships and communication costs between upstream and downstream change, and those changes are visible in the call chains. These architectural adjustments are hard to see from the models themselves; only the people who lived through the refactor know what changed before and after. Architecture design should help upstream and downstream domain services draw clear boundaries and make responsibilities explicit, so design docs and proposals should call out not only changes in technical direction but also changes in domain models and service responsibilities. This shows up in a few DDD patterns, such as context mapping, evolutionary order, and highlighting the core.
The last point is architecture and engineering design review. Since a split or merge covers project breakdown, going up and down, feature iteration, and maintenance, inconsistent styles and naming across projects quickly becomes a headache. Take a Dubbo project: the classic shape is one parent module with two child modules, though one parent with three or four is just as common. Then the names of those child modules are rarely standardized enough to be understood at a glance, to say nothing of the packaging strategy inside. So when splitting and merging domains, naming conventions and module design matter a great deal. A consistent style helps a system stay maintainable.
5.3 Interface and Documentation Level
Interface and documentation problems are just as common when domains are split or merged. For example, an interface is split off and never taken down, the code is never deleted or marked deprecated, the interface docs are never updated, and interfaces and their documentation get shuffled between documentation repositories every time departments or the business change. From a domain point of view, model changes are hard to reflect in documentation, which raises the cost of understanding a new system for whoever maintains or iterates on it. The best approach is to stop tying domain service documentation to department documentation. Domain service documentation covers interface docs, database docs, and domain analysis docs (entities, value objects, service interfaces, upstream and downstream model relationships). That way, no matter how department names or responsibilities change, the product or order center always lives in this documentation repository; only the people maintaining it change.
In practice almost nobody does this. Most teams each maintain their own set, and the moment the org structure or business shape shifts even slightly, documentation falls into chaos. Some copy documents, some migrate documentation directories, some create overlapping new documents, some create similar-looking documentation repositories. So in domain splitting and merging, the stability of documentation really does determine the stability of maintenance and iteration.
6. Bonus: the Cracked Egg Diagram
The diagrams above are something I only picked up in the last couple of days. I jokingly call them cracked egg diagrams, but the real name is domain context map. Plenty of more experienced authors use this style of diagram to explain domain contexts, and anyone learning DDD who cannot draw one would have little to show for it, so I have given it a few tries too. I started with ProcessOn and got the egg diagram finished, but with difficulty: its connectors are too smart, so anchor points are hard to control and lines can only attach to fixed positions, which looks a bit rigid. After that I searched for dedicated diagramming software and tried the online tool from the Rookie Tutorials site, only to find there is no undo; one mistake and the whole canvas has to be thrown away. So I also tried Edraw on macOS, and after downloading the Mac version I found this kind of diagram fairly easy to draw. Exporting was less friendly, since it adds a watermark by default, but the trial version is already enough for a diagram like this.
Comments
Comments are powered by GitHub Discussions. Sign in with GitHub to join the discussion.