Finding Boundaries

Images

Many domains are too big to be understood and modeled as a whole. In such cases, you need to break down a domain into manageable units. In this chapter, we elaborate an important step in this process: finding the boundaries between subdomains.

This chapter is for you in the following cases:

  • You are struggling with a monolith and want to re-organize it or split it into more manageable parts.

  • You want to design microservices or self-contained systems.

  • You want to apply Domain-Driven Design (DDD) and have difficulties identifying bounded contexts.

  • Your development team has become too big to work efficiently, and you want to split it into several teams.

  • You already have more than one development team and want to find out how you can organize the work for these teams.

In this chapter, we will come across some software development terms and concepts that we will explain only briefly. For more details, please see the references provided. In particular, we will refer to the following:

  • Strategic DDD vocabulary like subdomain , bounded context , and context map [ Vernon 2016 ]

  • Architecture styles ( monolithic , modular [ Lilienthal 2019 ], microservices [ Newman 2015 ], and self-contained systems [ SCS Website ])

  • Principles for organizing development teams, such as cross-functional teams [ Rubin 2013 ] and Conway’s Law [ Conway 1968 ]

Images

Henning’s Aircraft Maintenance Story

A big airline reached out and asked me to structure a large system for the technical maintenance of their aircraft. A child’s dream came true for me when the IT manager gave me a tour of the hangars and showed me how the mechanics worked on the planes. There were small ones and big ones; as a highlight, we climbed into a 747 to take a glance at all the different technology that is built into a modern airplane.

Back in the office, we met with a group of 20 people. We started by modeling the most important business processes of aircraft maintenance. We drew COARSE-GRAINED, PURE domain stories. This overview proved useful for getting everyone on the same page and finding out what we still had to do.

The domain experts told me that the sentences in these stories could be considered business processes in their own right. In fact, most of the work objects appeared only once per domain story. To me, each of these (apparently cloud-level) sentences felt a bit like an item on a checklist rather than sentences that build on each other to create a compelling story. I suspected that each sentence would be its own context, probably even more than one context.

We had to narrow the scope to identify useful boundaries in the domain, so we scheduled a series of follow-up workshops. Each had 5–8 participants who were experts in the respective area.

In the follow-up workshops, we dove deeper into the domain while still modeling COARSE-GRAINED , now at kite level. In the emerging stories, we found groups of coherent activities. These groups quickly developed further into 20 candidates for bounded contexts.

The context map that we distilled from the domain stories later became the basis for the team organization and new architecture of the system.

The Joy of Multiple Models

A single conceptual model is a tricky beast to work with.

—Martin Fowler [ Fowler 2003b ]

One of the challenges in building software is to structure it in a way that is comprehensible for developers. If a domain is too big to be understood as a whole, then it is too big to be modeled in software as a whole. A better solution is to have multiple models that cover self-contained parts of a domain instead. This enables the software and the development team to grow.

As we write this book, splitting monoliths is one of the hottest topics in software development. It is also one of the biggest problems that some of our clients experience. We have seen many large (> 1,000,000 LOC) legacy systems that had an adequate technical architecture and were nevertheless considered a big ball of mud [ Foote/Yoder 1997 ] by their developers.

Many of these barely comprehensible software systems are the result of a fundamental misunderstanding: That software should be based on a single, common model of the domain. And that this model is unambiguous. And that it should contain all properties of the real world in as much detail as possible.

DDD uses the term domain model , but it does not mean a company-wide model. If an entire organization is described with just one model, every software requirement needs to be understood in the context of this one model. The problem with this approach is that the model grows bigger and bigger. It tends to become a tangled mess that cannot be understood as a whole. A big ball of mud model leads to big ball of mud software.

DDD recognizes that, in real life, there is more than one truth, and a company needs several domain models. Take a look at central domain concepts in your organization, e.g., “account,” “client,” “customer,” or “product.” People will use the same term with different meanings in different parts of a domain—the so-called subdomains each have their own domain model.

Images

“The one” model as the source of pure and unambiguous truth is an illusion.

A Heuristic for Finding Subdomains

A good understanding of subdomains will help you identify technical boundaries in the form of microservices [ Newman 2015 ], self-contained systems [ SCS Website ], or modules within a monolith (also called a modular monolith or modulith by some).

We found that domain stories can help with defining the boundaries within a domain: You can use domain stories to find out which activities—from a domain expert’s perspective—belong together. Thus, the domain can be broken down into subdomains. We consider this a heuristic rather than a strict rule.

Images

Subdomains consist of activities that belong together from an actor’s perspective .

Applying the Heuristic

This “recipe” describes our heuristic:

  1. Find meaningful scenarios that cover the essentials of the domain.

  2. Model those scenarios as domain stories. The scope should be COARSE-GRAINED, AS-IS , and PURE (see Chapter 4 , “ Scope ”). Coarse granularity is cloud or kite level. PURE stories work best, because they are about activities that are not tainted by current software systems. You probably want to remove the impact of the existing systems on the organization and start thinking about subdomains completely from scratch.

  3. Within the domain story (or stories), find activities that belong together. (To help you with finding cohesive activities, we have compiled some indicators in the next section.)

  4. Cluster the activities into groups to make the subdomain boundaries visible. Since actors may act in more than one subdomain, place them outside the groups to make it clear that the actors are not considered part of the subdomain.

We will apply this recipe to Alphorn now.

Images

Back to the Leasing Example

We have already taken steps 1 and 2 together with salesperson Sandy, risk manager Raymond, and customer service agent Charley in Chapter 8 , “ Case Study —Alphorn Auto Leasing Inc.” Together with them, we modeled a ­happy-path scenario as COARSE-GRAINED domain story Alphorn 1 (reprinted in Figure 10.1 ).

Images

Figure 10.1 Alphorn 1: Leasing a car— COARSE-GRAINED, PURE, AS-IS

Let’s now take the other steps.

When we ask the domain experts which activities belong together, Sandy the salesperson says, “Sentences 1 to 5, that is the ‘offering’ part of the story. Once I have passed the contract on to the risk manager, it is literary out of my hands.” We group those activities together and name them accordingly (see Figure 10.2 ).

Images

Figure 10.2 The “offering” subdomain

Next, we ask Raymond if the risk managers’ part of the story should be grouped in one or in several sets of activities. He answers that sentences 6 to 8 belong together. Every contract has to be processed in this way. We agree on a name for this group of activities—“risk assessment” (see Figure 10.3 ).

Images

Figure 10.3 The “risk assessment” subdomain

We continue the discussion with the domain experts until we have reached the result shown in Figure 10.4 . Since this is a further iteration of domain story Alphorn 1 (see Figure 10.1 ), we name it Alphorn 1a.

Images

Figure 10.4 Alphorn 1a: Leasing a car— COARSE-GRAINED, PURE, AS-IS —grouped by subdomain

In summary, we have derived four subdomains from a COARSE-GRAINED domain story. That domain story describes just one scenario. If we look at more scenarios, most of these subdomains will appear again. Also, we will probably find other subdomains.

We also noticed that the offering subdomain is quite large. In our experience, this suggests that we will encounter inconsistent language as we continue to analyze the subdomain. In this case, we would further split the subdomain.

Sometimes, it is not so easy to figure out where one subdomain ends and another one begins, or if a subdomain should be split into smaller ones. In such cases, we recommend you model domain stories that play within one subdomain. Check how well those stories fit within the boundaries that you have proposed. Test the subdomain boundaries by looking for signs that the domain story reaches into other subdomains. Refine the boundaries and consider other heuristics as well (see the following section).

Indicators for Subdomain Boundaries

Indicators are not definitive proof that there is a boundary. They just provide some clues about what to look for. We have collected some indicators we have come across repeatedly. This list is not exhaustive, but we think it is helpful:

  • Actor produces result on their own: An actor completes several related activities independently, producing a meaningful outcome. Often, the actor then passes the result on to other actors. An example is “risk assessment,” as shown in Figure 10.4 .

  • One-way information flow: A handover between actors—an actor A transfers a work object to actor B , and there is no information flowing back to actor A (neither directly nor indirectly). This means that A is not involved in whatever B does with the transferred work object.

  • Different triggers: Customer service agent Charley has told us that the ­customer’s inquiry triggers the offering—an example of a request-based trigger. Once the car has been handed over, the customer must pay the monthly installment—an example of a time-based trigger (see Figure 10.5 ).

    Images

    Figure 10.5 Indicator: Different triggers—here: time-based

  • Activities supporting something that is not in the picture: In another domain story, Raymond tells us that creating a “risk report” is one of the risk managers’ activities. However, this risk report is not used by other actors in the story. Since the report was created for a reason, it will probably be used in another subdomain that is not relevant for this domain story.

  • Differences in language: The same work object is given different names by different actors. Or the same name is used with a (slightly) different meaning. (The second case is much harder to spot.)

  • Different use of the same thing: The same work object is used for significantly different tasks. For example, at Alphorn, the contract is “signed” by the customer and “voted” by risk managers. Signing is a legal act that creates a relationship. Voting takes place in a financial context—it is done to mitigate the financial risk for Alphorn.

From Subdomains to Bounded Contexts

So far, we have analyzed the problem space , where subdomains exist. If your goal is to build software, you have to transition from the problem space into the solution space . In DDD, this means designing bounded contexts . A bounded context implements an unambiguous domain model with a ubiquitous language. If a subdomain and a bounded context have a 1:1 relationship, you can think of them as two sides of the same coin.

Defining bounded contexts is a design process. DDD expert Nick Tune distinguishes five main categories of criteria for designing boundaries [ Tune 2019a ]:

  • Business value: Design decisions aligned to the business strategy

  • Domain: Design decisions aligning boundaries with the problem domain

  • Sociopolitical: Design decisions driven by the needs of the people building the systems

  • Technical: Design decisions affected by the technical requirements of a system (e.g., performance, security)

  • User experience: Design decisions that have an impact on how users experience the system

As you can see, alignment with (sub)domains is one of several criteria for finding bounded contexts. Often, there is no single, obvious solution. Trade-offs need to be considered. For that reason, the DDD community has resorted to the use of heuristics for finding bounded contexts.

Heuristics for Finding Bounded Contexts

Several DDD practitioners have shared their experience:

  • DDD Heuristics was initiated by Rebecca Wirfs-Brock and Kenny Baas-Schwegler. The webpage collects heuristics that are relevant for DDD, including some for bounded contexts [ DDDHeuristics Website ].

  • Nick Tune’s Tech Strategy Blog [ Tune Blog ].

  • The DDD Crew Repository contains useful tools [ DDDCrew Website ].

  • In addition to other DDD topics, Mathias Verraes writes about boundary finding in his blog [ Verraes Blog ].

Bounded context is one of the most important concepts of Domain-Driven Design. In the DDD literature, 1 you will find methods that help with reasoning about bounded contexts. One useful tool is a context map that shows how bounded contexts are connected. The context map shows a combined view of what can be learned by modeling several stories. Creating a context map is the logical next step after defining bounded contexts. Let’s look at a first version of an Alphorn context map in Figure 10.6 . It includes the four bounded contexts that we had identified so far and one relationship between offering and risk assessment.

1 . See for example Vaughn Vernon’s Implementing Domain-Driven Design [ Vernon 2013 ] and Michael Plöd’s Domain-Driven Design by Example [ Plöd 2020 ].

Images

Figure 10.6 Beginning of a context map for Alphorn

This is just the beginning of context mapping . The next step is to describe the relationships and interfaces. We are not going into that here, because it is covered in the DDD literature.

Bounded contexts are necessary to enable independent teams and keep software changeable. But business processes usually need integration. This requires a behavioral view of business processes. Domain Storytelling supports this shared view by bringing together people from different subdomains so that they can tell us what happens when a business process crosses from one subdomain to the next.

Domain stories provide a behavioral view that complements the structural view of a context map and the temporal view of EventStorming. That means that Domain Storytelling is not only a means for finding bounded contexts; it is also a means for visualizing collaboration across context boundaries.

Images

Context boundaries should separate models, not people.

From Context Boundaries to Team Boundaries

Once we have defined the context boundaries, we can use this knowledge to find the team boundaries. With a large software system (like the monolithic big ball of mud we described earlier), there are many people working, usually more than fit into one team. It makes sense to divide them into several teams and ask the question, who does what? If you have more than one team, it is generally a good idea to not let different teams work on the same parts of the system.

Images

Collective code ownership [ Beck 2000 ] is desirable inside a team, but not across team boundaries.

A classical approach to development team organization is to split the teams by the architectural layer. One UI team, one business logic team, one database team. This is a horizontal cut. Because of Conway’s Law, 2 the agile community (and we as part of it) think this is a bad idea. A more modern idea is to have cross-functional teams. This would mean a vertical cut. But where do we draw the boundaries between teams? That is where bounded contexts come into play.

2 . Conway’s Law basically says that the architecture of the software will have the same structure as the organization of the teams that build it [ Conway 1968 ].

One rule of design is that one bounded context should belong exclusively to one team. The reason is that we don’t want several teams to work on the same part of the software, so they do not destroy each other’s work. On the other hand, this does not mean that one team can have only one bounded context.

So, when dividing your developers into several teams, make sure that every team has at least one bounded context. When we apply this rule to Alphorn, where we have three development teams, one possible split would be as depicted in Figure 10.7 .

Images

Figure 10.7 Team organization at Alphorn

The assignment of bounded contexts to teams may change over time. One possibility is to start with one team that takes care of all the bounded contexts. If the team grows, eventually a point will be reached where it is has to be split into two teams. At this point, assign the contexts to the resulting teams.

What to Read Next?

Finding boundaries is hard. In fact, it is probably the toughest challenge we write about in this book. Reasoning about subdomains and bounded contexts with Domain Storytelling is just one of many useful tools. We recommend that you check out the references provided in this chapter.

You can also try big-picture EventStorming and look for boundary events —for example, events that indicate a handover, a changed state, or a point of no return. Alberto Brandolini calls those events pivotal , and what they separate business phases . For more information, read his article “Discovering Bounded Contexts with EventStorming” [ Brandolini 2020 ]. Nick Tune came up with a workshop recipe that makes use of EventStorming, a bounded context design canvas [ Tune 2019b ], and an adaptation of Domain Storytelling that he calls Domain Message Flow Modelling [ Tune 2021 ].

If you are satisfied with the boundaries that you have found, one of the next questions to ask for every bounded context is this: Do we build this part of the software ourselves (“make”), or do we buy an off-the-shelf solution (“buy”)?

  • If the decision is “make,” Chapter 12 , “ Modeling in Code ,” describes how to implement the domain model.

  • If the decision is “buy,” read Chapter 14 , “ Deciding Make or Buy and Choosing Off-the-Shelf Software ,” to decide which of the standard products is the right one for you.

Once you decide to dig deeper, consider learning more about the language (see Chapter 9 ) that is spoken within each subdomain (called ubiquitous language in DDD).

When you have organized your teams, the next thing to do is to define what the teams should do (e.g., with agile user stories , see User Stories Applied [ Cohn 2004 ]) and to organize that work (e.g., in a product backlog , see Essential Scrum [ Rubin 2013 ]). How that is done is the topic of Chapter 11 , “ Working with Requirements .”