dine. a kitchen run by sagas Book a table
Log in with Google (coming soon)

Articles

Tiếng Việt · English

How I started building dine

October 15, 2026 · about 7 min read

The article What dine is describes what dine looks like today. This one is about the order it was built in: each piece I added, why I added it, and the places I thought would be simple but turned out not to be. If you plan to build a similar system yourself, this order might save you a few rewrites.

Starting with a message queue

A booking needs three jobs: hold a table, have the kitchen take the order, charge the money. Three different services do those jobs, so first of all I needed somewhere to send commands to all three.

I chose Kafka, because Kafka has consumer groups and keeps the read position (offset) per group. That way I only need one topic to send a command to every service. I created the topic order-events.

Each service reads order-events with a consumer group of its own. Kafka keeps a separate offset for each group, so all three groups receive every message, independently of each other: a slow kitchen does not make payment wait. Messages also do not disappear once read; they stay on Kafka for a while, so a service that dies and comes back can carry on reading from exactly where it left off.

Kafka is not the only option. RabbitMQ can also deliver one message to several consumers (with a fanout exchange). What I like about Kafka is that messages are kept and can be read again, which is very handy when you need to figure out what an order went through.

A place to receive orders: dine.order

Next I needed an API to receive what users submit, and then send a message to Kafka. I created the repo dine.order.

Step 1: dine.order receives orders from users and sends commands to the order-events topic on Kafka. dine.order order API command Kafka order-events user books a table
Step 1: one API receives orders and sends commands to a single topic.

Three services that do the work

Then I thought about the services that would do the actual work: payment, kitchen, reservations. I created three more repos: dine.payment, dine.kitchen and dine.reservation. Each repo has its own database, and each service reads order-events with its own consumer group. The three services do not know about each other and do not call each other. Each one just listens for commands and does its own part.

Step 2: the reservation, kitchen and payment services all read the order-events topic, each with its own consumer group. dine.order order API command Kafka order-events dine.reservation hold seats dine.kitchen take stock dine.payment charge One consumer group per service: all three receive every command.
Step 2: one command, received by all three. Adding a new service only takes one more consumer group, with no change to dine.order.

The interface, and only then the extras

With the services in place, users needed an interface to work with. I created dine.web, the very site you are reading.

Step 3: web in front, calling order; order sends commands through Kafka to payment, kitchen and reservation. web order kafka payment kitchen reservation
Step 3: a web interface in front, where users do their part.

I added the two services dine.gateway and dine.auth later, because at first the system ran fine without them. With only one API to call, there was no need for a shared way in yet. Until outsiders could book tables themselves, there was no need for sign-in. The article API gateway explains why they became necessary later.

dine.product, the service that returns the menu, is another extra I came up with later. Right now it just provides the menu so the site can show dishes for guests to choose from. But if it grows, for example letting guests search for dishes by name or ingredient, or filter by price, then the way data is stored for writing (adding, editing dishes) and the way it is stored for searching start to diverge. That is when CQRS comes in: splitting the write side and the read side into two separate models, with the read side built specifically for searching and kept up to date from the write side. That is a story for a later article.

My first picture of the saga

At first, the saga in my head was very simple: a job that keeps sending messages to Kafka and listens for the services' replies.

But sending a message to Kafka is not just sending. The order is stored in MySQL, while the command goes through Kafka: two systems, and no transaction can span both. If the process dies right between the two steps, an order sits in the database that no service knows about. Swap the order and you can end up with a command for an order that does not exist. The two places drifting apart like that is the MySQL–Kafka inconsistency problem, and I only noticed it when I thought about the moments when the system dies halfway.

The fix is the transactional outbox: instead of sending directly, write the command as a row in MySQL, in the same transaction as the order. The order and the command either both exist or neither does. My job is still there; the difference is that it reads commands from the outbox table and only then sends them to Kafka. If a send fails, the row is still there and gets sent next time. The article Transactional outbox covers how it works in full, and where it can still go wrong.

A second topic for replies

When the services reply with their results, they cannot share the old topic either. All three are listening to order-events, so if replies went there too, each service would also receive the other two's replies, and dine.order would read its own commands mixed in with them.

So I created a second topic, saga-step-responses, used only for the way back. The three services only write to it and never read it. At first I planned a separate reply topic per service, but then every new service would mean another topic, so I merged them into one. Each reply carries the step name (step_name) so you can tell which service it came from.

dine.order listens to this second topic, and every time a message arrives it makes a decision: record that the service is done, mark the order successful once all three are done, or cancel the order and undo the services that already did their part if one fails.

Step 4: adding the way back. The three services send their replies to the saga-step-responses topic; dine.order reads that topic and decides what happens to the order. dine.order takes orders, decides command Kafka order-events dine.reservation hold seats dine.kitchen take stock dine.payment charge Kafka saga-step-responses replies order reads, decides Solid: commands going out. Dashed: replies coming back. The three services only write to the reply topic, never read it.
Step 4: two topics, one per direction. This is also the shape of dine today, apart from the outbox sitting between each service and Kafka.

Things I had not thought of at first

At this point the system worked for an order where everything went right. Most of the effort afterwards went into the orders where things go wrong:

Each of these is an article in the reading path. The next one starts from the most fundamental question: why not use one shared transaction for all three services.

See it for yourself

Spotted a mistake, or have a question? Write to [email protected].

dine is a personal project about distributed systems, written in Go: orchestrated sagas, transactional outbox, Kafka. More articles.