Summary
Redis sorted sets are the standard implementation substrate for fan-out-on-write news feed architectures. Each user's feed is a sorted set keyed by user_id, with post IDs scored by timestamp, enabling O(log N) per-follower write and O(1) feed reads with ZREVRANGE.
Evidence
- ·Redis ZADD + ZREVRANGE enables O(log N) write and O(1) read for sorted feed data
- ·Sorted set score = epoch timestamp gives chronological ordering without secondary sort
- ·Redis pipeline batches the N ZADD operations per write across follower set
- ·TTL on feed sorted sets bounds memory usage for inactive users
Operational Context
- ·Fan-out write amplification scales with follower count: precompute max follower ceiling before adopting
- ·Celebrity accounts (>100k followers) typically bypass fan-out and use pull-on-read hybrid
- ·Feed cache must be pre-populated on first login to avoid cold-start empty feed
Tradeoffs
- ·Fan-out-on-write requires Redis memory proportional to total_users * avg_feed_size
- ·High follower accounts create write hotspots: requires hybrid fan-out strategy
- ·Deleted posts require a compensating fan-out sweep to remove the post ID from all follower feeds
Generator Relevance
Redis + fan_out_on_write is the canonical recommendation for social feed and notification delivery in read-heavy social platform scenarios. Architecture generator should surface this combination when scenario includes news feed, activity stream, or notification delivery.
Evidence grounding
Grounded, 4 supporting itemsRedis sorted sets are documented as the canonical data structure for timeline/feed fan-out in multiple public engineering posts (Twitter, Instagram, and others).