Video in progress

Explain the DDD concepts of ubiquitous language and bounded context in plain words.

Ubiquitous language means the business and the developers use the same terms, and those terms are named exactly the same in code. A bounded context is the boundary within which those terms have a single meaning; in another context the same word may mean something else.

📖 Answer

Say it is an online learning platform. The word "course":

  • in the Catalog context means a title, description, price, rating, cover;
  • in the Learning context means a sequence of lessons and the student's progress;
  • in the Billing context means a product being sold, a discount, the author's share.

If you cram all of this into one Course entity, it ends up with 40 fields, and every team changes it for its own needs. With the bounded context approach, each context has its own model, its own Course class, with only the fields it needs. They are linked through courseId.

Ubiquitous language in practice:

  • if the business says "the student completed the course", the code should have enrollment.complete(), not updateStatus(3);
  • if the business distinguishes "refund" from "cancel", the code has refund() and cancel() separately too;
  • when a new term appears, it is agreed on in conversation first and then goes into the code.

In the package structure this might look like:

com.example.catalog.Course
com.example.learning.Course
com.example.billing.Product

A bounded context is not the same thing as a microservice. Even inside a single monolith there can be several contexts, separated by modules or packages. And a microservice boundary usually shouldn't cut across a context boundary.