Booking an intercity bus seat looks like a simple CRUD application until five hundred passengers click on the same sleeper berth in the same second. Without distributed locks, relational transactions lock entire tables or fail silently, leading to catastrophic double bookings.
RoutePulse pairs a production-grade MERN architecture with in-memory distributed concurrency in Redis, layered Route-Controller-Service patterns, and a real-time transit radar streaming live telematics from the Delhi Open Transit Data (OTD) GTFS-RT binary Protocol Buffers feed.
Before and after (measured metrics)
| Metric | Without Distributed Locks | RoutePulse (Redis Concurrency) |
|---|---|---|
| Double booking rate | ~4.2% under concurrent test bursts | 0% (deterministic atomic reservation) |
| Popular corridor search p95 | ~340ms (repeated MongoDB queries) | ~8ms (Redis 60s cached corridor pipeline) |
| Live fleet telematics | N/A (static schedule guesses) | 4,100+ DTC Electric & CNG buses streamed live |
| Abandoned seat recovery | Manual administrative cleanup | Automatic release at TTL expiry (600s) |
Atomic Seat Locking via Distributed Redis Keys
When a passenger clicks a seat on the multi-deck bus layout, we do not write to MongoDB immediately. We acquire an atomic lock in Redis:
const lockKey = `lock:seat:${tripId}:${seatNumber}`;
const acquired = await redis.set(lockKey, passengerSessionId, 'NX', 'EX', 600);
if (!acquired) {
return res.status(409).json({ error: 'Seat is currently reserved by another passenger' });
}
- Atomic Acquisition (
NX): If two requests hit the backend within the same millisecond, Redis's single-threaded event loop ensures exactly one succeeds. - Deterministic Time-To-Live (
EX 600): If the user closes their browser or abandons checkout, the lock automatically expires after 10 minutes without orphaned database states. - Instant Manual Release: If the passenger deselects the berth, the lock is freed immediately, making the seat instantly available to other passengers.
- Permanent Transaction Commit: Upon successful payment confirmation, the seat status is persisted into MongoDB and the ephemeral Redis lock is safely removed.
Live Fleet Telematics: Ingesting Delhi GTFS-RT Protobuf
Most booking platforms rely on static timetables. RoutePulse ingests the official Govt of NCT Delhi Open Transit Data (OTD) real-time binary stream (VehiclePositions.pb):
- Protobuf Decoding: Parses compact binary feeds directly via
gtfs-realtime-bindingsrather than bloated JSON payloads. - Fleet Scale: Monitors live GPS coordinates, bearings, speeds, and trip IDs across more than 4,100 active Electric and CNG buses in the capital region.
- Interactive Transit Radar: Provides an admin & passenger radar modal with electric fleet filtering, live speeds, nearest landmark geocoding (e.g. Kashmiri Gate ISBT, Dhaula Kuan), and Google Maps cross-linking.
High-Throughput Search Caching & Layered Architecture
Corridor queries (e.g., Delhi to Chandigarh, Jaipur to Delhi) experience heavy read volumes. RoutePulse caches search results in Redis with a 60-second TTL. Whenever a new trip is scheduled or pricing is altered, invalidation hooks purge stale corridor keys.
The backend strictly enforces the Route → Controller → Service architectural separation:
- Routes: Handle URL definitions and authentication middleware.
- Controllers: Orchestrate HTTP request/response lifecycles and input extraction.
- Services: Encapsulate business logic, Redis lock acquisitions, Protobuf stream parsing, QR code generation, and database interactions.