A reference project for API routes and database patterns
Simple GET request with query parameters → /api/hello
Store and retrieve simple values → /api/redis-strings
Store objects with multiple fields → /api/redis-hashes
Perfect for leaderboards! → /api/redis-sorted-sets
Activity feeds and recent events → /api/redis-lists
Three approaches for getting live updates from server to client
Repeatedly fetch data at fixed intervals. Simplest approach, but least efficient.
setInterval(() => fetch('/api/redis-sorted-sets'), 3000)
Polling with optimization: server tracks when data last changed, skips sending data if unchanged.
fetch('/api/realtime/smart-polling?since=' + lastKnownUpdate)
Industry-standard solution: server pushes updates instantly via Pusher's WebSocket service.
pusher.subscribe('game-events').bind('leaderboard-update', callback)
Open this page in another browser tab/window to see real-time sync!
✓ No setup required! These work with your existing Redis + Vercel setup.
PUSHER_APP_ID=your_app_id
PUSHER_KEY=your_key
PUSHER_SECRET=your_secret
PUSHER_CLUSTER=your_cluster
src/main.js:
YOUR_PUSHER_KEY and YOUR_CLUSTER
npm install to install pusher packages| Approach | Latency | Efficiency | Scalability | Setup |
|---|---|---|---|---|
| Short Polling | High (seconds) | Poor | Poor | None |
| Smart Polling | Medium (seconds) | Medium | Medium | Minimal |
| Pusher | Low (instant) | Excellent | Excellent | Account needed |
GET /api/hello?name=XGET/POST /api/redis-stringsGET/POST/PUT /api/redis-hashesGET/POST /api/redis-sorted-setsGET/POST /api/redis-listsGET /api/realtime/smart-polling?since=XGET/POST /api/realtime/pusher-trigger