Geospatial Indexing

1. What exactly is Geospatial Indexing?

Your ASP.NET Core API stores each driver's live location as two plain columns, Latitude and Longitude, in Azure SQL. To match a rider with the nearest driver, it loads every driver currently online, works out the distance to each one in C#, and picks the smallest.

At 300 online drivers, that's under a second. But at 4,000 drivers during rush hour, the same query and loop takes over 4 seconds, and it just keeps getting slower as more drivers come online.

A search for what's nearby ends up checking everyone, not just who's close. That's exactly what geospatial indexing fixes.

2. How would you fix it in Azure?

Geospatial indexing lets the database do that work instead: change the Latitude/Longitude columns to a single geography column in Azure SQL, and create a spatial index on it, so Azure SQL organizes locations by where they are instead of scanning every row in order. Query using STDistance() with a radius filter, so the database returns only drivers within range, already sorted by distance.

Use: Azure SQL Spatial Index (STDistance)

Search only what's nearby, not everyone who exists.

3. How can you visualize it in everyday terms?

A phone book sorted alphabetically by name is great for finding one person, but useless for finding every restaurant within a mile of you. You would have to read every single entry to check.

A map sorted by neighborhood solves that instantly. You only ever look at the neighborhoods near you, never the whole book.

A map beats a phone book for finding what's nearby, every time.