Design Google Map
Design Google Map
Ref: Original Video
Ref: 系统设计系列讲解 Design Point of Interest (POI) or Nearby Interests
Ref: 老印的这个视频讲解了 quad tree 和 Hilbert Curve 的一些原理:Food delivery algorithms: Designing a location database
Requirements
Design a google map service
Support display maps for certain cities(San Francisco, Seattle etc)
Support tracking the user movement(GPS, telematics data)
Support routing from place A to place B
Support the place look up service
(Bonus) Tracking of the traffic
(Bonus) tracking of traffic light etc
High-level design
location service: get location related info that we collect from users
navigation service: communicate with user for navigation
Spark Streaming cluster: All location pings coming into Kafka will be read by a spark streaming service, which can then use this information to add unidentified roads in our data, identify hot spots, identify change in avg speed etc.
graph processing service: processing and rendering map graph to user
area search service: covert locations to coordinates; search given locations
Traffic
Google Map: 1 billion monthly user
Read/Write Ratio:
Location service: 1 : 1
Navigation service: 1 : 10^5
Graph processing service: 10^5 : 1
area search service: 10^5 : 1
Database
Data schema
Uber uses a Hexagon to index each of the spatial data
storing 4 points of (latitude, longitude), area, road length, locale, etc.
Ref this doc
sample data:
Database selection
use Graph Database: like neo4j
Read this neo4j spatial search doc, explaining how to do location based search, route finding, etc.
Cassandra also has GeoSpatial support
use BinTree to store geo data(Store)
Algorithms
Ref this doc: Damn Cool Algorithms: Spatial indexing with Quadtrees and Hilbert Curves
Quadtrees
Quadtrees are a very straightforward spatial indexing technique.
Each node represents a bounding box covering some part of the space being indexed, with the root node covering the entire area.
To query a quadtree, starting at the root, examine each child node, and check if it intersects the area being queried for. If it does, recurse into that child node. Whenever you encounter a leaf node, examine each entry to see if it intersects with the query area, and return it if it does.
Geohashes("Z" shape)
At this point, you can actually throw out the quadtree itself - the node number, or geohash, contains all the information we need about its location in the tree.
Each leaf node in a full-height tree is a complete geohash, and each internal node is represented by the range from its smallest leaf node to its largest one.
Range Query: Thus, you can efficiently locate all the points under any internal node by indexing on the geohash by performing a query for everything within the numeric range covered by the desired node.
Hilbert Curves("U" shape)
Hilbert Curves are part of a class of one-dimensional fractals known as space-filling curves, so named because they are one dimensional lines that nevertheless fill all available space in a fixed area.
Sharding
Based on the business model with region-based sharding
One problem with region-based sharding is that the server for a region that is more popular can become overloaded with requests in comparison to servers of regions that aren’t as popular.
Consistent hashing use LocationID
new POI's
LocationID
will be put through a hash functionquery proximity places will use an aggregation server to aggregate geohashing server data. (Use Yelp's design graph as an example below)
Questions
Support tracking the user movement(GPS, telematics data)
use navigation service, constantly upload location data(latitude, longitude)
Support routing from place A to place B
It has been discussed in neo4j's design: https://neo4j.com/blog/building-spatial-search-algorithms-neo4j/
Dijkstra algorithm, which considers weights. As such, Dijkstra will always find the shortest path based on weights. However, it doesn’t go very fast because it’s searching in all directions. It starts from one side and just searches in all directions until it finally finds the other node.
A* search is more clever. You give it two functions, one for the weights and the other one for a preferred direction Or it’s an additional cross-function, which in our case implies a preferred direction. A Star tends to be much faster.
Support the place look up service
Elasticsearch
Tracking of the traffic
Collect user's upload data for analysis
Last updated