A high-concurrency, low-latency pricing engine designed to balance supply and demand in real-time marketplaces. This system simulates the core logic used by global ride-hailing platforms to manage dynamic surge pricing across geographic tiles.
The engine is built on a distributed architecture to ensure sub-millisecond price calculations:
- Spatial Indexing: Utilizes Uber’s H3 Discrete Global Grid (Resolution 8) to partition the earth into hexagons, avoiding the "boundary edge" issues of traditional circular geofencing.
- State Management: High-speed Redis atomic counters store real-time driver/rider presence.
- Concurrency: Built with Go (Golang) and the Fiber web framework for maximum throughput.
- Automatic Decay: Implements Redis TTL (Time-To-Live) logic; if a driver stops pinging for 60 seconds, they are automatically evicted from the surge calculation, ensuring data freshness.
- Dynamic Surge Algorithm: Real-time Rider-to-Driver ratio calculation with tiered multiplier logic.
- Geospatial Pings: RESTful endpoints for real-time location check-ins.
- Live Dashboard: Interactive Leaflet.js map visualizing surge "heatmaps" in the Nairobi CBD.
- Swarm Simulator: A multi-threaded simulation tool that pings the engine with 50+ concurrent "moving" drivers.
** Endpoint - Method - Description :**
- / - GET - Interactive Live Map Dashboard
- /surge - GET - Returns cell ID, counts, and price multiplier
- /checkin - POST - Updates presence for a specific lat/lng

- Go 1.21+
- Redis (running on
localhost:6379)
go run cmd/api/main.go
go run simulate.go