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

Fanout Rate Limiting

Throttling fanout speed to prevent overwhelming downstream systems and maintaining system stability during traffic spikes.

Fanout Rate Limiting

What You'll Learn

You'll learn how to throttle fanout speed to prevent overwhelming downstream systems and maintain stability during traffic spikes in social media feeds.

The Problem

When a popular user posts, your fanout service might attempt to write to millions of user feeds simultaneously. Without rate limiting, this can:

  • Overwhelm database write capacity, causing latency spikes or timeouts
  • Saturate network bandwidth between services
  • Create cascading failures when dependent systems (cache clusters, storage nodes) become overloaded
  • Starve other operations, making the entire system unresponsive

How Fanout Rate Limiting Works

Rate limiting controls how fast your fanout workers process deliveries, similar to a water valve controlling flow through pipes—too much pressure breaks the system.

Implementation Strategies

Per-Worker Rate Limiting: Each fanout worker limits its own write throughput (e.g., 1000 writes/second). This prevents individual workers from hammering storage nodes.

Global Rate Limiting: Use a centralized token bucket or distributed rate limiter to cap total fanout throughput across all workers. This protects the entire system from collective overload.

Priority-Based Throttling: Apply stricter limits to celebrity fanouts while allowing normal users faster processing. This prevents one mega-post from blocking everyone else.

Adaptive Rate Limiting: Monitor downstream system health metrics (database response times, queue depths) and dynamically adjust fanout speed. Slow down when systems show stress, speed up when healthy.

Practical Example

If a celebrity with 50M followers posts, instead of spawning 50M writes immediately, you might:

  • Limit to 10K writes/second per worker
  • Use 100 workers = 1M writes/second maximum
  • Complete full fanout in ~50 seconds instead of creating a thundering herd

Key Takeaway: Fanout rate limiting acts as a safety valve, trading slightly delayed feed updates for system stability by preventing downstream overload during high-volume fanout operations.