# Design Location Based App

* **Yelp** or Nearby Friends
* Proximity server

## Requirements and Goals of the System

**Functional Requirements:**

1. Users should be able to add/delete/update **Places**.
2. **Given** their **location** (longitude/latitude), users should be able to **find** **all** **nearby** **places** **within** a **given** **radius**.
3. Users should be able to add feedback/review about a place. The feedback can have pictures, text, and a rating.

**Non-functional Requirements:**

1. Users should have a real-time search experience with minimum latency.
2. Our service should support a heavy search load. There will be a lot of search requests compared to adding a new place.

## Scale Estimation

500M daily user \* 2 times per day \* 5 queries per time / 86400 seconds \~ 50k QPS

Peak hour: \* 2 \~ 100k QPS

Assuming 500M places

## Database Schema

### Each location:

1. **LocationID** (8 bytes): Uniquely identifies a location.
2. **Name** (256 bytes)
3. **Latitude** (8 bytes)
4. **Longitude** (8 bytes)
5. **Description** (512 bytes)
6. **Category** (1 byte): E.g., coffee shop, restaurant, theater, etc.

Total size: 8 + 256 + 8 + 8 + 512 + 1 => 793 bytes

### reviews, photos, and ratings of a Place

1. **LocationID** (8 bytes)
2. **ReviewID** (4 bytes): Uniquely identifies a review, assuming any location will not have more than 2^32 reviews.
3. **ReviewText** (512 bytes)
4. **Rating** (1 byte): how many stars a place gets out of ten.

## System APIs

API for searching

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

## Basic System Design and Algorithm

### Two different use case:

* Location of a place doesn’t change that often, we don’t need to worry about frequent updates of the data.
* Objects do change their location frequently, e.g., people or taxis


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aaronice.gitbook.io/system-design/system-design-problems/design-location-based-app.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
