Files
system-design-101/data/guides/quadtree.md
Kamran Ahmed ee4b7305a2 Adds ByteByteGo guides and links (#106)
This PR adds all the guides from [Visual
Guides](https://bytebytego.com/guides/) section on bytebytego to the
repository with proper links.

- [x] Markdown files for guides and categories are placed inside
`data/guides` and `data/categories`
- [x] Guide links in readme are auto-generated using
`scripts/readme.ts`. Everytime you run the script `npm run
update-readme`, it reads the categories and guides from the above
mentioned folders, generate production links for guides and categories
and populate the table of content in the readme. This ensures that any
future guides and categories will automatically get added to the readme.
- [x] Sorting inside the readme matches the actual category and guides
sorting on production
2025-03-31 22:16:44 -07:00

1.9 KiB
Raw Blame History

title, description, image, createdAt, draft, categories, tags
title description image createdAt draft categories tags
Quadtree Explore the quadtree data structure for spatial data partitioning. https://assets.bytebytego.com/diagrams/0311-quadtree.jpg 2024-03-03 false
how-it-works
Data Structures
Algorithms

Let's explore another data structure to find nearby restaurants on Yelp or Google Maps.

A quadtree is a data structure that is commonly used to partition a two-dimensional space by recursively subdividing it into four quadrants (grids) until the contents of the grids meet certain criteria.

A quadtree is an in-memory data structure and it is not a database solution. It runs on each LBS (Location-Based Service, see last weeks post) server, and the data structure is built at server start-up time.

The second diagram explains the quadtree building process in more detail. The root node represents the whole world map. The root node is recursively broken down into 4 quadrants until no nodes are left with more than 100 businesses.

How to get nearby businesses with quadtree?

  • Build the quadtree in memory.

  • After the quadtree is built, start searching from the root and traverse the tree, until we find the leaf node where the search origin is.

  • If that leaf node has 100 businesses, return the node. Otherwise, add businesses from its neighbors until enough businesses are returned.

Update LBS server and rebuild quadtree

  • It may take a few minutes to build a quadtree in memory with 200 million businesses at the server start-up time.

  • While the quadtree is being built, the server cannot serve traffic.

  • Therefore, we should roll out a new release of the server incrementally to a small subset of servers at a time. This avoids taking a large swathe of the server cluster offline and causes service brownout.