What Starbucks Can Teach Us About Asynchronous Messaging and Two‑Phase Commit
The article uses Starbucks' coffee‑ordering workflow as a real‑world analogy to explain asynchronous messaging patterns, correlation challenges, exception handling strategies, and why two‑phase commit can hinder scalability, illustrating how everyday processes inspire robust distributed system designs.
1. A Cup of Hot Chocolate (Hotto Cocoa o Kudasai)
After a two‑week trip to Japan, the author observed the massive number of Starbucks stores in Shinjuku and Roppongi and wondered how Starbucks handles orders.
Starbucks maximizes orders by using an asynchronous workflow: the cashier marks the cup, places it in a queue (the line of cups on the coffee machine), decoupling cashier and barista so the cashier can keep taking orders.
2. Correlation
Because the order of coffee completion may differ from order placement, Starbucks must correlate each finished cup with the correct customer. In the US they write the customer's name on the cup; elsewhere they may use the drink type as an identifier.
3. Exception Handling
Starbucks deals with failures similarly to asynchronous messaging systems:
If payment fails, they discard the coffee or remove the cup from the queue.
If the coffee is wrong or unsatisfactory, they remake it.
If the machine breaks, they refund.
3.1 Discard
The simplest strategy is to do nothing or discard the work, which is acceptable when the loss is small.
3.2 Retry
When an operation fails, you can either roll back completed steps or retry the failed ones. Retry is viable if the failure is transient (e.g., an external system is down).
3.3 Compensation
Compensation rolls back all completed actions to restore consistency, such as refunding a charge in a financial transaction.
4. Two‑Phase Commit
Applying two‑phase commit to Starbucks would require a prepare phase (order placed, receipt printed, cash held) and an execute phase (cash, receipt, and coffee exchanged simultaneously). This would drastically reduce throughput.
5. Conversation Pattern
The coffee ordering process exemplifies a simple conversation pattern: a short synchronous interaction for ordering and payment, followed by a longer asynchronous interaction for preparation and delivery. Similar patterns appear in e‑commerce, where order numbers are assigned synchronously and fulfillment happens asynchronously, with compensation and retry mechanisms.
Observing everyday asynchronous processes can inspire robust message‑oriented system designs.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
