Getting people to report garbage sounds easy. In practice, it requires overcoming one of the hardest problems in product design: making a tedious, unrewarded action feel worth doing — every single day.
SafaiPay is a waste management platform where users report garbage, book pickups, and earn redeemable points. The technical challenge was building a rewards economy that felt fair, fast, and fun. The design challenge was making civic behaviour addictive.
Why Points Alone Don't Work
Points without context are meaningless. A user earning 50 points doesn't know if that's good or bad, fast or slow, worth anything at all. The moment you add a leaderboard, a badge, or a payout, the points become real.
We layered three mechanisms on top of each other:
- Points — earned for every action: reporting, booking, completing a pickup
- Badges — 15 milestone badges for behavioural streaks and thresholds
- Leaderboard — real-time ranking against other users in your area
Each layer addresses a different psychological need. Points give immediate feedback. Badges mark identity ("I'm a Cleanup Champion"). Leaderboards create social competition.
The Technical Problem: Consistency
Points economies have a nasty failure mode: double-crediting. A user taps "Report Garbage", the request times out, they tap again — and earn points twice. At scale, this breaks trust and the economy.
We solved this with atomic transactions in PostgreSQL. Every point award was wrapped in a database transaction that checked for idempotency before crediting. Each action was assigned a unique event ID; the transaction would reject a second credit for the same event ID. No double-spending, ever.
Redis Leaderboards: O(log N) at Any Scale
Leaderboards are a classic engineering problem. A naive implementation — sort all users by points on every request — is O(N log N) and collapses under load.
Redis Sorted Sets solve this elegantly. Every point award updates the user's score in a sorted set with a single ZADD command. Fetching the top 100 users is a single ZREVRANGE call — O(log N) regardless of total user count.
The leaderboard updates in real time. When a user earns points, their rank changes instantly. That immediacy is what makes the competition feel alive.
Payouts: When Points Become Money
The final layer — and the one that makes SafaiPay different from most gamified apps — is that points convert to real money via RazorpayX UPI payouts. This changes everything psychologically: the rewards are no longer abstract, they're real rupees in your wallet.
We implemented wallet withdrawals with a minimum threshold (to keep transaction costs manageable) and a 24-hour processing window. The UPI integration used RazorpayX's payout API with webhook confirmation to mark withdrawals as complete only after settlement.
When civic participation pays — literally — people show up.
The lesson from SafaiPay: gamification works best when the rewards ladder from intrinsic (satisfaction, identity) to extrinsic (money). Start with points and badges to build habit. Add real payouts to make it stick.