Real-Time vs Precomputed Ranking
What you'll learn: How to decide between computing feed rankings on-demand versus pre-calculating them ahead of time.
The Core Tradeoff
When building a social media feed, you face a fundamental choice: should you rank posts when the user opens the app (real-time) or continuously in the background before they even look (precomputed)?
Real-time ranking means running your ranking model every time a user requests their feed. You fetch candidate posts, apply ranking signals (recency, engagement, relevance), and sort them on-the-fly. This guarantees the freshest possible results with the latest signals, but adds latency to every read request.
Precomputed ranking means maintaining a pre-sorted feed in storage. A background process continuously updates each user's ranked timeline as new posts arrive. When users open the app, they simply read from their pre-ranked feed—fast, but potentially stale.
When to Choose Each
Use real-time ranking when:
- Feed freshness is critical (trending topics, breaking news)
- Ranking signals change frequently (real-time engagement metrics)
- User base is small enough to handle computation on every read
- You have spare read-time latency budget
Use precomputed ranking when:
- Serving latency must be minimal (p99 < 200ms)
- Write volume is manageable (fewer posts per second than reads)
- Users tolerate slight staleness (5-10 minute delays acceptable)
- Scale demands it (millions of concurrent users)
The Practical Hybrid
Most systems use hybrid approaches: precompute a base-ranked feed in the background, then apply lightweight real-time adjustments (filtering muted users, boosting very recent posts) at read time. Think of it like preparing a restaurant dish 80% ahead of time, then finishing with fresh garnishes when ordered.
Key Takeaway: Real-time ranking maximizes freshness but costs latency; precomputed ranking optimizes read performance but trades recency. Scale and latency requirements drive the choice.