AWS Builder Center
Kosi Twin

Kosi Twin

Turning a barrage number into a plan for every village

Kosi Twin: turning a barrage number into a plan for every village

Every year, the Kosi breaks out of its banks and Bihar pays for it. Governments change, but the floods keep coming back to the same villages. Ayush and I are residents of Bihar. We have seen this every monsoon, and as engineers we feel it is our job to help. We cannot stop the river, but we can make sure fewer people are caught off guard.
That is why we built Kosi Twin: a website, running entirely on AWS, that turns the Kosi barrage's official reading into a plan for every village. When will the water arrive? How deep will it get? When should we leave, and where should we go?

The problem: a number nobody can act on

The Kosi is called the "Sorrow of Bihar", and it earns the name. When it rises, the warning comes as a number: "4 lakh cusecs released at the Birpur barrage." On 29 September 2024, the department's own reading touched 6.13 lakh cusecs.
But nobody in a village decides anything from "lakh cusecs". A family needs to know: will the water reach my village? When? How deep? Which road is still dry? How much time do I have?
That gap, between a river number and a human decision, is what we wanted to close.

What Kosi Twin does

  • The live river. The newest official reading from the Bihar Water Resources Department's barrage report (issued at 10 AM and 3 PM), on a split-flap board, with how old it is.
  • What if. Drag a gauge to any river level and watch the flood spread across the map, with every village showing the hours until the water arrives.
  • Every flood since 2018. 31 floods, from the department's own readings, each one replayable hour by hour.
  • A card for every village. We cover 232 villages and towns on the Kosi plain. Each card says when to leave, when the water arrives, how deep it gets, and the safest route to a dry road, school or hospital.
  • Where people would go. For the river level on screen, how many people the plan sends to each school, hospital or raised road.
  • Email alerts. Follow a village, and when the official reading climbs to a level that would flood it, you get an email.
  • Flood Mirror. Add a photo of your own street and see the forecast water painted onto it.
  • For people, not just engineers. Four languages (English, Hindi, Bhojpuri, Maithili), spoken advisories, a one-page printable evacuation card, shareable links, and it keeps working offline.

How it works

  1. Discharge to river rise. The barrage reading goes through a rating curve to give the rise of the river.
  1. Where the water goes. We use the 30 m Copernicus elevation model from the AWS Open Data registry and a HAND model (Height Above Nearest Drainage). A patch of land floods when the river rise is higher than its height above the nearest channel and it is connected to the river.
  1. Who it reaches. Meta's population data, also on AWS Open Data, gives the people in each village, including the elderly and children.
  1. How they get out. OpenStreetMap roads, schools and hospitals give walking routes that avoid flooded roads.
  1. When. The flood wave runs down the river at about 5 km/h and then spreads over the fields at about 1 km/h. This is a rule of thumb, and the app says so.
The heavy computing happens once, on a laptop, and the results ship inside the Lambda package. At request time we only look things up. That keeps responses fast and costs close to nothing.

Built on AWS

Here is what each piece does for Kosi Twin.
AWS Lambda and API Gateway run the flood model (FastAPI) behind an HTTP API, throttled to protect the bill. Amazon S3 and CloudFront serve the web app, the flood map layers and cached audio on one domain. Amazon DynamoDB stores who follows which village, alert state and community reports. Amazon EventBridge runs every 5 minutes to refresh the barrage reading, keep Lambda warm and check for alerts. Amazon SNS sends the alert emails: one topic, each address filtered to its own villages, with SNS handling confirmation and unsubscribe.
Amazon Polly speaks the advisories, cached in S3. Amazon Translate gives Hindi names for villages and shelters. Amazon Rekognition finds a door or a person in a street photo, so Flood Mirror can measure the water height. AWS CloudFormation holds the whole stack in one template and one deploy script. The Copernicus elevation and Meta population data come from the AWS Open Data registry. Amazon Bedrock is wired in for AI-written advisories and AI-painted water, but we could not use it (see below).
At demo scale, about a thousand visitors and a hundred thousand API calls a month, we estimate it costs $1 to $5 a month at list prices. For a tool meant for villages, "almost free to run" matters.

What went wrong, and what we did about it

Our own model told us it might be wrong. We checked the model against 3,099 official readings that pair the barrage discharge with the river level just below it. Between 1.9 and 2.4 lakh cusecs, the river rose about 0.55 m. Our rule gives 1.43 m. These are not the same measurement, so it is a sanity check and not proof. But it suggests our flood depths may run high. We could have hidden this. Instead, the app plots the chart and says so. A flood tool that overstates its own confidence is dangerous.
Bedrock was not available to us. Our account had no model access, so AI-written advisories and AI-painted water could not run. So every AI feature has a fallback: written advisory templates and water drawn by the app itself. Everything works without Bedrock, and it switches on when access arrives.
A global model misread our own flood. We first tried GloFAS river data for history. It read the 2024 flood at about half its official size and ranked other years wrongly. We dropped it for history and use only the department's own readings, which start in 2018 because its earlier reports show gate positions but no discharge.
No AWS service speaks Bhojpuri or Maithili. Many families we know speak these at home. Our advisories in these languages are written templates, and they need review by native speakers. The app says that too.
Nobody publishes how many people a shelter holds. OpenStreetMap has schools and hospitals but not their capacity. So "Where people would go" shows demand only, and says clearly that it cannot tell whether a place has room.
A weak connection is the normal case. A flood is exactly when the network fails. A service worker saves the app and the last data it loaded, and we tested it by cutting the network in Chrome and reloading: the app opened from saved data and warned that the reading might be old. We also shrank our flood map layers after finding that each one used far too much graphics memory for weaker phones and laptops.

What Kosi Twin is not

It is a planning aid built on a flood model, not an official warning. The rating curve is not yet calibrated, arrival times are a rule of thumb, and it ignores embankment breaches. Please follow the district administration's orders. We would rather say this plainly than have anyone trust it too much.

What we would do next

  • Calibrate the model against downstream gauge data, with help from the department.
  • Get the Bhojpuri and Maithili text reviewed by native speakers.
  • Add real shelter capacities from district disaster-management records.
  • Send alerts on a channel families actually use, like SMS, not only email.
  • Sit with the people who run relief on the ground and ask what is missing.

How we built it

We built Kosi Twin over the four days of the WeMakeDevs x AWS Environmental Hacks (Track 2, Heat and Water). We used Claude Code as our AI coding assistant. The illustrations in the app are AI-generated and labelled as such, and the narration in our demo video is Amazon Polly.
The Kosi will rise again next year. We cannot stop that. But we can make sure that when it does, nobody finds out only when the water is at the door.
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