Designing Geospatial Architecture

EngineDetail
PostGISPostgres extension; ST_DWithin, ST_Distance
MongoDB2dsphere index; $near
Elasticsearchgeo_point / geo_shape
RedisGEO commands (geohash)
Tile38Specialized geo cache

2. Designing Proximity Query System

PatternDetail
Bounding boxCheap pre-filter
Then exact distanceRefine within box
Top-K nearestkNN with index
Geohash bucket lookupSearch 9 cells around target

3. Designing Geospatial Indexing

IndexDetail
R-tree / GiSTPostGIS
GeohashString prefix → proximity
S2 (Google)Spherical cells; hierarchical
H3 (Uber)Hex grid; uniform neighbors
QuadTree2D recursive partition

4. Designing Distance Calculation

MethodDetail
HaversineGreat-circle on sphere; quick
VincentyEllipsoid; accurate
Geodesic (PostGIS)ST_Distance with geography type
Manhattan / ChebyshevGrid-based use cases

5. Designing Geocoding and Reverse Geocoding

ProviderDetail
Google / Mapbox / HERECommercial
OpenStreetMap (Nominatim)Open
Pelias / PhotonSelf-hostable
Cache resultsAddress → lat/lng stable
ToSWatch storage / display restrictions

6. Designing Geofencing System

ElementDetail
Polygon storeSpatial index
Point-in-polygonST_Contains
Enter / exit eventsTrack previous state per device
Real-timeTile38 / streaming

7. Designing Coordinate System Management

SystemDetail
WGS84 (EPSG:4326)GPS standard; lat/lng
Web Mercator (EPSG:3857)Map tiles
Local UTMSurvey-grade
ReprojectST_Transform when mixing

8. Designing Map Tile Serving

ElementDetail
FormatRaster (PNG) vs Vector (MVT/PBF)
ServerTegola, Martin, TileServer GL
CachingCDN + S3 pre-rendered
Zoom levels0 (world) – 22 (street)

9. Designing Location Tracking

AspectDetail
Time-series store(device_id, ts, lat, lng)
CompressionPolyline encoding for paths
SamplingDistance / time threshold
PrivacyRetention + opt-out

10. Designing Geospatial Query Performance

LeverDetail
Spatial indexMandatory; full-scan kills
Bbox prefilterBefore exact distance
Cell-based shardBy H3 / geohash prefix
Cluster nearby pointsFor map display

11. Designing Real-Time Location Updates

PatternDetail
Pub/sub by regionSubscribers per H3 cell
WebSocketPush to UI
DebounceThrottle updates per device
Use caseRide-sharing, fleet, delivery

12. Designing Route Optimization

ElementDetail
Routing engineOSRM, Valhalla, GraphHopper, Google Directions
AlgorithmsDijkstra, A*, Contraction Hierarchies
VRPVehicle routing; OR-Tools
Traffic-awareReal-time data weighting
ETAHistoric + live; ML-enhanced