Articles
Tiếng Việt · English
Notes from building dine: why one approach and not another, and the places where distributed systems go wrong. Every article is also available in Vietnamese.
Getting started 3 articles
-
What dine is, and why this site exists
Many CVs list sagas and microservices, but few people have seen them run. dine is a simulated restaurant on real services, open for anyone to watch.
-
How I started building dine
The order dine was built in: Kafka first, then order and three services, then the web, and why sending to Kafka was not as simple as it looked.
-
How one order travels through the system
An order passes through four services and Kafka. How dine records each step as one row to draw its path, and why not Jaeger or OpenTelemetry.
Saga 7 articles
-
Why saga instead of 2PC
One order goes through 3 services, a database each. Where two-phase commit gets stuck, what a saga uses instead, and the price you pay.
-
Transactional outbox: writing to the database and sending to Kafka without drifting apart
Creating an order means saving to MySQL and telling 3 services via Kafka. Why that can't be done directly, how the outbox fixes it, and where it can fail.
-
Receiving a command twice without doing it twice
In a messaging system, a command will sometimes arrive twice. How dine's services filter duplicates so stock and money are never taken twice.
-
What a saga does when a reply arrives
The services only send results to a topic and know nothing about the saga. order looks at the saga's state and the step's result to pick one of four moves.
-
Compensation is not rollback
Payment is declined after the table was held and stock taken. How a saga undoes committed work, who gets undone, and what if the undo fails too.
-
Why 5 seconds cancels an order
A service takes the command and then goes silent. Why the system cannot wait forever, how dine picked its 5-second limit, and what happens when time runs out.
-
Late success: the order is cancelled, yet a service reports done
Payment is declined and the order cancelled, then the table and kitchen report done. Why that is normal, and how dine cleans up the late work.
Data and messaging 2 articles
-
Two orders fighting over the last ingredients
2 portions of dough left, two orders need 2 each. Why read-then-subtract drives stock negative, and how dine's kitchen lets only one order win.
-
Where broken messages go
Some messages can never be processed. dine sets them aside, retries less and less often, and finally stops for a person, like a call about a stuck refund.
Operations 3 articles
-
One way in for many services: the API gateway
The dine site reaches six services through one address. What a gateway does (sign-in, CORS, rate limits, caching) and why dine wrote its own in Go.
-
Shutting down gracefully
Every deploy shuts a service down. SIGTERM vs SIGKILL, how dine stops its API and workers, and why it must stay correct even if the plug is pulled.
-
Zero-downtime deploys
One instance means a few silent seconds per deploy. How dine runs old and new side by side (blue/green) and drains the old one before stopping it.