Order State Machine: Delivered, Then Picked Up Again? @KGPTalkie
Order State Machine: Delivered, Then Picked Up Again?  @KGPTalkie
Uploaded October 2026 | Updated November 2026, 4 days ago
Delivered. Then, a moment later, picked up again. The same order, moving backwards. How does that happen?

A food order looks like one thing, but inside it moves through many states, and every step is a chance for things to go wrong. If the status is just a text column that any service can write anything into, the order ends up in a state that can't exist. The fix is an order state machine.

Step 1, list the states: placed, confirmed, preparing, ready, picked up, delivered, plus two exits, cancelled and refunded. An order is in exactly one state at a time.
Step 2, write down the allowed transitions. Placed goes to confirmed or cancelled, ready goes to picked up, picked up goes to delivered. Anything not on the list is rejected. Delivered back to preparing? Never.
Step 3, make every transition atomic: set the status to picked up, but only if the current status is ready. The database checks and updates in a single step. Zero rows updated means someone else changed the state first, so if a cancel and an accept arrive together, only one wins.
Step 4, every transition is an event, written in the same transaction into an outbox table. It notifies the customer, updates the rider app, feeds the ETA and builds the history for support, and the state can never change while the event gets lost.

Even timers are transitions: no acceptance in five minutes (an example value) moves placed to cancelled, with a refund event. No person has to remember.

The catch: events arrive late, and sometimes twice. Apply every event blindly and a delivered order goes back to picked up. The same transition table fixes it: if a move is not allowed from the current state, ignore it. A duplicate event changes nothing, because the state is already there.

Next: in today's System Design Interview reel, designing Swiggy or Zomato. Comment and tell me: has an order of yours ever shown delivered, but never arrived? Follow for the full series.

kgptalkie.com

#shorts #SystemDesign #StateMachine #BackendEngineering #DistributedSystems #FoodDelivery #OutboxPattern #SoftwareEngineering #SystemDesignConcepts #SystemDesignInterview #Microservices #KGPTalkie
Order State Machine: Delivered, Then Picked Up Again?Fable 5.2 vs Gemini 4 Argon: Same Score, 5x Cheaper?Quick and Simple Sentiment Analysis App in PythonNemotron 3.5 Lightning 33B vs Claude Haiku 5.5: Is Fast Also Good?NumPy Crash Course for Machine Learning | Arrays, Indexing, Operations and More02 RAGWire RAG Tutorial: Multi Company RAG for Financial Comparison using OllamaBPE vs WordPiece vs SentencePiece: Whats the Difference? | LLM InterviewAWS Tutorial 1 - Launching EC2 Ubuntu Machine on AWSRTX 5090 vs Used RTX 4090 for Local AI: $2,000 for 8 GB?1 Spacy Introduction for NLP | Spacy 3 Masterclass Tutorial 1 | Install Spacy on Google ColabQwen 3.6 on Ollama 🚀 Build Games in One HTML (Beats Gemma 4?)Qwen 3.8 27B in Just 6 GB- How Ternary Bonsai 2 Works
Laxmi Kant | KGP Talkie |

Order State Machine: Delivered, Then Picked Up Again?

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER