Geek Culture
Published in

Geek Culture

Domain Driven Design | Deep dive into context mapping

A few months ago, I created a story about Domain Driven Design (DDD) with a pretty high level overview about what is and is not part of the DDD language. In this story I want to have a more specific eye on the Context Maps in DDD.

Why use Context Mapping?

A context map, as the name already suggests, helps you define the relationships between the different contexts of your application in a mostly visual way. This is very useful, if for example a word has one meaning in one context, and a totally different in another one. This can happen quite fast and will result in a confusing language barrier between the two contexts.

What is Context Mapping?

Context mapping is a tool that allows developers and domain experts to identify the relationship between bounded contexts and the relationship between the teams that are responsible for them.

There are different ways of how we can integrate between two or more bounded contexts:

  • Partnership
  • Shared kernel
  • Customer supplier
  • Conformist
  • Anticorruption Layer
  • Open Host Service
  • Published Language
  • Separate Ways
  • Big Ball of Mud

Partnership

When teams in two Contexts will succeed or fail together, a cooperative relationship needs to emerge. The teams institute a process for coordinated planning of development and joint management of integration. The teams must cooperate on the evolution of their interfaces to accommodate the development needs of both systems. Interdependent features should be scheduled so that they are completed for the same release.

Shared Kernel

Sharing part of the model and associated code forms a very intimate interdependency, which can leverage design work or undermine it. Designate with an explicit boundary some subset of the domain model that the teams agree to share. Keep the kernel small. This explicit shared stuff has special status and shouldn’t be changed without consultation with the other team. Define a continuous integration process that will keep the kernel model tight and align the Ubiquitous Language of the teams.

Customer-Supplier Development

When two teams are in an upstream-downstream relationship, where the upstream team may succeed interdependently of the fate of the downstream team, the needs of the downstream team come to be addressed in a variety of ways with a wide range of consequences. Downstream priorities factor into upstream planning. Negotiate and budget tasks for downstream requirements so that everyone understands the commitment and schedule.

Conformist

When two development teams have an upstream/downstream relationship in which the upstream team has no motivation to provide for the downstream team’s needs, the downstream team is helpless. Altruism may motivate upstream developers to make promises, but they are unlikely to be fulfilled. The downstream team eliminates the complexity of translation between bounded contexts by slavishly adhering to the model of the upstream team.

Anticorruption Layer

Translation layers can be simple, even elegant, when bridging well-designed Bounded Contexts with cooperative teams. But when control or communication is not adequate to pull off a shared kernel, partner, or customer-supplier relationship, translation becomes more complex. The translation layer takes on a more defensive tone. As a downstream client, create an isolating layer to provide your system with functionality of the upstream system in terms of your own domain model. This layer talks to the other system through its existing interface, requiring little or no modification to the other system. Internally, the layer translates in one or both directions as necessary between the two models.

Open Host Service

Define a protocol that gives access to your subsystem as a set of services. Open the protocol so that all who need to integrate with you can use it. Enhance and expand the protocol to handle new integration requirements, except when a single team has idiosyncratic needs. The, use a one-off translator to augment the protocol for that special case so that the shared protocol can stay simple and coherent.

Published Language

The translation between the models of two Bounded Contexts requires a common language. Use a well-documented shared language that can express the necessary domain information as a common medium of communication, translating as necessary into and out of that language. Published Language is often combined with Open Host Service.

Separate Ways

We must be ruthless when it comes to defining requirements. If two sets of functionality have no significant relationship, they can be completely cut loose from each other. Integration is always expensive, and sometimes the benefit is small. Declare a Bounded Context to have no connection to the others at all, enabling developers to find simple, specialized solutions within this small scope.

Big Ball of Mud

As we survey existing systems, we find that, in fact, there are parts of systems, often large ones, where models are mixed and boundaries are inconsistent. Draw a boundary around the entire mess and designate it a Big Ball of Mud. Do not try to apply sophisticated modeling within this Context. Be alert to the tendency for such systems to sprawl into other Contexts.

To sum up, understanding various context mapping techniques allows a more effective integration between Bounded Contexts. It is also important to think about whether integration is necessary and brings benefits to the business in the first place. Using multiple approaches at the same time is also acceptable and sometimes preferred. For example, having a RESTful API naturally provides OHS, but at the same time, the downstream may also be encouraged to implement its own ACL, especially when the upstream service is by third party. You and your team will be the best people to decide which approaches to use based on the respective situation.

If you want to get more information about Context Mapping, visit https://github.com/ddd-crew/context-mapping

For more information about DDD in general, I can only recommend the book Implementing Domain Driven Design by Vaughn Vernon

Reflection

What went good

Since this post was all about context mapping based on DDD by Eric Evans, I was able to get most of the information about this topic from the book, which was really great.

What needs improvement

Next time, I would take a quick look at some examples before I begin to read the theory. This way, I could get a clearer picture upfront about what this is all about and could connect the newly learned stuff with the example.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store