Course contentsShow
← System Design
Lesson 1669 of 1,91940. Real-World System: Social Media FeedFree lesson

Ranking Score Decay and Updates

Implementing time-decay functions and updating ranking scores as posts receive new engagement without full recomputation.

Ranking Score Decay and Updates

What you'll learn: How to keep feed ranking scores fresh over time without recomputing everything from scratch when engagement happens.

The Time-Decay Challenge

A post's relevance naturally decreases over time—what's hot today is stale tomorrow. But posts also gain new likes, comments, and shares constantly. If you recomputed every post's ranking score on every engagement event, you'd burn enormous compute resources. The solution is incremental score updates with time decay.

Core Idea: Score = Base + Decay Function

Think of a post's ranking score like food freshness: it starts at 100% but decreases predictably over time. When someone adds new engagement (a "like"), you don't recalculate from scratch—you add points to the current decayed score.

A typical decay formula:

decayed_score = original_score × e^(-λ × hours_since_post)

Where λ (lambda) controls decay rate. Larger λ means faster decay.

Incremental Updates

When a post receives new engagement:

  1. Apply time decay to the current stored score
  2. Add the engagement delta (e.g., +10 for a like)
  3. Update the stored score and timestamp

This avoids re-fetching all historical signals. You're treating the score as a living value that ages naturally and gets "refreshed" by engagement.

Practical Implementation

Store last_score, last_updated_timestamp, and engagement_counts in your cache or database. When ranking:

  • Compute decay since last_updated_timestamp
  • Apply to last_score
  • If new engagement occurred, blend it in

For frequently-updated posts, batch updates every few minutes rather than per-event to reduce write load.

Key Takeaway: Time-decay functions let you efficiently age post scores while incremental updates add fresh engagement signals without full recomputation—balancing recency with computational efficiency.