StadiumFlow
Link to open source: https://github.com/ApurveKaranwal/StadiumFlow
Link to Live Project: https://stadium-flow-web.vercel.app/
Stadium Flow Advisory — Real-Time Crowd Optimization System
Problem Context
Large-scale stadium events consistently face uneven crowd distribution at entry points. Certain gates become heavily congested while others remain underutilized, leading to increased wait times, potential safety risks, and inefficient use of infrastructure. The core issue is not lack of capacity, but lack of real-time, personalized routing intelligence.
System Overview
Stadium Flow Advisory is a real-time decision system that dynamically routes users to the most efficient entry gate. Instead of relying on static proximity (nearest gate), the system continuously computes an optimal entry path based on both spatial and temporal factors.
The platform operates as a feedback-driven system where:
- User location provides spatial input
- Crowd reports and organizer inputs provide temporal congestion data
- The backend computes optimal routing decisions
- Results are pushed to users in real time
Core Algorithm: Optimal Gate Selection
Each gate is modeled as a queueing system. The objective is to minimize total entry time rather than distance.
For a given user location:
- Walking Distance is calculated using OSRM based on real road/footpath networks
- Walking Time is derived from distance using an average walking speed (~1.4 m/s)
- Queue Time is estimated from live crowd density signals
The system computes:
Total Cost = Walking Time + Queue Delay
This converts the problem into a multi-factor optimization task rather than a simple nearest-neighbor lookup.
The system evaluates all candidate gates and selects the one with the minimum total cost. This decision is recalculated continuously as new data arrives.
Real-Time Crowd State Estimation
Crowd density is not directly measured but inferred using a hybrid model:
- Crowd-Sourced Reports
- Users submit local observations (e.g., sparse, moderate, dense)
- Reports are geo-tagged and time-stamped
- Validation Layer
- Nearby users can verify reports
- Confidence scores are assigned based on agreement
- Aggregation Layer
- Reports are cached and aggregated (Redis-ready design)
- Gate-level crowd states are derived from weighted averages
- Organizer Overrides
- Organizers can directly set or adjust crowd levels and queue estimates
This creates a self-correcting system where inaccurate data is naturally filtered out over time.
Routing Engine Integration
The system integrates with OSRM to perform:
- Shortest path computation for pedestrian routes
- Distance and duration estimation
- Route geometry generation for frontend visualization
This ensures routing decisions are based on actual walkable paths, not straight-line approximations.
Incentive Mechanism for Load Balancing
A key challenge is behavioral: users prefer the nearest gate even if it is slower overall.
To address this, the system introduces a detour incentive model:
- If a user is recommended a farther but faster gate
- And the user chooses to follow that recommendation
- The system tracks completion (arrival at gate region)
- Rewards are issued via backend validation
This transforms routing from passive suggestion into active crowd redistribution.
Dual Interface Architecture
Fan Interface
- Real-time map visualization (Leaflet + OpenStreetMap)
- Gate markers with dynamic attributes:
- Queue time
- Walking time
- Total estimated entry time
- Route rendering for selected gate
- Lightweight reporting interface for crowd input
Organizer Interface
- Centralized control panel
- Gate state management (open/close/emergency)
- Real-time crowd distribution overview
- Broadcast system for instant updates
- Report verification tools
Privacy Model
The system is designed with minimal data retention:
- GPS data is processed in real time and not permanently stored with user identity
- Crowd insights are aggregated at gate-level granularity
- No personally identifiable tracking is required for system functionality
This ensures operational efficiency without compromising user privacy.
System Architecture
Frontend
- Next.js with React and TypeScript
- Leaflet for map rendering
- State-driven UI for real-time updates
Backend
- Node.js with Express
- REST APIs for core operations
- Designed to support WebSocket integration for live updates
Data Layer
- SQLite (sql.js) for lightweight persistence
- Suitable for hackathon deployment and edge scenarios
Routing Layer
- OSRM for geospatial computation
API Design
GET /api/gates/recommendation
Returns optimal gate based on user coordinatesGET /api/reports/live
Returns aggregated crowd state per gatePOST /api/reports
Submit crowd observationPOST /api/rewards/detour-points
Validate and assign rewardsPOST /api/updates
Organizer broadcast endpoint
Key Outcomes
- Reduces average entry time by distributing crowd load
- Prevents localized congestion and potential safety risks
- Provides organizers with real-time operational control
- Encourages cooperative user behavior through incentives
Closing Thought
This system shifts crowd management from reactive monitoring to predictive and adaptive control, using real-time data and optimization logic to continuously improve flow across the stadium.










