This PR implements a complete leaderboard system showcasing top artists, generous tippers, and trending tracks with advanced ranking algorithms, caching, and real-time updates.
Labels: backend, frontend, gamification, drips-wave, stellar-wave
-
ranking.service.ts: Implements decay algorithms for time-based rankings- Exponential decay for momentum scoring
- Time-weighted scoring with configurable half-life
- Growth rate calculations for fastest growing artists
- Composite trending score combining plays, tips, and recency
-
leaderboards.service.ts: Main service handling all leaderboard types- Artist leaderboards (most tipped, most played, fastest growing, by genre)
- Tipper leaderboards (most generous, most active, biggest single tip)
- Track leaderboards (trending, most tipped, most played)
- Redis caching with 5-minute TTL
- Cache invalidation support
-
leaderboards.scheduler.ts: Scheduled cache refreshes- All-time leaderboards: hourly
- Weekly leaderboards: every 15 minutes
- Monthly leaderboards: every 30 minutes
- Trending tracks: every 5 minutes
All endpoints are public and support filtering:
GET /api/leaderboards/artists/most-tippedGET /api/leaderboards/artists/most-playedGET /api/leaderboards/artists/fastest-growingGET /api/leaderboards/artists/by-genre/:genreGET /api/leaderboards/tippers/most-generousGET /api/leaderboards/tippers/most-activeGET /api/leaderboards/tippers/biggest-singleGET /api/leaderboards/tracks/trendingGET /api/leaderboards/tracks/most-tippedGET /api/leaderboards/tracks/most-played
Query parameters:
timeframe:all-time|monthly|weeklylimit: number of results (1-100, default: 50)offset: pagination offset (default: 0)genre: filter by genre (for artist leaderboards)
- Redis Module: Global Redis client with connection pooling
- Schedule Module: NestJS scheduler for cron jobs
- TypeORM Integration: Optimized queries with proper joins and aggregations
-
LeaderboardTable.tsx: Reusable table component- Medal badges for top 3 positions
- Rank change indicators (up/down arrows)
- User highlighting for current user
- Responsive design with hover effects
- Click handlers for navigation
-
LeaderboardsPage.tsx: Main leaderboard page- Category tabs (Artists, Tippers, Tracks)
- Type selection dropdown
- Timeframe filter buttons
- Share functionality (Web Share API + clipboard fallback)
- Loading and error states
- URL state management with query parameters
leaderboardService.ts: API client for leaderboard endpoints- Type-safe enum definitions
- Query parameter handling
- Response type definitions
-
Momentum Score:
score = base * e^(-decay * age_in_days)- Default decay rate: 0.1-0.15
- Gives more weight to recent activity
-
Time Decay Score:
score = base * 0.5^(age_in_hours / half_life)- Configurable half-life (default: 168 hours = 1 week)
- Exponential decay for time-sensitive rankings
-
Growth Score:
score = (recent - historical) / historical * 100 * (recent / time_window)- Compares recent activity to historical baseline
- Weighted by recent activity volume
-
Trending Score: Composite of plays, tips, and tip amounts
- Each component uses momentum decay
- Weighted combination for balanced ranking
- Redis cache with 5-minute TTL
- Cache keys include type, timeframe, limit, offset, and genre
- Scheduled refreshes prevent stale data
- Manual cache invalidation support
- Efficient SQL queries with proper indexes
- Aggregation at database level
- Pagination support
- Lazy loading for large datasets
backend/src/leaderboards/ranking.service.tsbackend/src/leaderboards/leaderboards.service.tsbackend/src/leaderboards/leaderboards.controller.tsbackend/src/leaderboards/leaderboards.module.tsbackend/src/leaderboards/leaderboards.scheduler.tsbackend/src/leaderboards/redis.module.tsbackend/src/leaderboards/dto/leaderboard-query.dto.tsbackend/src/leaderboards/dto/leaderboard-response.dto.ts
frontend/src/pages/LeaderboardsPage.tsxfrontend/src/components/LeaderboardTable.tsxfrontend/src/services/leaderboardService.ts
ioredis: Redis client for Node.js@nestjs/schedule: NestJS scheduler for cron jobs
Add to .env:
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0- All leaderboard types implemented
- Ranking algorithms correct
- Caching working
- Frontend displays rankings
- Filters functional
- Real-time rank updates (via scheduled refreshes)
- Unit and integration tests (to be added in follow-up PR)
- Historical snapshots (store leaderboard state over time)
- Real-time WebSocket updates for rank changes
- User-specific leaderboard position highlighting
- Export leaderboard data (CSV/JSON)
- Leaderboard analytics dashboard
- A/B testing for ranking algorithms
None - this is a new feature addition.
- Ensure Redis is running and accessible
- Update environment variables
- Run
npm installin backend directory - Restart backend service to enable scheduled tasks
(Add screenshots of the leaderboard UI when available)
Ready for Review ✅