On the next day you showed up in Mr. Sandwich’s headquarters. Both factory and office building were modern and elegant constructions, built with concrete, steel and glass. A meeting room was cosy and well-equipped space. There was a giant white board, perfect for the Event Storming session. After quick introduction about what Event Storming is, what is the role of a facilitator and what are the next steps.
Let The Session Begin
After you have handed out post-its, people started writing down events names and putting them on the wall. After 20 minutes of silence, and then removing duplicated events and putting them chronologically, the result was like on the picture below. Details about how to conduct Event Storming Workshops, can be found in Domain-Driven Design Tutorial dedicated article.
Sequence Of Events
Part 1 shows us a first Event, which is User Created. User is needed to create a Chef role in the system. It can be updated or request a password reset. To define a Dish in the Food Factory Domain, there must be two things: Ingredients and Recipe. After dealing with Dish list, there must be created a Delivery Points, they are places where Deliverer will stop and wait for the Customers, so they can pick up their Deliveries. Set of Delivery Points creates a Route. Route defines an order of Delivery Points and respective Arrival Hours for every Delivery Point. Routes can be edited, they are also assigned to a particular Deliverer at given day.
The next step is to import Dishes to the Web Store. From Web Store’s point of view, Dishes are Products. Their availability, prices and metadata are managed by the Web Store Administrator. There must be at least one Product in the Web Store to operate. After Web Store is packed with delicious food, now it makes to sense to let Customers to register their accounts. Customer may add or remove Payment Methods, so he can pay for the Order. Now, it’s time to manipulate Cart content by adding your favourite food and then Checkout. During the Checkout process, the new Order and Payment records are persisted. The Payment itself started processing at the payment agent end. It may fail or be successful, if so, Order is considered to be completed, therefore it can be added to the Deliveries for the next day.
When Food Factory reports a Dish to be cooked, Delivery matches given Product with the Order, and, if all Dishes are included, system marks the Order as Completed. Now, on a day of Delivery, a proper Deliverer is assigned to a given Routes. When Deliverer arrives to the next Delivery Point he Checks-In, so all Customers are notified about their Order waiting for them in the lobby. Customer may or may not come, if he comes, than Delivery picked up or Declined. When all goes well, then Order gets a Delivered state and its story ends here.
Aggregates
For the sake of this lesson, I will skip some Event Storming steps, which are explained in the article dedicated to this subject. Instead, you will be presented with a results of Strategic DDD phase. Let’s jump straight to the Aggregates.
Food Factory
Our first Aggregate, which by the way is required for the system to start operating, is a Chef. Chef is a person who is employed in the Food Factory, he is responsible for creating Recipes and cooking Dishes. Next we have an Ingredients and Recipes, which together form a Dish, a final product to be sold. The last Aggregate found here is Scanner, which is responsible for reporting cooked Dish.
Web Store
In this case we need to start with a Product Aggregate. It symbolizes a Dish from Food Factory, but from Store’s point of view, it doesn’t matter what merchandise it sells, so to avoid misunderstandings a Product phrase was defined. Then, there are Customers, users who may register in the Web Store and place some Orders. Orders and Carts are another Aggregates in the Web Store context, which make it possible to purchase your favourite food.
Delivery
Delivery must be delivered by the Deliverer, so this is our first Aggregate. It lets administrative user to manage list of employees delivering Orders to Delivery Points. Delivery Points are places where Deliverer will show up with your Dishes at the given hour, every day. The last aspect of Delivery is a Route, collection of Delivery Points, which have to be visited every day by the assigned Deliverer.
Users
The last, and the smallest of Aggregates is Users. It allows creating a new User in the system, but also lest Chefs, Deliverers and Customers to reset their passwords.
Summary
As you can see, the Aggregates nicely shows both, transaction and consistency boundaries. Now, we have to define existing Bounded Contexts, which will be our guides, when defining Microservices. You might be surprised, how easy it will be after Event Storming session.