AWS Builder Center
The Road Not Poisoned: Why We Replaced "Fastest Route" with "Cleanest Route" on AWS?

The Road Not Poisoned: Why We Replaced "Fastest Route" with "Cleanest Route" on AWS?

How we built an event-driven serverless engine using AWS Lambda, DynamoDB, and Uber H3 spatial indexing to minimize commuters' toxic particulate inhalation across high-pollution urban corridors.

Software Developer | Full-Stack Web Development | AWS & Cloud Enthusiast
Every navigation app on your phone operates on an unwritten, dangerous assumption: the air above every road in a city is equally safe to breathe.
It isn't.
In Delhi, peak-hour PM2.5 on an arterial truck corridor like the Outer Ring Road routinely crosses 380 µg/m³. Move just 400 meters inland into an interior residential avenue lined with neem trees, and the particulate count drops to 130 µg/m³.
That difference is invisible to your eyes, but it represents a 65% reduction in toxic particulate matter entering human lungs.
Yet, every morning, standard routing algorithms send delivery riders on two-wheelers and children in non-air-conditioned school buses straight down bumper-to-bumper diesel corridors to shave off 180 seconds.
We built VayuMarg during the Bharat Builds Tour Hackathon to fix this blind spot. It is an event-driven, serverless navigation engine deployed on AWS that optimizes for human biology rather than raw transit speed.



See VayuMarg in Action! 🚀

Watch our 3-minute hackathon walkthrough to see the engine recalculate routes live, check the school fleet warning triggers, and take a look at the live serverless backend:
🔗 Try the Deployed App:  VayuMarg Live Link (AWS Amplify)   | 💻  Explore the Code:  GitHub Repository 
End-to-end event-driven architecture using AWS Lambda, DynamoDB, API Gateway, and Amazon SNS




The Biological Formula: Beyond d / t

Standard navigation calculates cost as:
$$\text{Cost} = \frac{\text{Distance}}{\text{Speed}}$$
VayuMarg introduces a second optimization variable: Cumulative Inhaled Toxic Dosage ($D$):
$$D = \sum_{i=1}^{n} \left( \text{PM}{2.5}^{(i)} \times \Delta t{\text{hours}}^{(i)} \times V_{\text{mode}} \right)$$
Where:
  • $\text{PM}_{2.5}^{(i)}$ is the real-time pollutant concentration in road segment $i$.
  • $\Delta t_{\text{hours}}^{(i)}$ is the transit duration across that segment.
  • $V_{\text{mode}}$ is the minute ventilation factor adjusted for physical exposure:
  • Walking: 1.6× (elevated heart and respiratory rate)
  • Two-Wheeler: 1.2× (open-air exposure with moderate breathing)
  • Enclosed Transit / Bus: 0.8× (cabin buffering)
Instead of a binary choice, the user receives an honest, tangible trade-off: Take Route B: add 4 minutes to your commute, but cut particulate lung inhalation by 57%.



The Architecture: Sub-20ms Spatial Queries on Serverless

The central engineering challenge of this project was spatial granularity. Traditional PostGIS spatial database joins on GPS lines are computationally heavy and expensive to keep idling on virtual machines.
We wanted zero server management, sub-50ms roundtrip API latency, and zero monthly cloud expenditure.
End-to-end event-driven architecture using AWS Lambda, DynamoDB, API Gateway, and Amazon SNS


1. Spatial Discretization with Uber H3

Rather than storing bounding boxes or complex GIS polygons, we partition the city map into Uber H3 hexagonal grid cells at Resolution 8 (each cell covers an area roughly 460 meters across).
Every latitude/longitude coordinate from city air monitors collapses deterministically into a single 15-character string hash (e.g.,  883da11283fffff ).
showing a GPS route on an interactive hexagonal grid over an urban area of Delhi, India

Figure 3: Translating GPS polyline coordinates into discrete H3 resolution 8 cells for constant-time DynamoDB retrieval.

2. Micro-Caching with Amazon DynamoDB

Our table,  VayuMarg_SpatialTiles , uses the  h3_index  string as its primary partition key.
  • Zero Range Queries: No costly coordinate boundary math occurs at runtime.
  • Cost Safety via TTL: Every record has an epoch  ttl  attribute set to 24 hours. Old air readings expire and purge automatically without consuming write throughput or incurring persistent storage fees.
In Aws dashboard create bucket for project

Figure 4: The VayuMarg_SpatialTiles table in the AWS Console, showing indexed H3 cells and 24-hour TTL configuration.

3. Route Evaluation in a Single Trip

When a user requests directions:
  1. The client sends candidate polyline coordinate streams to our HTTP API Gateway.
  1. The Route Optimizer Lambda decodes the polylines and samples the coordinates into traversing H3 hashes.
  1. It deduplicates the hashes and issues a single  BatchGetItem  call to DynamoDB, retrieving pollution scores for up to 100 city blocks simultaneously in under 15 milliseconds.
  1. It weights each segment by travel time and user ventilation mode to score each route alternative.



What Fought Back: Two Engineering Roadblocks

Building on a hackathon clock always exposes architectural edge cases. Two issues almost derailed our pipeline:

1. The Sparse Station Interpolation Trap

Delhi has around 40 official air quality monitoring stations. If you map those raw points onto H3 resolution 8 cells across the National Capital Region (NCR), over 95% of your hexagons end up empty (null).
Initial route queries returned blank exposures because the roads ran between official sensor stations.
The Fix: In our ingestion pipeline, we implemented a localized Inverse Distance Weighting (IDW) step combined with H3's native  gridDisk  neighborhood expansion.
When a monitoring station reports 380 µg/m³, our ingestion Lambda radiates that value into surrounding hexagonal rings with an exponential distance-decay function. If a commuter crosses an unmonitored block, the system uses a calibrated background baseline rather than failing silently.

2. Polyline Over-Sampling

A typical 10-kilometer route geometry returned by routing engines can contain upwards of 1,200 raw coordinate points.
Translating all 1,200 points into H3 cells generated identical hexagonal hashes dozens of times in a row, causing our DynamoDB batch requests to hit internal limits with redundant keys.
The Fix: We built a light temporal down-sampling pass before running  latLngToCell . Coordinates are aggregated by segment duration ($\Delta t$) so that each distinct H3 cell is evaluated only once per contiguous traversal, drastically reducing compute memory and keeping Lambda execution under 120ms.



Automated Shielding: Beyond the Commuter Screen

The system goes beyond personal routing. When peak ground readings breach severe thresholds (> 300 µg/m³) during morning school commute windows (06:30–08:30 IST), the backend publishes directly to an Amazon SNS Topic.
Registered school transport supervisors automatically receive immediate alerts recommending alternative inner avenues, rolled-up bus windows, and moving morning outdoor assemblies indoors.
Action shifts from post-facto newspaper reading to pre-transit operational intervention.



Reflections for Cloud Builders

Building VayuMarg reinforced three core software engineering lessons:
  1. Algorithms reflect their objective functions: If you only tell an algorithm to minimize seconds, it will route people through poison without hesitation. Our software needs to account for human biological cost.
  1. Serverless fits hyper-local spatial data: Pairing spatial hashing (H3) with DynamoDB single-table design eliminates the operational overhead of running dedicated spatial databases for real-time reads.
  1. The AWS Free Tier is remarkably capable: By utilizing HTTP APIs, ARM-based Lambda functions ( arm64 ), and DynamoDB's on-demand capacity with TTL, this entire architecture runs smoothly within free allowances.
Clean air across India's urban corridors remains a long-term infrastructure battle. But until the air is cleaned at the source, the software we build must at least give people the clarity to choose the cleaner path.


All code, AWS SAM infrastructure templates, and setup instructions are open-source on  GitHub  and verified on the AWS Builder Center.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article