How to implement real-time tracking in applications like Swiggy, uber, and Dunzo?


How to implement real-time tracking in applications like Swiggy, uber, and Dunzo? When we talk about this question we have these aspects to handle.

  1. How to send the location
  2. How to process it and keep the data 
  3. Displaying it

Let’s start by answering these questions one by one.

How to send the location?

Sending location is easy as your mobile devices have GPS and network connectivity. Mobile devices can send their location via an HTTP call. Websockets can also be used to save the extra cost of creating a TCP connection every time which is costly due to a three-way handshake.

How to process it and keep the data 

Next is the process of saving it. The problem comes here as you will be getting a lot of requests. Now say you have around 50 thousand riders and the location is sent every 30 seconds to keep it as much real-time as possible. So the total number of requests that you will get is around 100 thousand requests per min which is 1600 per second.

Now when you are getting these number of requests it may be hard to process it on the go or say in a synchronous way, you need to have a buffer where you can keep and process these requests a few seconds later. You can use any queue system for it like rabbitmq, SQS etc. But if you want to make it work for the huge scale you may like to use something like Kafka.

How to implement real-time tracking in applications like Swiggy, uber, and Dunzo?

There will be a process running which will take these locations from these queues and process it. Now for processing you can have few workers which take these tasks do it and after getting the result to write it to a place where the last known location of drivers is stored.

Now the application can read the last known location of the driver assigned to anyone. This again can be done using WebSocket to save the connection creation overhead.

Displaying it

Now comes the third question of how to show it. Well, it is not a tough problem as google provides APIs for this purpose.

This is just a basic flow of how you can build it at scale. When you go deeper into each of these aspects you will figure out more problems. Feel free to message me if I can be of any help.

Update: Earlier the service layer between the device driver and message queue was missing in the diagram. Thanks to Abhivendra for figuring it out. Also, keep in mind there are a lot of things abstracted in this so to give you a basic understanding of how it can be done. A lot of components can be added like caching, etc.

If you like the article please share and subscribe. Also, comment if you want me to write about other system designs.

You can install our app for quick updates.


Gaurav Yadav

Gaurav is cloud infrastructure engineer and a full stack web developer and blogger. Sportsperson by heart and loves football. Scale is something he loves to work for and always keen to learn new tech. Experienced with CI/CD, distributed cloud infrastructure, build systems and lot of SRE Stuff.

3 COMMENTS
  • Itsafjal
    Reply

    worth reading , I would suggest you to elaborate more for better understanding.

  • Simo
    Reply

    Hello ,
    How can I achieve the same result if I already have the lat/lng coming from a car device ?
    I mean I want to track a car device instead of mobile device

    1. Gaurav Yadav
      Reply

      Cars can have some IOT device. Feed it to mqtt broker like emqx and then from broker can send/prcoessor can pass the data from mqtt to Kafka.After that you can process it easily.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.