Geolocation using Redis | Nearby Application | System Design



Geolocation using Redis | Nearby Application | System Design

Geolocation using Redis | Nearby Application | System Design

How do we deal with geographic locations? Location is becoming extremely important now a days for any systems:

1. nearby petrol pumps OR restaurants
2. Food delivery apps
3. Tracking the rider or cab in real time.

So, you can see there are multiple use cases where you need to deal with locations. The operations should be fast, for example here you can see I am searching for Chinnaswamy stadium from my work location and shows a list of other places with the distance. In this video I am going to share how do you deal with geo location.

For calculating distance, we are going to solve the arial distance only , And not the shortest path and what turn OR road you need to take to reach somewhere. That is a separate problem statement and should be dealt separately. You can see all the apps and services use the combination of two.
Redis is the best solution. It is most simple to use. Almost all organisation use redis in one or the other form. So, you do not have to integrate anything new to make it work. You can just use the same existing Redis for distance calculations .
Since it is in memory dba and takes backups in background. So, you get great performance as well. So, number of people search for location OR continuously updating your food delivery rider location will not impact the system.
It uses the same Haversine formula we saw. It follows multiple GEO standards and supports the lat long as below.
You can see in most of the cases -85 to +85 lat long is enough.

Using https://en.wikipedia.org/wiki/Haversine_formula, we can get max error of 0.55% , but in most cases below 0.3%. This 3 meter error in every 1km. Here is more read http://www.movable-type.co.uk/scripts/latlong.html
There is http://www.movable-type.co.uk/scripts/latlong-vincenty.html which is accurate close to 1mm every km.

Install redis: https://redis.io/docs/getting-started/installation/install-redis-on-mac-os/

00:00 Introduction
00:53 What are we solving & not solving
02:03 Problem breakdown
03:35 Flat earth assumption
05:05 Spherical earth
07:50 Geolocation in redis
10:00 Geo operations in redis
12:20 demo
20:15 Conclusion

Follow me on Linkedin: https://www.linkedin.com/in/anubhavsri/
You can also DM me if you need guidance as a software engineer.

Comments are closed.