No history yet

Strategic Domain Design

The Blueprint for Microservices

The hardest part of building microservices isn't the technology; it's deciding where to draw the lines. A poor choice leads to a 'distributed monolith'—a system with all the complexity of microservices but none of the benefits. Strategic Domain-Driven Design (DDD) provides the blueprint to get this right. It’s not about code patterns; it's about aligning your software architecture with the reality of the business.

Finding Your Core Domain

Before you can draw boundaries, you must understand the landscape. Not all parts of a business are equally important. DDD forces you to classify parts of your system into subdomains.

Your goal is to map each microservice to a single, well-defined business subdomain.

There are three types of subdomains:

  • Core: This is the secret sauce, the part of the business that provides a unique competitive advantage. For a ride-sharing app, this might be the algorithm that matches riders with drivers.
  • Supporting: These are necessary for the business to function but aren't a key differentiator. They are often custom-built. In our ride-sharing example, this could be the user profile management system.
  • Generic: These are solved problems that can be handled by off-the-shelf software. Think authentication or payment processing. You don't gain an advantage by building these yourself.

By identifying your , you know where to invest your best resources and talent. Generic subdomains can be outsourced or handled by a library, and supporting subdomains can be built with less complexity. This classification is the first strategic step in defining your microservices.

Once subdomains are identified, you can define a Bounded Context for each one. This is a critical concept: it's an explicit boundary within which a specific domain model is consistent and self-contained. Inside a Bounded Context, every term has a specific, unambiguous meaning.

Ubiquitous Language

noun

A shared, rigorous language developed by the team, composed of terms from the business domain, used in all communication and in the code itself.

For example, in an e-commerce system, a 'Product' inside the 'Inventory' context might include attributes like warehouse_location and stock_level. But in the 'Marketing' context, a 'Product' might have display_name and target_demographic. They are both called 'Product', but they are different models serving different purposes. Each lives in its own Bounded Context, with its own Ubiquitous Language. A microservice should ideally implement a single Bounded Context.

Managing Service Relationships

Microservices don't exist in a vacuum. They need to communicate. Context Mapping is a strategic DDD pattern for visualizing and managing the relationships between Bounded Contexts. Instead of letting teams integrate in a chaotic, ad-hoc way, you define explicit patterns for their interaction.

PatternDescriptionWhen to Use
Shared KernelTwo teams agree to share a common subset of their domain models.When there's significant functional overlap that can't be easily separated. Use with caution.
Customer-SupplierOne context (the Supplier) provides services to another (the Customer). The Supplier's priorities are driven by the Customer's needs.When one team's success is directly dependent on another's output.
ConformistThe downstream team conforms to the model of the upstream team without question.When the upstream team has no motivation to support the downstream team, or when integration is simple.
Anti-Corruption LayerThe downstream team builds a translation layer to protect its model from being corrupted by the upstream model.When the upstream model is complex, messy, or changes frequently. This is a key pattern for maintaining autonomy.

Choosing the right pattern is a crucial architectural decision. An (ACL) is a defensive pattern that isolates your service. It translates data from another context's model into a model that makes sense for your own domain, preventing 'leakage' from other contexts. In contrast, a is a collaborative pattern where two teams agree on a common piece of the model. This creates tight coupling, which should be used sparingly and only when absolutely necessary.

Strategic DDD is about the big picture: identifying subdomains and defining the relationships between them. Tactical DDD involves the implementation details within a single Bounded Context, like Aggregates and Entities. Always start with strategy.

Applying these strategic design patterns helps you create a blueprint for a system of autonomous, well-defined services. This upfront thinking is the most effective way to prevent the creation of a distributed monolith and build a microservice architecture that is truly scalable and maintainable.

Quiz Questions 1/5

What is the primary risk of poorly defined boundaries when designing a microservice architecture?

Quiz Questions 2/5

In a ride-sharing company, a custom-built system for managing driver profiles and documents is essential for operations but doesn't offer a direct competitive advantage over rivals. According to DDD, which type of subdomain would this be?