Rider dispatch: pick the right rider in seconds, built serverless with Nami

Real-world systems
Rider dispatch
Nami, cloud architect
Nami
Thank you

You built the dispatch with me.

From a packed bag to a rider who said yes. You learned:

  • How one workflow per order remembers where it is and survives failures.
  • How a map of riders answers nearby in milliseconds.
  • How scoring uses real road time, load and fairness, not only distance.
  • How one conditional write makes sure an order has exactly one rider.
  • How timeouts, wider circles and stacking handle the messy evenings.
Next: the home feed

    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.

    1. A bag is packed. Four hundred riders are on the road. You have seconds to pick one. How?
    2. The nearest? Sounds right. And is often wrong.
    3. 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.
    4. By the end: how one write stops two riders for one bag. Scroll.
    5. 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?
    6. 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?
    7. 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.
    8. 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?
    9. 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.
    10. 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.
    11. 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?
    12. 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.
    13. 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.
    14. 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.
    15. 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.
    16. The whole picture. That is one order finding its rider. Trace an order, or open the full diagram.

    More stories on Real-world systems