Tiếng Việt · English
What dine is, and why this site exists
Microservices, sagas, event-driven: these words show up in a lot of CVs and interviews. But ask "what exactly is a saga, and how do its parts work together?" and the answer often stops at the definition. dine is a small but real, running system built to answer that question by letting you see it for yourself.
Why I built dine
I have met quite a few people who list "microservices" and "saga" on their CV without having built one themselves. Many developers have also asked me: what is a saga, concretely? How does an order move between services? When something fails halfway, who cleans up?
There is no shortage of theory on these topics; the books and articles already exist. What is missing is a system that is actually running and that anyone can open up: which order is where, which service answered when, and how the system reacts when something goes wrong. I believe building such a system yourself is the fastest way to understand it. And once it is built, it might as well be open for everyone to look at.
dine is the result: a simulated restaurant that takes table bookings, running on several real services that talk to each other through Kafka. Every order on the home page really goes through the system (some are placed by a bot, so there is always something to watch), and every order has its own page showing how it travelled through the system.
A restaurant that takes bookings
A guest picks a time, a party size and a few dishes in advance. For one booking to succeed, three things must all happen:
- reserve seats for the whole party;
- the kitchen sets aside ingredients for the chosen dishes;
- take the payment.
If any one of them fails, the whole booking must be cancelled, and whatever was already done must be undone. It sounds simple, but once the three steps live in three different services, each with its own database, the problem contains almost every hard part of distributed systems.
The services
Each service is its own repository, written in Go, with its own database, deployed on its own.
order;
everything behind it goes through Kafka.| Service | What it does |
|---|---|
order | The center of the system. Guests book through the order API. It records the
order, sends commands to the other services through Kafka, collects their replies, and decides whether the order
succeeds or has to be cancelled and undone. |
reservation | Holds seats out of the restaurant's 500. A seat is held from booking until the guest finishes eating and leaves; only then is it free again. A cancelled order releases its seats. |
kitchen | Cooks and manages supplies. Each order deducts ingredients for its dishes. When stock runs low, the kitchen restocks on its own, like a real storeroom. A cancelled order puts the ingredients back. |
payment | A simulated payment, no real money. There is no amount limit, and about 5% of charges are randomly declined so there are always failed orders to look at. A cancelled order is refunded. |
There are also a few supporting repositories: gateway, the single entry point for every API; auth, which handles Google sign-in; web, the site you are reading; one that checks the data contracts between services; and an Ansible repository that sets up the servers and deploys everything.
The three services reservation, kitchen and payment do not know about each other,
and do not know there is a saga at all. Each one listens for commands on Kafka, does its part, and replies. The only one
who knows the whole story is order.
Microservices are not just code split into repositories
Splitting an application into four repositories takes an afternoon. The hard part starts right after: everything the database used to handle for you, you now have to do yourself. These are the problems dine had to solve, each with its own article (most of them in Vietnamese for now):
- No shared transaction. Three databases cannot commit together, so a saga replaces the transaction: Why saga instead of 2PC.
- Writing to the database and sending a message must not drift apart. If the order is saved but the command is lost, the order hangs forever: Transactional outbox.
- Undoing a failure halfway through. There is no
ROLLBACK, so every step needs its own undo: Compensation is not rollback. - A service goes silent. A dead service and a slow one look the same, so there has to be a deadline: Why 5 seconds cancels an order.
- Late messages. The order is already cancelled, and then a service reports success: Late success.
- Knowing where an order is. Logs are spread across four places, so the order's path has to be recorded: How one order travels through the system.
- Two orders want the same thing. Read-then-deduct can drive stock negative, so it takes a conditional update and a lock: Two orders, one last portion.
- The same command arrives twice. Messages are not lost, but they can be duplicated, so the receiver must filter: Receiving a command twice without doing it twice.
- A message that never succeeds. It must not block the whole queue, and it must not disappear: Where broken messages go.
- One entrance for many services. Six services should not each handle sign-in and face the internet: API gateway.
- Shutting down without breaking work in progress. Every deploy shuts a service down: Shutting down gracefully.
- Deploying without a gap. Run the old and new version side by side, then retire the old one: Zero-downtime deploys.
How to explore dine
- Home page: live orders, updated every second. Click an order to see how it went through the system.
- Seats, Kitchen, Payments: each service's own data, matching the orders on the home page.
- Sample orders: six ready-made scenarios, from a clean success to a failed refund waiting for a human.
- Book a table yourself: log in with Google and press Book a table. Turn on “Incident test” to choose the order in which services reply, make one service go silent, or have the payment declined, and watch how the system handles it.
The whole site is available in English (the EN / VI button in the header switches language); most articles are still in Vietnamese and are being translated. If you are just starting, read the articles in order from the Articles page.
dine is a personal project for learning and sharing, not a real restaurant. No dish is ever cooked, and no real money is ever charged.
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.