Proximity Service Deep Dive: How I Finally Understood Geohashing
Part of my system design interview prep series. If you missed the earlier pieces, start here: “I Opened System Design Prep After 6 Years and Realized I’m Rusty“
I stared at a geohashing algorithm for three hours yesterday and had what can only be described as a “systems design awakening.” This is the problem that made me realize I’ve been living in a blind spot for six years.
No Medium membership? That’s fine. Use this friend link to read the article.
Here’s the thing: I knew consistent hashing. I knew sharding. I knew how to partition databases. But geohashing? Quadtrees? Google S2? These terms kept showing up in interview prep materials and I’d just nod and move on, thinking “this is location-specific stuff, not relevant to me.”
Then I realized: location-specific stuff is literally everywhere now. Every product has a location component. Every company asks about proximity services. And I’d been mentally filing it under “nice to know” when it should be “must know.”
Where Proximity Services Live in the Real World
I started mapping out where I actually encounter proximity services daily and realized they’re everywhere.
Ride-sharing: Uber needs to find drivers within 2 km of a rider requesting a ride. Not just any drivers. Specifically drivers heading the right direction, with the right rating, who are currently available. But the foundation is still “find nearby drivers.” That’s the proximity service working in the background.
Food delivery: DoorDash needs to find restaurants within delivery distance of your location. But also find delivery drivers near the restaurant who can pick up your order. Both are proximity queries.
Social discovery: Instagram’s “Find Friends Nearby” feature. Twitter’s location-based trending topics. These use proximity services to find other people in your area.
Job search: LinkedIn probably uses proximity services to show job openings near your commute distance. Glassdoor definitely does for local job matching.
Dating apps: Tinder, Bumble, Hinge all use proximity services to show potential matches nearby. The entire business model depends on this working well.
Local search: Google Maps, Apple Maps, any “find X near me” feature. The entire category depends on proximity services.
Emergency services: Dispatch systems for police, fire, ambulances. Finding the nearest responder to an emergency location is literally a proximity query.
So proximity services aren’t niche. They’re foundational. And they’re in almost every major app category.
Prologue
So I spent a day really understanding proximity service design. Not just the “how do you build it” but the “why do you choose this approach over that one.” And I realized you can’t understand the design decisions without first understanding what this service actually is and why it’s so hard.
So I’m splitting this into two parts.
Part 1 (this one): Setting the context. What is a proximity service? Where does it live in real products? What makes it deceptively hard? Why should you care?
Part 2 (next week): The actual system design. Architecture, database choices, partitioning strategies, caching layers, latency modeling, cost optimization. The “how do we actually build this” part.
Let me walk you through Part 1.
The Problem That Looks Simple But Isn’t
Proximity service is beautifully simple to describe: given a user’s location and a search radius, find all nearby businesses. That’s it. Sounds straightforward.
Then you realize the complications pile up immediately. You have millions of businesses across the globe. Users are searching from their phones in real time. You need sub-second latency. You’re dealing with constantly changing locations. You need to handle boundary cases where searches span geographic regions. And if you get it wrong, your Uber driver matching breaks or your restaurant search is weirdly inaccurate.
This is why geohashing exists. This is why it matters.
Why Latitude-Longitude Queries Don’t Scale
My first instinct was “why not just store latitude and longitude in a database and query within a bounding box?” Standard SQL range query, right?
The answer: it works until it doesn’t.
Imagine you have billions of business locations in a database. A user in San Francisco searches “find restaurants within 1 km.” Your database has to scan millions of rows, calculate distances, filter by radius. Every query hits every partition. You’re doing expensive distance calculations at scale. Latency explodes. Your database drowns.
This is where geohashing comes in as a rescue mechanism. It’s not just clever, it’s necessary.
How Geohashing Actuachlly Works (The Lightbulb Moment)
Geohashing converts latitude-longitude coordinates into strings. The key insight: these strings have a natural hierarchical property. Longer strings are more precise. Shorter strings are less precise but still correct.
Here’s a concrete example. San Francisco’s coordinates (37.7749, 122.4194) become a geohash. The geohash for the exact location might be something like “9q8yy”. A shorter version “9q8” covers a larger area that includes San Francisco. An even shorter version “9q” covers an even larger region.
This is genius because it means you can partition your entire world by geohash. Businesses in San Francisco go into one partition. Businesses in New York go into another. No overlap. Each partition holds only the businesses in that geographic region.
Now when a user searches for nearby restaurants, you calculate their geohash, figure out which partitions they’re in and nearby, and only query those partitions. You’ve gone from querying billions of rows to querying a handful of geohash buckets. Latency drops from seconds to milliseconds.
The First Real Complication: Boundary Cases
Everything feels perfect until you realize the actual problem with geohashing: boundaries.
Imagine a user is searching for restaurants within 1 km. They’re standing right on the edge of a geohash boundary. Some restaurants 500 meters away are in a different geohash bucket. If your algorithm only searches their current geohash, you miss them.
This is why real proximity service designs don’t just search one geohash. They search multiple neighboring geohashes. You calculate the user’s location, determine their geohash, then also search the geohashes that are adjacent. This catches restaurants that are nearby but technically in a different partition.
But now you’ve added complexity. You need to know which geohashes are neighbors. You need to handle the case where your search radius spans multiple geohash levels. You need to do distance calculations on the boundary to make sure you’re not including things that are technically outside the radius.
This is where most candidates (including me, a week ago) get fuzzy. The simple “just geohash everything” breaks down at the boundary.
Why Geohashing Alone Isn’t Enough: Quadtrees Enter the Chat
Here’s where I realized geohashing is the foundation but not the whole story.
Quadtrees solve a different problem. Instead of dividing the world into grid-based geohashes, quadtrees recursively divide the world into four quadrants. San Francisco might be in the top-left quadrant of California. Within that quadrant, there’s another top-left quadrant that’s more granular. You keep subdividing until you reach the right level of granularity.
Why use quadtrees instead of geohashing? Because quadtrees adapt to data density. If you have a million restaurants in San Francisco but only 100 in rural Montana, a quadtree naturally creates deeper partitions for dense areas and shallower ones for sparse areas. Your partition sizes are balanced.
Geohashing creates fixed grid cells regardless of how many businesses are in each cell. Some cells might have millions of businesses, others might have zero. You still get unbalanced partitions.
So in a real production system, companies often layer quadtrees on top of geohashing. Or they use Google S2, which is a more sophisticated geometric system that handles spherical geometry on Earth properly.
The Architecture Pattern That Actually Works
After reading through what real systems do, I realized there’s a pattern:
First, you decide: grid-based (geohashing) or hierarchical (quadtrees/S2)? For most use cases, geohashing is simpler and S2 is overkill unless you’re Google.
Second, you partition your business data by geohash ahead of time. You build a geohash index. During indexing, you calculate the geohash for every business location and store it. When a business location changes, you update its geohash.
Third, you create a mapping of geohash to storage location. Geohash “9q8” maps to database partition X. Geohash “9q9” maps to partition Y. This is your lookup table.
Fourth, when a user searches:
- Calculate their geohash
- Fetch neighboring geohashes (the boundary case safety net)
- Query all relevant partitions for businesses
- Calculate actual distances to filter to the exact radius
- Return results ranked by distance
Fifth, you add caching because location data changes slowly. Cache the “restaurants near SF” result for a few minutes. Cache the “grocery stores near this zip code” for longer.
Where Cost Optimization Enters
Here’s where the latest interview context kicks in.
The naive approach would be to store every business’s geohash at every precision level. That’s storage bloat. The better approach is to store just the right precision level needed for your search requirements.
Do you need 1-meter precision? Store a longer geohash. 100-meter precision? Shorter geohash. This cuts storage costs and speeds up lookups.
Caching strategy matters too. Hot locations (downtown San Francisco) get cached aggressively. Cold locations (remote mountains) get cached conservatively. Uneven cache distribution saves cost while maintaining latency.
Database partitioning strategy affects query cost. Do you query all partitions and filter client-side, or do you push filtering to the database level? Client-side filtering is cheaper for compute, database-side is cheaper for network. Trade-off depends on your infrastructure.
An interviewer will absolutely ask “how would you reduce query costs by 40%?” The answer involves these trade-offs.
Real-World Complications I Glossed Over
After doing this deep dive, I realized there are so many real-world problems the pure algorithm doesn’t solve:
Moving targets: Drivers are constantly changing location. Do you update their geohash on every move or batch updates? How do you balance real-time accuracy with database write load?
Distance calculation: Latitude-longitude distances aren’t perfectly linear. The Earth is spherical. You need haversine formula or geodetic calculations. Doing this for every candidate result gets expensive. Most systems pre-filter with geohash, then do exact distance calculations only on candidates.
Search radius variations: A 1 km search is different from a 50 km search. For small radii, you might only need adjacent geohashes. For large radii, you might need geohashes several levels up. Your algorithm needs to adapt.
Handling sparse regions: In remote areas, businesses are spread out. A single geohash might be huge and contain very few results. Your algorithm needs to expand the search radius intelligently.
Precision trade-offs: A shorter geohash searches faster but returns more false positives that need distance filtering. A longer geohash searches slower but has fewer false positives. Where’s the sweet spot?
How This Fits into the Bigger System Design
Proximity service doesn’t exist in isolation. It’s part of a bigger product.
For Uber, proximity service powers driver matching. Drivers are constantly broadcasting their location. Your proximity service needs to handle massive write throughput (millions of location updates per second) and immediate read throughput (finding nearby drivers instantly).
For a restaurant search app, you’re querying a static list of businesses but the user location changes frequently. Your proximity service needs to cache heavily and handle mobile users whose locations jump across geohashes as they move.
For job search websites, you’re matching job seekers to jobs within a commute radius. This is less latency-sensitive but needs to be accurate across geographic boundaries.
The core algorithm is the same. The operational requirements are wildly different.
What I’m Taking Away from This Deep Dive
First, geohashing isn’t just an optimization. It’s a fundamental approach to making geographic queries scale. Latitude-longitude queries at billion-scale don’t work. You need spatial indexing.
Second, the simple algorithm has brutal edge cases. Boundary handling, precision trade-offs, distance calculations, caching strategy. These aren’t afterthoughts. They’re core to the design.
Third, cost optimization in proximity service isn’t just “use less memory.” It’s about precision levels, caching strategy, query filtering approach, database partition distribution. Each choice has cost implications.
Fourth, this is exactly the kind of problem where an interviewer drills into your thinking. They’ll ask about boundary cases. They’ll ask why you chose quadtrees over geohashing. They’ll ask what happens when search radius changes by an order of magnitude. These questions separate people who memorized algorithms from people who understand systems.
Why This Matters for My Interview Prep
Three days ago, geohashing felt like an optional advanced topic. Today it feels foundational. Not because I memorized the algorithm, but because I understand why it exists and what problems it solves.
This is one of my 7 flagship problems. I’ll be designing a proximity service in depth, handling all the complications, discussing trade-offs around precision and caching and cost. When an interviewer asks “what if you had to reduce latency by 50%,” I’ll have a mental model to draw from instead of panic.
Going into interview season, this feels like the right approach.
What’s Next
I’m going to do a complete system design deep dive on proximity service. The architecture. Database choices. Partitioning strategies. Caching layers. Real-time update handling. Latency modeling. Cost optimization. The “why do we choose this approach over that one” part.
That’s a full article on its own. This one was about understanding what proximity services are and why they matter. The next one is about actually building one.
Part 2 coming next: Designing a proximity service from scratch. We’ll start with the high-level architecture, work through database choices, handle the geographic partitioning strategy, design the caching layer, and model latency and cost. This is where the real system design decisions happen.
If you have questions about proximity services or want me to dive deeper into any particular aspect in Part 2, let me know in the comments.


