Domain Design · Part 1
Bounded Contexts: What Is a Ticket, Anyway?
The first version of Roarline had one Ticket class. Everybody used it: the seat reservation code, the payment code, the code that sends PDFs, the scanner app at the door. It was convenient, and it kept growing.
Then a fan lost their ticket, and support reissued it. Fulfilment set status = "reissued". The scanner app only let in tickets with status = "valid". On the night of the concert, every fan with a reissued ticket was turned away at the door. Nobody had done anything wrong. Two parts of the system simply meant different things by the same word.
One Word, Many Meanings
Pick a word and see what each part of Roarline actually means by it. Then switch to One shared model to see what the first version looked like.
Term explorer
Bounded Contexts
A bounded context is a boundary inside which a model and its words have exactly one meaning. Inside Reservations, a "seat" is something that can be held, sold or released, and nothing else. Inside Entry, a "door code" is valid, scanned or invalidated, and nothing else. Each context gets a model that is small enough to understand and change on its own.
The idea comes from Eric Evans' book Domain-Driven Design (2003), and it is the most useful part of it. You don't try to build one perfect model of "the ticket" that pleases everyone. You accept that different parts of the business see the world differently, and you draw a line around each view.
One model per context, not one model per company. The urge to create a single, canonical data model for the whole organisation is natural, and it is exactly what produced Roarline's 19-field Ticket class, with one status field that meant four different things.
Ubiquitous Language
Inside a context, developers and domain experts use the same words for the same things: in meetings, in tickets, in documentation and in the code. If the box office team says "release the hold", the code says hold.release(), not ticket.setStatus(3). This shared vocabulary is called the ubiquitous language. "Ubiquitous" means it is used everywhere, but only inside its own context.
| Context | Purpose | Ubiquitous language |
|---|---|---|
| Events & Venues | What is on, where and when | event, performance, venue, seat map, price category, on-sale date |
| Reservations | Which seat belongs to whom, right now | seat, hold, release, sell, inventory, allocation |
| Payments | Moving money exactly once | order, charge, refund, payer, payout, idempotency key |
| Fulfilment | Turning a sold seat into something to show at the door | ticket, barcode, wallet pass, delivery, reissue |
| Customer | Fan accounts, contact details and preferences | account, fan, contact details, consent, my tickets |
| Entry | Letting the right people in at the door | scan, gate, door list, admitted, invalidated |
Notice that only Fulfilment has a ticket in its model. Customer merely lists purchases under "My tickets", because that's what fans call them. Reservations sells seats, Payments charges orders, Entry scans codes. Choosing names this carefully is half of the work.
How to Find the Boundaries
- Listen for "it depends what you mean by...". When a word needs clarification in a meeting, you are probably standing on a boundary
- Follow the experts. The box office, the finance team and the door staff are experts in different things. Each group's language is a strong hint for a context
- Look at the lifecycles. A seat hold lives ten minutes; a payout lives until the show is over; a door code lives for one evening. Different lifecycles, different models
- Watch how things change. Pricing rules change weekly, door scanning rarely. Parts that change at different speeds want to be separate
- Check who owns it. A context is usually owned by one team. If three teams need to agree on every change, the boundary is in the wrong place
Crossing Boundaries
Contexts still need to work together. They do it by translating, not by sharing models. When Reservations sells a seat, it publishes a small fact: SeatSold { seatId, eventId, holderId }. Fulfilment listens and creates its own ticket, in its own words, with its own fields. Entry receives a door list with barcodes, nothing more. No context reaches into another's tables.
Publishing those events reliably is a problem of its own; the transactional outbox simulation shows why. How contexts relate to each other, who adapts to whom, is the topic of part 2: context mapping.
Bounded Contexts Are Not Microservices
A bounded context is a model boundary, not a deployment unit. Roarline is a modular monolith: five of its contexts are modules inside one application, each with its own schema in one database. The sixth, Entry, lives in the scanner app on the door staff's phones. You can see them as components in the C4 diagram. Good context boundaries make it possible to split a module into a service later. They don't require it.
Common Mistakes
- The canonical data model. One shared
CustomerorTicketfor the whole company, which everybody depends on and nobody can change - Boundaries along technical layers. "Frontend", "backend" and "database" are not contexts. Contexts follow the business
- Sharing tables across contexts. If two modules read and write the same table, they share a model, whatever the diagram says
- Translating nothing. Passing another context's objects straight through your code imports its language and its bugs
- Too many tiny contexts. A context should hold a meaningful piece of the business, not one entity
Key Takeaways
- The same word often means different things in different parts of a business, and that's fine
- A bounded context gives each meaning its own model, small enough to understand
- Inside a context, code and conversations use the same ubiquitous language
- Contexts cooperate by translating, usually through events, not by sharing models
- A bounded context is a model boundary; it can be a module just as well as a service
Further Reading
- Vlad Khononov - Learning Domain-Driven Design: a highly recommended, modern introduction, especially strong on strategic design and on connecting DDD to architecture and business strategy
- Eric Evans - Domain-Driven Design: Tackling Complexity in the Heart of Software
- Vaughn Vernon - Domain-Driven Design Distilled: a short, practical introduction
- Martin Fowler - BoundedContext
- DDD Crew - free tools and canvases, including the Bounded Context Canvas