Read this story as text
Rider dispatch: the story, written out
A box is packed and one rider out of hundreds has to take it. Nami, a cloud architect, builds the serverless AWS setup behind that choice: EventBridge, Step Functions, ElastiCache, Amazon Location, SNS and DynamoDB.
- A bag is packed. Four hundred riders are on the road. You have seconds to pick one. How?
- The nearest? Sounds right. And is often wrong.
- Three rules for dispatch: Pick a good rider fast, not the perfect one slowly. Never give one order to two riders. Keep going when a rider says no, or says nothing.
- By the end: how one write stops two riders for one bag. Scroll.
- A box is packed. The bag is ready and a clock is running. Checkout just shouts 'order packed' on the event bus. Dispatch listens. What does it do first?
- One flow per order. It starts a workflow for this one order: looking, offered, waiting, assigned. It remembers, even if a function crashes. Next: who is near?
- Who is nearby? We cannot ask four hundred riders. Tracking keeps them on a live map in memory. 'Riders within three kilometres' takes milliseconds. But nearest is not best.
- Closest is not the best. A rider across a river is a bad pick. So the twenty nearest get scored on real road time, workload and history. Who gets the offer?
- Offer, to one rider. One rider at a time. Offering ten means nine see 'gone' and stop trusting us. One push, with a timer. Now the dangerous moment.
- Claim it, exactly once. Asha taps accept just as the timer ends and another rider taps too. One conditional write: free to busy. Only one wins. Promise kept.
- When they say nothing. No answer? The workflow waits thirty seconds, then moves on. Declines and silence take the same path. And if nobody is free?
- When nobody is free. A rainy night: empty list. Wait ten seconds, widen the circle. That empty list tells the business to find more riders.
- Stack when it makes sense. A rider already heading to this store? Give them your bag too, if the drop is on the way. Cheaper for us, often faster for you.
- Be fair, too. If the best score always wins, the same five riders get everything and the rest quit. A boost for who waited longest keeps the fleet healthy.
- Watch the clock. One number: packed to accepted. Forty seconds is fine, four minutes means cold food. I watch the slow orders, never the average.
- The whole picture. That is one order finding its rider. Trace an order, or open the full diagram.
More stories on Real-world systems