Scaling Graph Algorithms: System Design of Google Maps Routing

Explore the intricate system design behind Google Maps' industry-leading routing engine in this insightful article. From graph algorithms to real-time data utilization, uncover the core principles and innovative strategies that power optimal route finding. Learn about techniques such as A-star search and hub-partitioning, which transform complex networks into seamless navigation experiences, all while delving into the challenges of ETA calculation and traffic detection. Discover how Google Maps merges technology with practical optimization to redefine modern navigation.

In an era where every turn, intersection, and shortcut matters, Google Maps stands as the leader in navigation technology. The algorithms, databases, and real-time data that power this application helps users move around the world.

This article will delve into the system design of Google Maps Routing Engine considering its product and technical requirements.

Main Idea

At its core, Google Maps maps places and tracks users. With this, the application offers features like routing and finding nearby restaurants. These functionalities are enabled using graph algorithms, artificial intelligence, and real-time data as shown below.

Finding the Optimal Route

Let's start simple: How would you find an optimal route between a given source and destination?

For a single source-destination pair, you may have thousands of intermediate points, that permute into millions of potential paths. No graph algorithm can iterate over this web efficiently.

1: Define the problem correctly.

The problem of finding an optimal route between two points using a precise algorithm like breath first search or Dijikstra is slow. To speed things up, we will resort to approximations.

One approximation that most people start with is Cartesian distance. This simplifies the problem as a distance optimization problem.

However, this won't work.

You cannot cross the park using your car, so cartesian distance is a poor approximation for road networks

Figure 1. Me trying to get to the library when the new Game of Thrones book comes out.

Cartesian distance is a poor indicator of ETA in a road network. Not all points are connected in this topology (you cannot cross a park using your car).

So we must resort to using an approximate algorithm that works over a Network Topology: we must choose from the set of path-search algorithms.

2: Reduce the search space.

In the case of road networks, bigger is better. So we do the sensible thing: Choose wide streets.

This ensures you don't get stuck in unknown gulleys or off-beat roads. Wide streets are likely to be faster, have fewer traffic stops, and are less prone to dead-ends.

This technique of choosing a path on principle is called a heuristic, and the result of this action is called Pruning.

In the case of Google Maps, the pruning step is fulfilled by an algorithm called A-star search.

3: Reduce the size of the problem.

Every path could have thousands of intermediate points. Wide streets reduce the solution search space, but not the problem.

Go back to the idea of manually finding a route. If you need to learn how to get from a source to a destination, you will likely ask a friend!

"Hey, how do you get to 12th Baker Street, Marylebone, London?

"No."

"Do you know how to get to Marylebone, London?"

"Yes. Just take this right, followed by…."

Aha! The idea is to look for regions! We can reduce many points in our graph to hubs (points representing the entire region).

We then restrict our thinking to "Get to the centroid of the current region and then find the best path to the destination region".

And looking for hubs helps you reduce the number of intermediate points to manageable ones.

By reducing our search space with hubs and hueristics we are able to converge on an optimal path
Figure 2. Me finally managing to get to the library.

This method of reducing points in a set is called Sieving. Sieving in Google Maps is performed by an algorithm called hub-partitioning.

These ideas may not yield optimal paths for every source-destination pair, but they significantly reduce the time to converge on an answer. Thinking as a customer, our requirements prioritize speed and safety of routes more than small optimizations on time to travel.

There are many more things to consider in the system design of Google Maps.

  1. Choosing the right database for Maps
  2. Finding nearby restaurants or stores
  3. Detecting traffic jams and updating routes
  4. Efficiently calculating an ETA

All of these are hard problems, but estimating a time of arrival for a massive network with millions of connected devices is a thing of itself.

The discussions around these problems are in our Google Maps chapter here.

Wrapping Up

The system design of Google Maps is a fusion of innovative graph technology with common-sense optimizations. Google Maps transforms webs of roads and intersections into a network of traversable connections to provide a seamless navigation experience.

The system design of Google Maps describing how servers and databases work together to serve real-time routing requests
Figure 3. Google Maps System Design Diagram

Feel free to leave your thoughts and suggestions in the comments below. And if you liked the content, please register to get notifications for new articles.

Cheers!

Start Preparing for your Dream Job today!

The most comprehensive Interview prep platform ever built

Start Prep