Designing Geospatial Architecture
1. Designing Location-Based Search
| Engine | Detail |
|---|---|
| PostGIS | Postgres extension; ST_DWithin, ST_Distance |
| MongoDB | 2dsphere index; $near |
| Elasticsearch | geo_point / geo_shape |
| Redis | GEO commands (geohash) |
| Tile38 | Specialized geo cache |
2. Designing Proximity Query System
| Pattern | Detail |
|---|---|
| Bounding box | Cheap pre-filter |
| Then exact distance | Refine within box |
| Top-K nearest | kNN with index |
| Geohash bucket lookup | Search 9 cells around target |
3. Designing Geospatial Indexing
| Index | Detail |
|---|---|
| R-tree / GiST | PostGIS |
| Geohash | String prefix → proximity |
| S2 (Google) | Spherical cells; hierarchical |
| H3 (Uber) | Hex grid; uniform neighbors |
| QuadTree | 2D recursive partition |
4. Designing Distance Calculation
| Method | Detail |
|---|---|
| Haversine | Great-circle on sphere; quick |
| Vincenty | Ellipsoid; accurate |
| Geodesic (PostGIS) | ST_Distance with geography type |
| Manhattan / Chebyshev | Grid-based use cases |
5. Designing Geocoding and Reverse Geocoding
| Provider | Detail |
|---|---|
| Google / Mapbox / HERE | Commercial |
| OpenStreetMap (Nominatim) | Open |
| Pelias / Photon | Self-hostable |
| Cache results | Address → lat/lng stable |
| ToS | Watch storage / display restrictions |
6. Designing Geofencing System
| Element | Detail |
|---|---|
| Polygon store | Spatial index |
| Point-in-polygon | ST_Contains |
| Enter / exit events | Track previous state per device |
| Real-time | Tile38 / streaming |
7. Designing Coordinate System Management
| System | Detail |
|---|---|
| WGS84 (EPSG:4326) | GPS standard; lat/lng |
| Web Mercator (EPSG:3857) | Map tiles |
| Local UTM | Survey-grade |
| Reproject | ST_Transform when mixing |
8. Designing Map Tile Serving
| Element | Detail |
|---|---|
| Format | Raster (PNG) vs Vector (MVT/PBF) |
| Server | Tegola, Martin, TileServer GL |
| Caching | CDN + S3 pre-rendered |
| Zoom levels | 0 (world) – 22 (street) |
9. Designing Location Tracking
| Aspect | Detail |
|---|---|
| Time-series store | (device_id, ts, lat, lng) |
| Compression | Polyline encoding for paths |
| Sampling | Distance / time threshold |
| Privacy | Retention + opt-out |
10. Designing Geospatial Query Performance
| Lever | Detail |
|---|---|
| Spatial index | Mandatory; full-scan kills |
| Bbox prefilter | Before exact distance |
| Cell-based shard | By H3 / geohash prefix |
| Cluster nearby points | For map display |
11. Designing Real-Time Location Updates
| Pattern | Detail |
|---|---|
| Pub/sub by region | Subscribers per H3 cell |
| WebSocket | Push to UI |
| Debounce | Throttle updates per device |
| Use case | Ride-sharing, fleet, delivery |
12. Designing Route Optimization
| Element | Detail |
|---|---|
| Routing engine | OSRM, Valhalla, GraphHopper, Google Directions |
| Algorithms | Dijkstra, A*, Contraction Hierarchies |
| VRP | Vehicle routing; OR-Tools |
| Traffic-aware | Real-time data weighting |
| ETA | Historic + live; ML-enhanced |