
Building Sparrows: A Serverless Food Rescue Dispatch System on AWS
Sparrows helps restaurants share safe surplus food with nearby NGOs and volunteers before the pickup window closes. We built its deadline-aware dispatch workflow on AWS using Amplify Hosting, API Gateway, Lambda, DynamoDB, CloudWatch, and infrastructure defined with AWS CDK.
Starting a four-day hackathon with 30 hours left
Bharat Builds: First Commit ran from Thursday to Sunday. My team found out about it on Friday night.
That left us with roughly 30 hours instead of the full 96-hour window. There was no time to build every feature we could imagine, so we had to answer a harder question: what was the smallest version of the idea that would prove something meaningful?
We were inspired by existing food-rescue initiatives that connect surplus food with people who can distribute it. They showed us that the willingness to donate and volunteer already exists. The difficult part is often the last mile: finding a responder with enough capacity, close enough to the restaurant, while the food is still within its pickup window.
That became the focus of Sparrows.
The name is a small reference to the kindness and swiftness we associate with sparrows. It is not a complicated metaphor, but it suited a product built around small, fast acts of coordination.
What Sparrows does
Sparrows is an expiry-aware dispatch system for safe surplus food. A restaurant can publish a listing with the food description, number of meals, dietary category, packed time, location, and pickup deadline. The donor must also acknowledge that the food is unserved surplus and that the pickup window reflects its handling requirements.
NGOs and volunteers use a map-based responder view to find listings within 10 kilometres. They can filter by food category, quantity, and time remaining, and the interface prevents a responder from accepting more meals than their remaining capacity. We also built and tested matching logic for food preferences, verification status, distance, and whether an estimated journey can fit inside the remaining pickup window; connecting that complete ranking model to the live feed is a next step.
The workflow continues after discovery. A responder claims a listing, confirms pickup, and confirms delivery. Every successful state change records the actor and timestamp, while an admin dashboard reports metrics such as meals listed, claimed, picked up, and delivered.
Two rules mattered more than anything else: an expired listing must never be claimable, and two responders must never win the same donation.
Sparrows does not certify food safety or replace compliant food handling. It records the donor's declaration and enforces the stated pickup deadline; participating organizations remain responsible for safe preparation, storage, transport, and distribution.
The serverless architecture
We wanted the infrastructure to stay small enough to understand during a hackathon while still exercising the real failure cases. The deployed path looks like this:
React web application | vAWS Amplify Hosting | vAmazon API Gateway | vAWS Lambda functions | vAmazon DynamoDB
Amazon CloudWatch receives logs from each Lambda function.AWS CDK defines and deploys the backend infrastructure.The React application has separate restaurant, responder, and admin experiences. API Gateway exposes routes for listings, claims, pickup, delivery, profiles, and impact metrics. Focused Lambda functions handle those operations, and DynamoDB stores listings, responder profiles, claims, deadlines, and status history.
The frontend refreshes its data every five seconds. That was a deliberate hackathon trade-off: polling gave us predictable cross-session updates without pretending we had already implemented a subscription-based real-time system.
We defined the backend infrastructure in TypeScript with AWS CDK. Each Lambda function receives only the DynamoDB operations it needs. For example, the claim function can update listings but cannot scan the table, while the health function has no database access at all. CloudWatch gives each function a dedicated log group so we can trace requests and lifecycle operations.
Learning to think in DynamoDB access patterns
Before Sparrows, most of my database experience was with PostgreSQL. My instinct was to begin with normalized entities and relationships, then decide how to query them. DynamoDB pushed me to reverse that process: begin with the requests the product must answer and shape the keys and indexes around them.
Our most important read pattern was: "Give me the available listings, ordered by the closest pickup deadline." We created a global secondary index with the listing status as the partition key and the pickup deadline as the sort key:
listingsTable.addGlobalSecondaryIndex({ indexName: "status-deadline-index", partitionKey: { name: "status", type: dynamodb.AttributeType.STRING }, sortKey: { name: "pickupDeadline", type: dynamodb.AttributeType.STRING }, projectionType: dynamodb.ProjectionType.ALL});This lets the listings Lambda query available donations in deadline order instead of scanning the entire table for the main responder feed.
DynamoDB is not a geospatial database, so we handled distance in a second step. Lambda queries active listings from the index, removes expired records, and calculates straight-line distance using the Haversine formula. The MVP then keeps listings inside the requested radius and applies the supported food, quantity, and deadline filters.
For a small, seeded Bengaluru demonstration, that division was practical. At a larger scale, I would introduce a more selective geographic access pattern or a dedicated routing service rather than reading every available listing in a broad area.
Making one responder the winner
The claim path was where DynamoDB became more than a storage choice.
Imagine two volunteers seeing the same donation during the same frontend refresh interval. Both click "Claim pickup." A check followed by a separate update would leave a race window in which both requests could believe the listing was available.
Instead, our Lambda sends one conditional update through the DynamoDB document client:
await db.send(new UpdateCommand({ TableName: listingsTable, Key: { id }, UpdateExpression: "SET #status = :claimed, claimedBy = :actor, claimedAt = :now", ConditionExpression: "attribute_exists(id) AND #status = :available AND pickupDeadline > :now", ExpressionAttributeNames: { "#status": "status" }, ExpressionAttributeValues: { ":claimed": "CLAIMED", ":available": "AVAILABLE", ":actor": actor, ":now": now }}));The real handler also appends the transition to the listing's status history in that update. The important part is that DynamoDB evaluates availability and the deadline as part of the write itself. There is no separate lock service and no application-level gap between checking and claiming.
If the condition fails, the API returns a conflict response and the frontend removes the stale listing before refreshing. This covers listings that were already claimed as well as listings whose deadline has passed.
The most satisfying moment of the hackathon was sending two claim requests at the same listing. One responder received the updated record. The other received a conflict. That small result proved that our central reliability promise was enforced in the deployed system, not just represented in the interface.
What we completed
By the end of our shortened build window, we had a deployed frontend and API, deterministic Bengaluru demo data, and role-specific workflows.
Restaurants could publish safe-surplus listings and monitor their progress. Responders could explore the 10-kilometre map, apply filters, see their remaining capacity, claim a pickup, and move it through pickup and delivery. Admins could view operational impact metrics calculated from listing state and history.
We tested the lifecycle and edge cases in the backend, including radius boundaries, capacity matching, expired listings, invalid status changes, and competing claims. We also exercised the deployed API: one concurrent claim succeeded, the competing request was rejected, the winning responder completed pickup and delivery, the dashboard reflected the activity, and the relevant Lambda executions appeared in CloudWatch.
What I learned
The biggest lesson was not a single AWS API. It was learning to model the system around its invariants.
DynamoDB made us state the claim rule precisely and enforce it where the data changes. AWS CDK let us keep tables, indexes, routes, Lambda functions, log groups, and IAM policies in the same TypeScript repository as the application. Running a synthesis and reviewing the infrastructure diff made cloud changes far less mysterious for someone new to AWS.
The 30-hour constraint also improved the product. We deferred attractive features when they did not strengthen the working path. A simple polling loop was more valuable than a half-finished real-time layer. Seeded demo identities were more useful than rushing production authentication. One complete restaurant-to-responder workflow taught us more than a wide collection of disconnected screens.
Where Sparrows could go next
The next step is not simply adding more AWS services. It is validating the operating model with restaurants, NGOs, and volunteers: how they define safe pickup windows, how capacity changes during a shift, why pickups fail, and who owns reassignment when they do.
The technical roadmap includes production authentication, user-facing notifications, travel-time routing, proactive expiry handling, and automatic reassignment while a listing is still usable. These improvements could eventually support a broader social-impact platform across more neighbourhoods, but the product should expand only alongside real operational partnerships and responsible food-handling processes.
Built by a team
I led the team and worked on the AWS architecture, infrastructure, deployment, and concurrency-sensitive backend flows. Anirudh Yekkaluri built shared contracts, routine APIs, demo data, distance logic, dashboard aggregation, and the backend test suite. Nikhil Krishna Sathvik built the frontend experience, map, restaurant and responder workflows, API integration, and impact dashboard.
I am grateful to both of them for turning a rough idea into a working product under an unusually tight deadline. I also want to thank Kunal Kushwaha, Hitesh Choudhary, Arkodyuti Saha, Jatin Mehrotra, Veeramani A, the AWS mentors, WeMakeDevs, and Polaris School of Technology for the feedback, conversations, and environment that made the build possible.
Good ideas are easy to discuss. Sparrows reminded me that the real learning begins when a team has to make the idea work.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article