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

What is a ticket?

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.

ContextPurposeUbiquitous language
Events & VenuesWhat is on, where and whenevent, performance, venue, seat map, price category, on-sale date
ReservationsWhich seat belongs to whom, right nowseat, hold, release, sell, inventory, allocation
PaymentsMoving money exactly onceorder, charge, refund, payer, payout, idempotency key
FulfilmentTurning a sold seat into something to show at the doorticket, barcode, wallet pass, delivery, reissue
CustomerFan accounts, contact details and preferencesaccount, fan, contact details, consent, my tickets
EntryLetting the right people in at the doorscan, 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

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

Key Takeaways

Further Reading

Domain Design overviewThe whole series: from bounded contexts to aggregates, all on Roarline.