Domain-Driven Design in TypeScript / Module 02

Module 2: Mapping a Sale with Event Storming

Map a sale from the first hold to the payout with event storming in a Markdown file, mark the open questions, and find candidate boundaries.

On Tuesday at 10:00, a show by Kofi Asante, one of the 12 organizers, went on sale. At 10:25 he wrote to the team about a buyer who had paid at 10:12 for a hold that ended at 10:10.

“Is the seat still hers, or did someone else get it?” Kofi asked.

Nina said the seat had been free since 10:10. Omar said the buyer already had her tickets by email. Maya said the payout would not count them.

“So which of you is right?” Leo asked.

Maya, Leo and TinyTickets are invented, and so are the numbers in their story.

All three answers were true, each for one part of the code, and nobody on the team could tell the whole path of a sale. This module maps that path, from the first hold to the payout, with event storming. You keep the map as plain text in a Markdown file next to the code, and it ends with a list of open questions and four candidate boundaries.

After this module, you can:

  • write the events of a business flow in the past tense, put them in time order, and merge the duplicates
  • add the command, actor, external system, policy or passing time that causes each event in one stretch
  • mark hotspots, and trace each one to the code that raises it and the module that answers it
  • check a board against the code with grep, and find events with no code and events with two causes
  • choose pivotal events, draw candidate boundaries, and say when a session is not worth its cost

Where the code stands

Module 1 left TinyTickets with a glossary, one name for a hold, and one clock that ends it. The code is still sorted by technical layer, and no TypeScript changes in this module. Figure 1 shows the folders and the direction of each call.

(Buyers)     --+
(Organizers) --+--> [Web app] routes/ --> services/ --> db/ --> [[PostgreSQL]]
(Door staff) --+              pages/
                    [Worker]  jobs/ --> services/, db/ -------^

Figure 1: the code is sorted by layer, so the path of one sale runs through every folder.

Three answers to one question

Kofi’s buyer held a seat at 10:00, so her hold ended at 10:10. The worker runs expireHolds once a minute, and it cancelled her order before 10:11. At 10:12 her payment arrived as a webhook from the payment provider. This is what markOrderPaid does with it (an excerpt of services/orders.ts, lines 14 to 22):

    const order = await findOrderByToken(payment.metadata.order_ref, client);
    // The payment service may send the same webhook twice.
    if (order === undefined || order.status === "paid") {
      await client.query("ROLLBACK");
      return;
    }
    // A buyer who paid after the hold ran out still gets the tickets.
    await client.query("UPDATE orders SET status = 'paid', paid_at = now() WHERE id = $1", [order.id]);
    await enqueue("send_confirmation", { payment });

Pause and predict: The order is already cancelled when this code runs. What is its status after line 21, and is its cancelled_at still set?

Line 16 stops only for orders that are already paid, so the cancelled order goes on. Line 21 sets status to 'paid' and fills paid_at, and it leaves cancelled_at as the worker set it. So the row is paid and cancelled at once, and line 22 queues the ticket email. Figure 2 shows the minutes in order.

10:00  (Buyer)             holds 1 seat           hold_expires_at = 10:10
10:10  [Web app]           counts it as free      routes/holds.ts:42
10:11  [Worker]            cancels the order      cancelled_at is set
10:12  [Payment provider]  sends the payment      status = 'paid'
10:12  [Worker]            emails the tickets     jobs/send-confirmation.ts

Figure 2: for two minutes the seat was free, and then the order became paid and cancelled at once.

Each developer read that row through the code they know, so each gave a different answer (Figure 3).

Who The code they know Their answer
Nina routes/holds.ts:42 counts a pending hold only before hold_expires_at The seat was free from 10:10, so another buyer could have held it.
Omar services/orders.ts:21-22 marks the order paid and queues the email She paid, so she has her tickets.
Maya db/payouts.ts:21 counts a ticket only if orders.cancelled_at IS NULL Kofi’s payout will not include her ticket.

Figure 3: each answer is true for one file, and no file holds the whole path.

The door, which nobody mentioned, will let her in, because routes/door.ts:22 checks only status. Nobody else held the seat in those two minutes, so the show did not sell it twice. Kofi’s question was a near miss.

Leo’s question is the real problem. Leo and Kofi know the path of a sale from the business side, and each developer knows one stretch of the code. Nobody can tell the whole path, and nobody can check it. The team needs a picture of the whole sale, in the organizers’ words, that everyone can read and compare with the code.

Event storming puts the whole sale in one place

Many people, one wall, one timeline

Event storming is a workshop where domain experts and developers write what happens in a business on sticky notes and put the notes in time order along a wall. Alberto Brandolini introduced it in a 2013 blog post, and he writes the name as one word, EventStorming.

It works because it puts the people with the questions and the people who know the answers in one room, as the post says. Kofi knows what buyers complain about, Leo knows when doors open, and Nina knows the hold route. Each of them writes notes, and the wall joins their parts into one path. The notation is small, so nobody needs a lesson before writing.

The cost is people’s time. The domain experts must be there, and someone must run the session and keep it moving. Brandolini’s examples run from a couple of hours to two days. For TinyTickets, that is an afternoon of Leo’s and Kofi’s time, plus three developers.

In TypeScript, event storming produces nothing. Its output is a board, and this module keeps that board in a Markdown file.

The whole sale first, then one stretch

Brandolini’s book, Introducing EventStorming, is still in progress, and its last update was in August 2021. It splits the workshop into formats by how much detail each one adds:

  • A Big Picture session covers a whole line of business with events only, so many people can join without learning much notation.
  • A Process Modeling session takes one process and adds what causes each event.

A third format, Software Design, adds what accepts or rejects each command, and Module 7 comes back to it.

TinyTickets uses both formats on one board. The Big Picture pass covers the sale from the first show to the payout. The Process Modeling pass covers only the stretch where Kofi’s question lives, from the hold to the ticket email.

Brandolini’s 2013 post also describes a short session with events only, which he used to show new hires how a business works. Nina and Omar joined this year, so that is a second reason to start with events. The cost of the Big Picture pass is that everyone must be in the room, and the book’s preface says it suffers most when people join remotely.

Domain events say what happened, in the past tense

The notes on the wall are domain events. Evans’ Domain-Driven Design Reference (2015, p. 13) defines a domain event in one line:

“Something happened that domain experts care about.” (Evans, Domain-Driven Design Reference, p. 13)

Brandolini asks people to write each one on an orange note, as a verb in the past tense. “Payment received” is a fact that Kofi can confirm or deny, and it has a place in time. “Pay” is only a wish, and “payment” has no time at all.

This is a different “event” from a DOM event or a Node.js EventEmitter event. On the board, a domain event is a sentence about the business, not code. Evans also separates domain events from events about the software itself, such as a job that ran.

In TypeScript today, TinyTickets has no type for any event. “Payment received” is the UPDATE on line 21 of services/orders.ts, and nothing names it. Module 9 turns some of the board’s events into code. On the text board, a domain event is a line that starts with EVT:

EVT  Payment received

Rule: If nobody outside the code could notice it happen, it is not a domain event. A job, a row or a webhook is how the code makes an event happen.

Hotspots mark what the team does not agree on

A hotspot is a note that marks a problem, a risk, an open question or a disagreement, placed next to the event it is about. Brandolini’s book adds one whenever someone warns that a step does not work as planned.

Disagreement is the signal the session exists to find. When two people write different words for one event, they may mean two different things. The DDD Crew’s EventStorming cheat sheet warns that duplicates can be the same words used for different ideas. Kofi’s question is a hotspot, and so is “ticket”, which means three things.

You don’t fix a hotspot during the session. Brandolini’s 2013 post says to accept an incomplete board, because chasing completeness slows the discussion. The cost is a list of questions that grows, and it helps only if someone owns it afterwards. On this board, each hotspot points to the module that answers it.

On the text board, a hotspot starts with !!:

!!   Two buyers hold the last seat at the same moment. Who gets it?

Commands and the people who give them

Most events in a sale happen because a person asked for something. A command is a request to do something, and it leads to an event if it succeeds. Brandolini puts commands on blue notes, and the DDD Crew cheat sheet says business people may prefer the word “action”. This is not a shell command.

An actor is the person or group who gives a command, such as a buyer or door staff. Brandolini puts actors on small yellow notes.

In TypeScript, a command is a route handler today. “Hold seats” is POST /shows/:id/hold in routes/holds.ts, and a door scan is POST /door/tickets in routes/door.ts. The actor shows in who may call the route. Anyone can hold seats, but requireLogin lets only a logged-in organizer account reach the door.

On the text board, an actor’s request points at the command, and the event follows on the next line:

(Buyer) --> CMD  Hold seats
EVT  Seats held

The arrow keeps the meaning it has in every figure of the course, a request in the direction it travels.

Events that no person causes

Brandolini’s book lists four causes of an event, and a person’s command is only one of them. The other three need no person:

  • An external system is a company, service or program outside TinyTickets whose action causes an event. The payment provider is one, and its webhook tells TinyTickets that a payment was received or failed.
  • A policy is a rule of the form “whenever X happens, we do Y”. Brandolini puts policies on lilac notes. “Whenever a hold runs out, cancel the order” is one.
  • Time passing causes events too. Ten minutes after the seats are held, the hold runs out, whether anyone acts or not.

On the text board, an external system is [Name] -->, a policy starts with POL, and time passing starts with TIME. In TinyTickets, each cause lives in a different file (Figure 4).

Cause On the board In the code today
A command from an actor (Buyer) --> CMD Hold seats routes/holds.ts:13, a route
An external system [Payment provider] --> EVT Payment received routes/webhooks.ts:8, a webhook
Time passing TIME 10 minutes pass after the seats are held worker.ts:34, a setInterval
A policy after another event POL Whenever a payment is received, issue the tickets services/orders.ts:25-33, a loop

Figure 4: every event has one of four causes, and the code keeps each cause in a different place.

The cost is one more line for each event, and a longer session. So the Process Modeling pass adds causes to one stretch, not to the whole sale.

Pivotal events and candidate boundaries

A pivotal event is one of the few events after which the business is in a new phase and different people start to care. The DDD Crew cheat sheet gives “Order Placed” and “Payment Received” as examples. It credits the idea to Brandolini’s essay “Discovering Bounded Contexts with EventStorming”.

When the people who care change, their words change too. Before “Doors opened”, a ticket is something a buyer paid for. After it, a ticket is a code that door staff scan. The stretches between pivotal events are a first guess at where TinyTickets could split, and this course calls them candidate boundaries (Figure 5).

Shows        | Sales               | Door           | Payouts
Show added   | Sale opened         | Doors opened   | Show ended
             | Seats held          | Ticket scanned | Payout sent
             | Payment received    |                |
             | Tickets issued      |                |
             | Tickets emailed     |                |
(Organizer)  | (Buyer)             | (Door staff)   | (Organizer)
             | [Payment provider]  |                | [Payment provider]

Figure 5: three pivotal events cut the sale into four stretches, and each stretch has its own people.

A pivotal event marks where new people start to care, not where the old work stops. Buyers can still hold seats after doors open, because the hold route has no time check.

Brandolini’s book also says that grouping notes by time and grouping them by responsibility give two different pictures. The timeline drives the big picture, and responsibility drives the design of the software. So this module draws candidates from the timeline, and Module 7 groups by responsibility. The cost is that candidates are guesses, and Module 3 tests each one before it becomes a folder.

A board in a Markdown file

Brandolini’s tool is a long paper roll on a wall. This course keeps the board in BOARD.md, next to GLOSSARY.md, with one line per note and time running down the page. Each kind of note has a fixed prefix, and the file starts with a notation block that lists them.

A text board lives in the repository, so changes go through a pull request, and grep can check it against the code. The cost is real. One person types while the others talk, so nobody writes in parallel, and a file has far less room than a wall. Online whiteboards such as Miro and Mural give a remote team a shared wall, and this course recommends none of them.

A board also goes stale, because it shows what the team knew on one day. So the file tells the reader to check the code first. Brandolini’s book suggests adding a kind of note only when the group needs it. This board has eight kinds, and later modules add more.

Map the sale, step by step

Each step says why, what to do, the text or code, and what you should see. Run the commands in the project folder that Module 1 left.

Step 1: Write the events alone, from memory

Why: each person knows one stretch, and writing alone first gets every stretch on the board before anyone argues. The DDD Crew cheat sheet starts a Big Picture session the same way.

What to do: the team wrote for ten minutes, each person alone, and typed the notes in the order they were written. Save them as BOARD.md:

# A 10:00 sale, first draft

Each person wrote alone, from memory, for ten minutes. The name at the end
of each line says who wrote it.

    EVT  Show announced                  Leo
    EVT  Sale opened                     Leo
    EVT  Buyers paid                     Leo
    EVT  Buyers came in                  Leo
    EVT  Money arrived                   Leo
    EVT  Reservation made                Kofi
    EVT  Payment made                    Kofi
    EVT  Tickets emailed                 Kofi
    EVT  Seats held                      Nina
    EVT  Hold ran out                    Nina
    EVT  Order cancelled                 Nina
    EVT  Webhook received                Omar
    EVT  Order marked paid               Omar
    EVT  Tickets issued                  Omar
    EVT  send_confirmation job queued    Omar
    EVT  Confirmation email sent         Omar
    EVT  Ticket scanned                  Maya
    EVT  Show ended                      Maya
    EVT  pay_organizers job ran          Maya
    EVT  Payout sent                     Maya

The indent of four spaces makes each block a code block when the file is shown as Markdown. Commit the draft, so Git keeps the raw notes:

git add BOARD.md
git commit -m "Add the first draft of the sale board"

What you should see: 20 events, grouped by who wrote them. They are not in time order, and several of them say the same thing in different words.

Step 2: Check the draft against the glossary

Why: some notes use words that the glossary says to stop using, and some use the code’s words instead of the organizers’. grep finds both.

What to do: search for the glossary’s “Do not say” words and for words that belong to the code:

grep -niE "reservation|pending order|webhook|job" BOARD.md

What you should see:

11:    EVT  Reservation made                Kofi
17:    EVT  Webhook received                Omar
20:    EVT  send_confirmation job queued    Omar
24:    EVT  pay_organizers job ran          Maya

Kofi wrote “reservation”, the word that Module 1 retired. Omar and Maya wrote what the code does, a webhook and two jobs, and no organizer sees any of those happen.

But grep misses the worst duplicates, because they use different words for one fact. “Buyers paid”, “Payment made”, “Webhook received” and “Order marked paid” are one event. You find that only when the notes are in time order.

Step 3: Put the events in time order

Why: in time order, duplicates sit next to each other, and gaps show as jumps.

What to do: the team read the draft aloud from Leo’s first note to Maya’s last, and merged every set of notes that meant one thing (Figure 6). Replace BOARD.md with this:

# A 10:00 sale, from the first hold to the payout

The event storming board of one sale at TinyTickets, written by Leo, Kofi,
Maya, Nina and Omar. Time runs down the page. The board shows what the team
knew on the day of its last commit, so check the code before you trust a
line.

## Notation

    EVT  Seats held             a domain event, in the past tense
    CMD  Hold seats             a command, a request to do something
    (Buyer)                     an actor, a person who gives a command
    [Payment provider]          an external system
    -->                         a request, in the direction it travels
    POL  Whenever X, do Y       a policy, what we always do after X
    TIME 10 minutes pass        time passing
    !!   Who gets the seat?     a hotspot, a problem or an open question
    ===  EVT  Sale opened  ===  a pivotal event, where a new phase starts
    Candidate: Sales            the part of TinyTickets that cares next

## The sale

    EVT  Show added
    EVT  Sale opened
    EVT  Seats held
    EVT  Payment received
    EVT  Tickets issued
    EVT  Tickets emailed
    EVT  Doors opened
    EVT  Ticket scanned
    EVT  Show ended
    EVT  Payout sent

## When the buyer does not pay

    EVT  Hold ran out
    EVT  Payment failed
    EVT  Order cancelled

Figure 6 shows where each draft note went.

Draft notes On the board Why
Buyers paid, Payment made, Webhook received, Order marked paid Payment received four names for one fact
Reservation made, Seats held Seats held the glossary’s word is “hold”
Tickets emailed, Confirmation email sent Tickets emailed one email
Buyers came in, Ticket scanned Ticket scanned one moment at the door
Money arrived, Payout sent Payout sent Leo’s money is the payout
Show announced Show added the event on TinyTickets is that a show is added
Sale opened, Tickets issued, Show ended, Hold ran out, Order cancelled the same kept as written
send_confirmation job queued, pay_organizers job ran (removed) how the code works, not an event
(nobody) Doors opened, Payment failed gaps found in time order

Figure 6: twenty notes become thirteen events, and two events come from no note at all.

What you should see: a board of 13 events. Two of them came from nobody’s draft. Leo added “Doors opened” when the timeline jumped from emails to scans, and Omar added “Payment failed” next to “Payment received”. Gaps like these show up only once the notes are in order.

Step 4: Check the board against the code

Why: the board is in the organizers’ words, and somewhere the code must make each event happen. An event with no code, or with two places in the code, changes the board.

What to do: start with “Order cancelled”, at the end of “When the buyer does not pay”.

Pause and predict: How many lines in the code set an order’s status to 'cancelled'?

grep -rn "status = 'cancelled'" *.ts db jobs routes services

What you should see:

jobs/expire-holds.ts:6:    `UPDATE orders SET status = 'cancelled', cancelled_at = now()
services/orders.ts:49:    "UPDATE orders SET status = 'cancelled', cancelled_at = now() WHERE token = $1",

Two lines, so “Order cancelled” has two causes. The worker cancels when a hold runs out, and cancelOrder cancels when the payment provider reports a failed payment. One note on the board hid two paths, and Step 5 splits them.

Next, look for code behind the first two events, and for refunds:

grep -rniE "on.?sale|refund" *.ts db jobs pages routes services migrations
grep -rln "INSERT INTO shows" *.ts db jobs pages routes services

The first command prints nothing. The second prints:

app.test.ts
seed.ts

Nothing in the code knows when a sale opens, so a show is on sale as soon as its row exists. Only the tests and seed.ts add shows, and the app has no page for it. Nothing handles a refund either. These three findings become hotspots in Step 6.

Step 5: Add the causes to the sale stretch

Why: Kofi’s question lives between “Seats held” and “Tickets emailed”. The Process Modeling pass adds the cause of each event there, and only there.

What to do: in “The sale”, replace the lines from EVT Sale opened to EVT Tickets emailed with these:

    EVT  Sale opened
    (Buyer) --> CMD  Hold seats
    EVT  Seats held
    (Buyer) --> CMD  Pay
    [Payment provider] --> EVT  Payment received
    POL  Whenever a payment is received, issue the tickets
    EVT  Tickets issued
    POL  Whenever tickets are issued, email them to the buyer
    EVT  Tickets emailed

Then replace the whole section “When the buyer does not pay” with two sections, one for each cause that Step 4 found:

## When the hold runs out

    TIME 10 minutes pass after the seats are held
    EVT  Hold ran out
    POL  Whenever a hold runs out, cancel the order
    EVT  Order cancelled

## When the payment fails

    [Payment provider] --> EVT  Payment failed
    POL  Whenever a payment fails, cancel the order
    EVT  Order cancelled

What you should see: in the stretch and the two new sections, every event except “Sale opened” has its cause on the line above or on the same line. “Payment received” comes from an external system, “Tickets issued” from a policy, and “Hold ran out” from time passing. “Order cancelled” appears twice, once after each cause.

The buyer’s “Pay” goes to the payment provider’s page, not to TinyTickets. That’s why the next event arrives from [Payment provider].

Step 6: Mark the hotspots, the pivotal events and the candidates

Why: the board now shows the questions nobody could answer, and where the people who care change. Hotspots keep the questions, and pivotal events mark the changes.

What to do: add a hotspot next to each event that raised a question in the session or in Step 4. Turn “Sale opened”, “Doors opened” and “Show ended” into pivotal events, and add a candidate after each one. BOARD.md now reads:

# A 10:00 sale, from the first hold to the payout

The event storming board of one sale at TinyTickets, written by Leo, Kofi,
Maya, Nina and Omar. Time runs down the page. The board shows what the team
knew on the day of its last commit, so check the code before you trust a
line.

## Notation

    EVT  Seats held             a domain event, in the past tense
    CMD  Hold seats             a command, a request to do something
    (Buyer)                     an actor, a person who gives a command
    [Payment provider]          an external system
    -->                         a request, in the direction it travels
    POL  Whenever X, do Y       a policy, what we always do after X
    TIME 10 minutes pass        time passing
    !!   Who gets the seat?     a hotspot, a problem or an open question
    ===  EVT  Sale opened  ===  a pivotal event, where a new phase starts
    Candidate: Sales            the part of TinyTickets that cares next

## The sale

    Candidate: Shows
    EVT  Show added
    !!   No page in the app adds a show. On the laptop, seed.ts does.
         Who adds a show on the server, and how?

    ===  EVT  Sale opened  ===========================================
    Candidate: Sales
    !!   Leo says big sales open at 10:00. The code has no sale time, so
         a show is on sale as soon as it is added.
    (Buyer) --> CMD  Hold seats
    EVT  Seats held
    !!   Two buyers hold the last seat at the same moment. Who gets it?
    !!   The dashboard's "Held" column and the "Hold my seats" button
         count held seats in different ways.
    (Buyer) --> CMD  Pay
    [Payment provider] --> EVT  Payment received
    !!   A payment came at 10:12 for a hold that ran out at 10:10 (Kofi).
         Is the order paid, cancelled, or both? Was the seat free?
    POL  Whenever a payment is received, issue the tickets
    EVT  Tickets issued
    POL  Whenever tickets are issued, email them to the buyer
    EVT  Tickets emailed
    !!   The email job is saved before the paid order is. If saving the
         order fails, does the buyer get an email with no tickets?
    !!   The email adds the booking fee to four tickets. The charge does
         not.

    ===  EVT  Doors opened  ==========================================
    Candidate: Door
    EVT  Ticket scanned
    !!   "Ticket" means a seat sold, a line of an order and a scan.

    ===  EVT  Show ended  ============================================
    Candidate: Payouts
    EVT  Payout sent
    !!   No event for a refund. What happens when a buyer wants the
         money back?

## When the hold runs out

    TIME 10 minutes pass after the seats are held
    EVT  Hold ran out
    POL  Whenever a hold runs out, cancel the order
    EVT  Order cancelled

## When the payment fails

    [Payment provider] --> EVT  Payment failed
    !!   A failed payment can come after a received one. Is a paid
         order then cancelled?
    POL  Whenever a payment fails, cancel the order
    EVT  Order cancelled

What you should see: list the hotspots. Use single quotes, because many shells read !! inside double quotes as “the last command”.

grep -n '!!' BOARD.md
17:    !!   Who gets the seat?     a hotspot, a problem or an open question
25:    !!   No page in the app adds a show. On the laptop, seed.ts does.
30:    !!   Leo says big sales open at 10:00. The code has no sale time, so
34:    !!   Two buyers hold the last seat at the same moment. Who gets it?
35:    !!   The dashboard's "Held" column and the "Hold my seats" button
39:    !!   A payment came at 10:12 for a hold that ran out at 10:10 (Kofi).
45:    !!   The email job is saved before the paid order is. If saving the
47:    !!   The email adds the booking fee to four tickets. The charge does
53:    !!   "Ticket" means a seat sold, a line of an order and a scan.
58:    !!   No event for a refund. What happens when a buyer wants the
71:    !!   A failed payment can come after a received one. Is a paid

Line 17 is the notation, and the other ten are hotspots. Each one comes from the code or from a gap in it. Figure 7 shows where, and which module answers it.

Hotspot Where the code raises it Answered in
“Ticket” means three things tickets, Ticket in services/pricing.ts, door_tickets Module 3
A late payment or a late failure services/orders.ts:16-21 and 47-51 Module 6
The booking fee on four tickets jobs/send-confirmation.ts:31 Modules 5 and 7
Two buyers and the last seat routes/holds.ts:38-49, no lock Module 7
The email job before the paid order services/orders.ts:22 Module 9
“Held” on the dashboard db/dashboard.ts:15 Modules 6 and 10
Adding a show, the sale time, refunds no code no module yet

Figure 7: every hotspot points at code, and most of them name the module that will answer them.

Then list the phases:

grep -nE "===|Candidate" BOARD.md
18:    ===  EVT  Sale opened  ===  a pivotal event, where a new phase starts
19:    Candidate: Sales            the part of TinyTickets that cares next
23:    Candidate: Shows
28:    ===  EVT  Sale opened  ===========================================
29:    Candidate: Sales
50:    ===  EVT  Doors opened  ==========================================
51:    Candidate: Door
55:    ===  EVT  Show ended  ============================================
56:    Candidate: Payouts

Lines 18 and 19 are the notation. The four candidates, Shows, Sales, Door and Payouts, have the same names as the subdomains from Module 1. The two lists agree here, though they need not. Subdomains sort what the business does, and candidates follow where its people and words change.

The “ticket” hotspot sits where Sales meets Door, and Module 3 starts there.

Step 7: Add the board’s new words to the glossary

Why: the board uses three words that the glossary lacks: sale, payment and scan. Each needs an entry with its names in the code, and “Sale” has none.

What to do: in GLOSSARY.md, add this entry after “Buyer”:

## Sale

The time when buyers can hold seats for a show. Big sales open at 10:00.

- Code: none. A show is on sale as soon as its row is in `shows` (see the
  hotspot under "Sale opened" in `BOARD.md`).

Add this one after “Order”:

## Payment

The money a buyer pays for an order, through the payment provider. A payment
is received, or it fails.

- Code: `createPayment` (`services/payments.ts`), `orders.payment_id`, and
  the provider's webhook events `payment.succeeded` and `payment.failed`
  (`routes/webhooks.ts`).

And this one after “Booking fee”:

## Scan

Door staff enter a ticket's code at the door, and the buyer comes in. A
ticket can be scanned once.

- Code: table `door_tickets` (`scanned_by`, `scanned_at`), `insertDoorTicket`
  (`db/tickets.ts`), the route `POST /door/tickets`, the dashboard column
  `scanned`.
- Do not say: door ticket.

If you did the exercise in Module 1, you already have “Scan”, so skip it. The entry still uses the word “ticket”, in Leo’s meaning, a seat sold with a code. In README.md, add one line at the end of the “Files” block:

BOARD.md    a 10:00 sale as events, from the first hold to the payout

No TypeScript changed in this module, so the last check is that nothing broke. Run npm run check and npm test.

What you should see: npm run check prints no errors, and npm test passes all 14 tests, as at the end of Module 1. The end of its output (from one run):

ℹ tests 14
ℹ suites 0
ℹ pass 14
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0

Commit the board and the glossary:

git add -A
git commit -m "Map a 10:00 sale with event storming"

How a hold works now, on the board and in the code

Follow Kofi’s buyer through the sale stretch. Each line of the board has a place in the code, but no line of code names its event (Figure 8):

  1. (Buyer) --> CMD Hold seats is POST /shows/:id/hold in routes/holds.ts. The route checks the form and counts the free seats (lines 38 to 47).
  2. EVT Seats held is the INSERT in insertOrder, which createHold calls (services/holds.ts:17). The new row has status = 'pending' and a hold_expires_at.
  3. (Buyer) --> CMD Pay starts when createHold asks the payment provider for a payment page (services/holds.ts:27). The route redirects the buyer there with a 303, and she pays outside TinyTickets.
  4. [Payment provider] --> EVT Payment received is the webhook POST /payments/webhook (routes/webhooks.ts), which calls markOrderPaid. Its UPDATE on line 21 of services/orders.ts is the event.
  5. POL Whenever a payment is received, issue the tickets is the loop on lines 25 to 33 of the same function, in the same transaction. Each insertTicket is part of EVT Tickets issued.
  6. POL Whenever tickets are issued, email them is the enqueue on line 22. It runs before the tickets are issued, in a different order from the board, and that is the hotspot about the email job. The worker then sends the email (jobs/send-confirmation.ts:49), which is EVT Tickets emailed.
  7. If the buyer never pays, TIME is setInterval in worker.ts:34. One UPDATE in jobs/expire-holds.ts is both EVT Hold ran out and EVT Order cancelled, up to a minute after the hold ends.
BOARD.md                                      The code
(Buyer) --> CMD  Hold seats                   routes/holds.ts:13  POST
EVT  Seats held                               services/holds.ts:17  INSERT
(Buyer) --> CMD  Pay                          services/holds.ts:27  page
[Payment provider] --> EVT  Payment received  services/orders.ts:21 UPDATE
POL  ... issue the tickets                    services/orders.ts:25 loop
EVT  Tickets issued                           db/tickets.ts  insertTicket
POL  ... email them to the buyer              services/orders.ts:22 enqueue
EVT  Tickets emailed                          [Worker] send-confirmation.ts

Figure 8: the code has a line for every note on the board, but the events have no names, and the email is queued earlier than the board says.

Going deeper

What Brandolini wrote in 2013, and what his book changed

The 2013 post describes one workshop. It used a large room, a paper roll, six to eight people, and a basic kit of four colors. Purple meant external systems, and also events caused by time. A note added to the post later says that format is no longer his favorite, and it points to the book.

The book, last updated in August 2021, splits the method into the Big Picture, Process Modeling and Software Design formats. Its colors differ from 2013. External systems are large pink notes, policies are lilac, and a green note holds the information a person reads before deciding, which Module 10 returns to.

Hotspot colors differ even inside the book, magenta in the preface and purple in chapter 2, and the DDD Crew cheat sheet says neon pink. A text board uses !!, so the color question goes away.

The book’s preface says Brandolini rewrote parts of it after 2020, because the method assumed one room with everyone in it. Big Picture suffers most when people join remotely, and the smaller formats cope better. Vaughn Vernon’s Domain-Driven Design Distilled (2016) also teaches event storming, in chapter 7.

Domain Storytelling, Event Modeling, or a talk with Leo

  • Domain Storytelling draws actors, work objects and activities as icons and numbered arrows. Choose it when the flow is about who hands what to whom, such as forms passed between people, more than about what changed. The method has a book by Stefan Hofer and Henning Schwentner.
  • Event Modeling, described by Adam Dymitruk in 2019, puts events, commands and views on a timeline, with screen sketches across the top. It writes each step as Given-When-Then. Choose it when discovery is done and the team wants a build plan, screen by screen.
  • A talk with Leo at a whiteboard costs least. The choice flips to event storming when several people each know one part and nobody knows the whole path, which is TinyTickets’ case.

Example Mapping, for the rules of one story, and BPMN, for a formal process model, sit further away.

What changed recently

  • EventStorming.com (Avanscoperta, 2025) now sorts the uses of the method by purpose: Improve, Envision, Explore and Design. The book and the DDD Crew still sort by level, and both ways are current.
  • The DDD Crew cheat sheet (last changed in October 2026) renames the design-level yellow note from “aggregate” to “constraint”, to keep DDD jargon away from business people. It calls “aggregate” a legacy word in EventStorming.
  • Brandolini’s book is still unfinished. In November 2026, its Leanpub page called it 70% complete. So the DDD Crew cheat sheet is the most current public summary.
  • Evans’ Reference (2015, p. iii) lists Domain Events among the patterns that are new since his book.

When a session is not worth it

Skip event storming when one person already knows the whole flow and can answer every question in a meeting. A small feature whose flow fits in one route handler gains little from a wall of notes. And skip it when nobody will act on the hotspots, because the questions are the session’s main output. These limits are our judgment, and no source lists them.

The text board has its own limit. With 20 people in a Big Picture session, one typist cannot keep up, so use a wall or an online whiteboard and copy the result into the file afterwards.

Check yourself

  1. Which four draft notes became “Payment received”, and why did grep find only one of them?
Answer

“Buyers paid”, “Payment made”, “Webhook received” and “Order marked paid”. grep found “Webhook received” because it searched for a word from the code. The other three use different words for one fact, so they showed up only when the notes were in time order.

  1. Name the four causes of an event, with one TinyTickets example each.
Answer
  • A command from an actor, such as a buyer’s “Hold seats”.
  • An external system, such as the payment provider’s “Payment received”.
  • Time passing, such as a hold that runs out after 10 minutes.
  • A policy after another event, such as “whenever a payment is received, issue the tickets”.
  1. What does a hotspot mark, and why doesn’t the team fix it during the session?
Answer

A problem, a risk, an open question or a disagreement, next to the event it is about. Fixing it would keep the session from covering the whole flow, and Brandolini says to accept an incomplete board. On this board, each hotspot names the module that answers it.

  1. What did grep on the code show about “Order cancelled” and “Sale opened”?
Answer

Two lines set status = 'cancelled', one in jobs/expire-holds.ts and one in cancelOrder, so “Order cancelled” has two causes and two paths. No code knows when a sale opens, so “Sale opened” has no code and got a hotspot.

  1. What is a pivotal event, which three did the team choose, and when would you skip the session?
Answer

An event after which the business is in a new phase and different people care. The team chose “Sale opened”, “Doors opened” and “Show ended”. Skip the session when one person already knows the whole flow, or when nobody will act on the hotspots.

Exercise: add the causes to the payouts stretch

The payouts stretch has one event and one hotspot.

Read jobs/pay-organizers.ts, db/payouts.ts (lines 5 to 15) and line 35 of worker.ts. Then add the causes of “Payout sent” to BOARD.md, and one new hotspot from what you read. Which of the four causes starts a payout? Don’t change any code.

Solution

The stretch now reads:

    ===  EVT  Show ended  ============================================
    Candidate: Payouts
    TIME 5 days pass after the show
    POL  Whenever a show ended 5 days ago, pay its organizer
    EVT  Payout sent
    !!   The transfer goes out before the payout is saved. If the worker
         stops between the two, is the organizer paid twice?
    !!   No event for a refund. What happens when a buyer wants the
         money back?

Time passing starts a payout. The worker queues pay_organizers every hour (worker.ts:35), and listShowsToPay picks shows whose date is five or more days ago (db/payouts.ts:12). No actor gives a command. The payment provider makes the transfer, but TinyTickets asks it to, so it is not written as [Payment provider] -->.

The new hotspot comes from jobs/pay-organizers.ts, lines 9 to 15. sendTransfer runs before insertPayout, so a crash between them leaves no row, and the next run pays again. You may also have noticed that payouts skip orders with cancelled_at set. That is Kofi’s question again, and it is already on the board under “Payment received”.

Cheat sheet

Cheat sheet

  • Event storming: domain experts and developers put the events of a business flow in time order.
  • Domain event: something that happened that the experts care about, in the past tense.
  • Two passes: Big Picture with events for the whole flow, then Process Modeling with causes for one stretch.
  • Four causes: a command from an actor, an external system, time passing, a policy.
  • Hotspot: a problem or open question, marked next to its event and left open.
  • Pivotal event: where a new phase starts; the stretches between them are candidate boundaries.
  • Checks: grep the board for retired words, and grep the code for each event.
  • Text board: reviewed and searched like code, but slower to write than a wall.

Figure 9 is the whole module in one picture.

Write alone     EVT lines, past tense, from memory
Time order      merge duplicates, fill gaps, grep for retired words
Check the code  grep: two causes, or no code at all
Causes          (Actor) --> CMD   [System] --> EVT   POL   TIME
Hotspots        !! next to the event, each with the module that answers it
Phases          === pivotal event ===   Candidate: Shows, Sales, Door, Payouts

Figure 9: a board grows in six passes, from notes written alone to phases with names.

The code is the same as after Module 1, with BOARD.md beside it and three new glossary entries. Next, Module 3 turns the four candidates into bounded contexts, starting with “ticket”, which means one thing in Sales, another at the Door and another in Payouts.

Sources