How to Find Nearby Users from 200 Million in Just a Second

Learn how to build a lightning-fast, scalable geolocation search to find nearby users from a pool of 200 million in under a second using H3 spatial indexing.

H3

How to Find Nearby Users from 200 Million in Just a Second: The Secrets of Scalable Geolocation Search

In today’s digital age, location-based services are at the heart of many popular apps—think ride-sharing, dating, delivery, and social networking. But have you ever wondered how these platforms can instantly show you nearby users, even when their databases contain hundreds of millions of users? In this article, we’ll reveal the technology and strategies behind finding nearby users from a pool of 200 million—within just a second.


Why Is Fast Geolocation Search So Challenging?

Let’s set the stage: Imagine a social app with 200 million users worldwide. When a user opens the app and wants to see who’s nearby, the system must:

Traditional database queries (like SQL WHERE distance < X) simply can’t scale to this level. As the user base grows, these queries become slower and more expensive. So, what’s the secret sauce that powers real-time, scalable geolocation search?


The Key: Spatial Indexing with H3

The breakthrough comes from spatial indexing. Instead of storing raw latitude and longitude, we use a spatial index like Uber’s H3. H3 divides the world into hexagonal cells at multiple resolutions, giving each cell a unique index.

How H3 Works

Why hexagons? Hexagons minimize distortion and provide more uniform coverage than squares or triangles, making them ideal for geospatial queries.


Step-by-Step: How to Find Nearby Users in a Flash

1. Preprocessing: Assign Users to H3 Cells

When a user signs up or updates their location, you convert their latitude/longitude to an H3 index and store it in your database. This is a one-time operation per location update.

2. Query: Find Nearby Cells

When searching for nearby users:

3. Filter Users by Cell

Query your database for users whose H3 index matches any of the nearby cells. This reduces the search space from 200 million to just a few thousand or less.


Visualizing the Process

Here’s a simple diagram to illustrate the process:

Nearby Users Flowchart

Real-World Example: H3 in Action

Let’s say you want to find users within 2km of a given point:

  1. Convert the point to an H3 index at resolution 9 (about 1km per cell).
  2. Use H3’s kRing function to get all cells within 2km.
  3. Query: SELECT * FROM users WHERE h3_index IN (list_of_cells)

This query is extremely fast, even with hundreds of millions of users.


Why Is This So Fast?

Fun fact: With H3, a single query can reduce the search space from hundreds of millions to just a few hundred or thousand users—making real-time results possible.


Each has its pros and cons, but H3’s hexagonal grid and hierarchical design make it a top choice for high-performance, scalable geospatial queries.



Try It Yourself: Open Source Example

Want to see a real-world implementation? Check out the open-source h3geo project on GitHub:

You’ll find a complete stack—Go backend, Angular frontend, MongoDB database, and a data generator for millions of users. The project is easy to run and perfect for learning or adapting to your own needs.


Conclusion

Finding nearby users from a massive user base in under a second is not magic—it’s smart engineering. By leveraging spatial indexing with tools like H3, you can build scalable, real-time geolocation features that delight your users and keep your app lightning fast.

Ready to supercharge your app with real-time location search?
Start exploring H3 and spatial indexing today!


Image Suggestions:


Reference:

Jobayer

© 2025 Jobayer Ahmed. All rights are reserved.