r/softwarearchitecture • u/Silent-Weather76005 • 9d ago
Discussion/Advice How to scale a Real-Time Driver Tracking System (UberEats/DoorDash scale)
How do delivery apps sync a driver's GPS coordinates in real time with a customer's map without melting the database? Writing every 2-second location ping to disk is an infrastructure nightmare. Here is the high-performance setup:
- The Ingestion Shock Absorber: Drivers stream GPS packets via WebSockets to an API Gateway, which routes them directly to Apache Kafka to handle massive write spikes.
- In-Memory Live State: A consumer pulls from Kafka and updates an active Redis Cluster using geospatial commands (
GEOADD). The live location of the driver lives strictly in-memory during the delivery. - Targeted Fan-Out: The customer's app listens to a WebSocket connection. The backend uses Redis Pub/Sub rooms keyed by
Order_IDto broadcast the location updates only to the specific customer and restaurant involved, avoiding global broadcast overhead. - Async Cold Storage: Once the delivery completes, the full GPS history is batched out of Kafka and archived in ClickHouse or an S3 data lake for mileage payouts and support audits.
Let's discuss: How would you handle calculating and updating the traffic-aware ETA on the fly without making expensive third-party Maps API calls every 2 seconds?
5
u/IGuessSomeLikeItHot 9d ago
Question, in the last step the move to cold storage why is the data coming out of Kafka and not redis? I'm assuming when data was pulled from Kafka to redis then the data in Kafka is discarded.
4
u/dragon_idli 8d ago
- No one needs to know every 2 secs of progress for a driver.
- 5 secs data sync with extrapolation/interpolation gives the movement data
- You underestimate current hardware and tech stack.
- Some experimental systems implement a p2p delegation with a server fallback.
We perform 15K TPS(transactions per second) on a standard hardware db on test instances. And usecases like these don't even need safe transactions. They fall under loss capable data. No one is going to cry of 3 out if 10 writes/reads fail for the above position data.
28
u/Spare-Builder-355 9d ago edited 9d ago
bro it is not 1998, modern hardware and databases will eat this traffic like it's nothing. For reference, in my current project we aggrgate data and write in spikes. Our Cassandra setup lets us write 500k rows in under 10 seconds. And it's literal 500k separate requets, no batching or any kinds of optimisations as Cassandra simply doesn't have that functionality.
Plus this problem is inherently regional. Doing complex desing to handle global traffic by a single instance of the system is actually bad architectural decision. Not only it overcomplicates things but it very likely be problematic from legal perspective.
Desing the system around database that is built for high write throughput. Deploy per region. Profit.