System Architecture: Core Components of Location Tracking
Ingestion Layer
Devices send location updates to ingestion servers. Use WebSocket or long-polling for persistent connections. UDP reduces overhead for high-frequency updates but loses delivery guarantee. HTTPS works but connection overhead is high for frequent small payloads.
Load balance by entity ID, not randomly. All updates from one driver go to one server. This enables local caching and deduplication. The server can skip writes if position has not changed significantly.
Hot Storage
Store current position in fast key-value store like Redis. Key is entity ID, value is lat/lon plus timestamp. Writes are simple key updates, O(1). Reads are key lookups, O(1). No spatial indexing at this layer.
This layer optimizes for write throughput. It answers "where is driver X right now" instantly. It does not answer "which drivers are near location Y" because there is no spatial index. Different layer handles spatial queries.
Spatial Index Layer
Separate system maintains spatial index of current positions. Receives position updates from hot storage via streaming or polling. Updates spatial index asynchronously. May be 1-5 seconds behind hot storage.
Spatial index answers "which drivers are near location Y." Use geohash, quadtree, or in-memory grid. Optimize for read performance since spatial queries are less frequent than position updates. Rebuild periodically from hot storage to handle drift.
History Storage
Archive positions for analytics, billing, disputes. Write to time-series database or append-only log. Query patterns differ: "show trip route" not "find nearby drivers." Optimize for sequential reads of one entity time range.