FundTracer v2: The Leaderboard That Actually Works
We rebuilt our rewards system from scratch. See how we achieved 98% Firestore read reduction and built a leaderboard that scales.
## Why We Rebuilt Everything
Our v1 leaderboard had potential but hit real problems: - Multiple campaigns created confusion - Expensive rank queries (full collection scans) - Firebase quota issues (49K reads/day) - N+1 query problems
We needed something simpler. One leaderboard. One metric. Production-ready.
The v2 Architecture
Firestore Schema (New) ```javascript // Collection: torque_wallets/{userId} { walletsScanned: number, // THE metric totalPoints: number, // scanned * 10 rank: number, // calculated ON WRITE displayName: string } ```
Key Innovation: Rank on Write, Not Read
**Old (v1):** Calculate rank every time a user checks stats ```javascript const rank = await db.collection('torque_user_stats') .where('points', '>', userPoints) .count() // Full collection scan = expensive! ```
**New (v2):** Calculate rank when user scans ```javascript await incrementScan(userId); await recalculateRanks(); // One-time batch update ```
This shifts O(read requests) to O(write events). Since writes are rare (~100/day) vs reads (~1000/day), we save ~95% of Firestore reads.
Performance Results
| Metric | v1 | v2 | Reduction | |--------|-----|-----|-----------| | Daily Firestore Reads | ~49,000 | ~700 | **98%** | | Leaderboard Queries | ~5,000 | ~96 | **98%** | | Rank Calculations | Expensive each time | Cached | **100%** |
What Changed
- **Single leaderboard** - Wallet Analyzer only
- **Clean API** - /api/torque/v2/*
- **Redis caching** - 5 min TTL
- **Telegram commands** - /rewardslb and /personalrewardslb
- **Stable refresh** - 60 seconds (won't hit quota)
The Result
A leaderboard that: - Updates in real-time - Works in Telegram groups - Doesn't hit Firebase quotas - Scales with more users
Try It Out
- Scan a wallet at fundtracer.xyz
- Check your rank: /personalrewardslb in Telegram
- View the leaderboard: /rewardslb
The leaderboard updates within 5 seconds of your scan.
---
*Engineering by Deji Tech*

