Live order tracking: watch the rider move, built serverless with Nami

Real-world systems
Live order tracking
Nami, cloud architect
Nami
Thank you

You built the live tracking with me.

From a ping on the rider's phone to a dot on your screen. You learned:

  • How thousands of location pings a second are taken in without hitting the database.
  • Why a stream sits in front, and why only the latest position is kept.
  • How WebSockets and a stream-triggered function push updates instead of polling.
  • How notifications, reconnects and a "last seen" state cover the bad moments.
  • How to watch how far behind the stream is.
Previous: checkout

    Read this story as text

    Live order tracking: the story, written out

    The rider's dot moves on your map and says arriving in 6 minutes. Nami, a cloud architect, builds the serverless AWS setup behind it: API Gateway, Kinesis, Lambda, DynamoDB, WebSockets, Amazon Location and SNS.

    1. How does a rider's dot move on your phone, when your phone never asks where he is?
    2. Twenty thousand riders. A new location every four seconds. Every customer sees only theirs, instantly.
    3. Three rules we must not break: Thousands of riders send their location every few seconds. Each customer sees only their own rider, right away. The dot keeps moving on a weak network.
    4. Stay till the end: the dot has a secret. Scroll.
    5. A phone that knows where it is. One tiny message: the rider's phone knows where he is. How does it find one screen, out of a million?
    6. A door that takes thousands of pings. Twenty thousand riders, a ping every four seconds: five thousand requests a second. API Gateway takes them all, no server to size. But where do they go next?
    7. Buffer first, think later. Not a database. That melts at eight pm. Each ping drops into a Kinesis stream: a buffer, ordered by rider. Who reads it?
    8. Keep only the latest spot. A function keeps only the newest ping per rider, overwriting one row. Old routes? Thrown away. But customers want a number, not just a dot.
    9. How long until it arrives? Asking for the time left on every ping would cost a fortune. So we ask Amazon Location only after a hundred metres. Now, the customer.
    10. A phone call that stays open. Your phone opens a WebSocket: a call that stays open. A function saves which connection watches which order. So what makes the dot move?
    11. Push, do not poll. Here is the magic. When the rider's row changes, a stream wakes a function, and it pushes the new spot down your connection. The server speaks first. But pocket the phone?
    12. The app in your pocket. The connection dies. So for big moments, picked up, arriving, at your door, we send a normal notification. 'Rider outside' is essential. And when you return?
    13. Reconnecting without a gap. On reconnect we instantly send the latest position. No stale dot. Now, the secret I promised.
    14. Make the dot glide. A ping every four seconds would make the dot jump. So the phone slides between pings. The server sends facts, the phone makes the magic. One last question.
    15. When the rider goes quiet. What if the rider loses signal? A frozen dot lies. After a minute we say 'last seen'. Honest beats smooth. And how do we know it works?
    16. Watch the stream. One number: how far behind the stream reader is. Thirty seconds late means a thirty second old dot. That is my alarm. Ready?
    17. The whole picture. That is one ping, phone to screen. Trace it yourself, or open the full diagram.

    More stories on Real-world systems