Video in progress

What is a bounded context? Explain with a simple example.

A bounded context is a boundary within which one model and its terms are used with a single meaning. For example, a "product" in the catalog lives with a description and pictures, while in the warehouse it's only a quantity and a location. Those are two different contexts.

📖 Answer

The term comes from DDD (Domain-Driven Design). The main idea: in a large system the same word means different things in different places, and you shouldn't try to cram that into one "universal" class.

An example, "customer" in an online store:

  • in the sales context, it's a name, discounts and a cart;
  • in the delivery context, it's an address and a phone number;
  • in the billing context, it's card and invoice details.

If you gather everything into a single Customer class, it turns into an object with 60 fields that's used everywhere and that nobody dares to change.

In microservices, a bounded context is a good candidate for a service boundary. Each context keeps its own Customer model and exchanges only an ID and the minimum necessary data with other contexts.