Design Yelp / Nearby

Problem Statement:


Step-1: Why Yelp or Proximity Server?


Step-2: Requirements and Goals of the System


Step-3: Capacity Estimation


Step-4: Database Schema


Step-5: System APIs

Search API
search(api_dev_key, search_terms, user_location, radius_filter, maximum_results_to_return, category_filter, sort, page_token)


Step-6: Basic System Design and Algorithm


Let’s see what are different ways to store this data and find out which method will suit best for our use cases:

a) SQL Approach:
Select * from Places where Latitude between X-D and X+D and Longitude between Y-D and Y+D
How efficient this query would be?


b) Grid Approach

What could be a reasonable grid size ?
Select * from Places where Latitude between X-D and X+D and 
	Longitude between Y-D and Y+D and GridID in (GridID, GridID1, GridID2, ..., GridID8)
Should we keep our index in memory ?
How much memory will we need to store the index ?


Problems with Fixed Grid Approach:

Using Dynamically Adjusting Grid Size


c) Dynamic Sized Grids - Quad Tree Approach
What data-structure can hold this information ?

How will we build QuadTree ?
How will we find the grid for a given location ?
How will we find neighboring grids of a given grid ?
What will be the search workflow ?
How much memory will be needed to store the QuadTree ?
How would we insert a new Place into our system ?


Step-7: Data Partitioning


We will explore two solutions here (both of these partitioning schemes can be applied to databases too):

a) Sharding based on regions:


b) Sharding based on LocationID:
Will we have different QuadTree structure on different partitions ?


Step-8: Replication and Fault Tolerance

What will happen when a QuadTree server dies ?
What if both primary and secondary servers die at the same time ?
How can we efficiently retrieve a mapping between Places and QuadTree server ?


Step-9: Cache


Step-10: Load Balancing (LB)


Step-11: Ranking

We didn’t build our system to update place’s data frequently. How can we modify popularity of a place in QuadTree in this design?


Note:- Our next problem Design Uber discusses dynamic updates of the QuadTree in detail.




← Previous: Design Facebook Newsfeed

Next: Design Uber →