
When Pipes Fail in the Dark: How We Built AquaLedger to Catch Water Leaks in Milliseconds
Every year, billions of liters of clean municipal water simply vanish beneath city streets before reaching a single home. Here is the behind-the-scenes engineering story of how our hackathon team built AquaLedger—an event-driven B2G platform powered by MongoDB geospatial indexing, real-time WebSockets, and AWS Lambda serverless orchestration.
Every day in developing cities, billions of liters of treated drinking water disappear before ever reaching a kitchen tap.
It happens underground, out of sight. A corroded joint buckles under midnight water pressure. Clean water cascades through soil and asphalt, carving subterranean sinkholes while nearby residents wake up to dry faucets. By the time someone files a formal complaint and a municipal worker tracks down the source, the damage is done: thousands of cubic meters of water wasted, municipal budgets drained, and marginalized neighborhoods left without access.
In public utility engineering, this hidden loss is known as Non-Revenue Water (NRW).
When our team entered the AWS Hackathon, we decided not to build another static municipal report dashboard. City engineers don't need another slow, weekly PDF digest. They need an active reflex system—a nervous system for municipal infrastructure.
That was the birth of AquaLedger.
The Reality of Municipal Infrastructure
The hardest part of managing urban water networks is that sensors alone rarely tell the whole story. A sudden pressure drop across a junction might indicate a burst main, or it might just be high peak-hour usage.
To separate noise from genuine crises, you need spatial context. You need to connect mechanical sensor anomalies with the voices of people living directly above those pipelines.
We started by modeling the municipal grid inside MongoDB Atlas, ditching flat relational tables for native GeoJSON structures indexed with
2dsphere :- Pipeline segments traced as spatial multi-polygons with real-time pressure thresholds.
- Administrative ward boundaries holding population densities and baseline equity targets.
- Citizen complaint logs logged as pinpoint coordinate points.
When a simulated telemetry drop hits our Node.js and Express backend, the server does not just flag a warning flag in a database. It triggers a
$near geospatial aggregation query that sweeps a 600-meter radius around the anomaly. If citizen complaints cluster over that same failing junction within the preceding hours, the confidence score shoots through the roof.The incident is immediately promoted to a CRITICAL emergency, recalculating the ward's Non-Revenue Water percentage and Water Equity Score in real time.
No Reloads: Streaming Anomalies at the Speed of Light
In an emergency operations center, waiting thirty seconds for a client polling loop to refresh is thirty seconds too slow.
We integrated Socket.IO directly into our Express HTTP server to turn AquaLedger into an active push-based stream. The moment our telemetry controller verifies an anomaly, the server broadcasts an event:
CRITICAL_LEAK_DETECTED In the browser, the operator doesn’t hit refresh. The dashboard reacts instantly:
- The pipeline line on the interactive GIS map turns from normal cyan to warning amber and flashes into high-alert crimson.
- The affected ward’s telemetry dial drops, updating the loss rate (LPM).
- The newly generated alert cards slide smoothly to the top of the action queue.
All of this happens in milliseconds, giving dispatchers an immediate, undeniable picture of ground reality.
The Mid-Hackathon Pivot: Engineering Around Dead Ends
Every hackathon project hits a wall. For us, it happened when we went to wire up the physical dispatch alerts.
Our initial architecture relied on AWS Simple Notification Service (SNS) to fire direct SMS alerts to field technicians. But under tight hackathon deadlines, we ran headfirst into sandbox messaging hurdles: our access keys were gated behind activation checks, threatening to stop our entire workflow in its tracks.
We couldn't wait 24 hours for account verification tickets. And we refused to present a faked, static mock.
So we pivoted our cloud architecture to an asynchronous, serverless design: AWS Lambda as an Emergency Proxy.
Instead of a monolithic notification pipeline, we refactored our alert controller to decouple the dispatch operation entirely:
- When an operator hits "Dispatch Crew" on the dashboard, our backend writes the status change to MongoDB, immediately updating the pipeline state to
under_repair.
- Using the modular AWS SDK for JavaScript v3 (
@aws-sdk/client-lambda), our Express server packages the alert payload—Alert ID, coordinates, severity, and pipeline references—and fires anInvokeCommandto a serverless AWS Lambda function namedDispatchTwilioSMS.
- Running on AWS Lambda, our handler executes in milliseconds, handling the payload and securely routing the emergency notification through our telephony provider.
- Concurrently, Socket.IO emits a
CREW_DISPATCHEDevent back to the command center, locking the alert and showing ground teams en route.
Because AWS Lambda runs completely isolated from our primary API, the municipal dashboard never suffers from network latency or blocked Node threads while dispatch notifications are processing.
The Impact
AquaLedger turns blind utility guesswork into a unified, event-driven response pipeline:
By marrying geospatial data, real-time event broadcasting, and serverless compute, city authorities can transition from reactive patch-ups to proactive infrastructure defense. Every minute cut from a leak response saves thousands of liters of clean water, protects vulnerable neighborhoods from water cuts, and proves that resilient urban utilities aren't just built on concrete and steel—they're built on smart, real-time code.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article