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

Fanout Service Architecture

Designing a dedicated service to handle post distribution with workers, queues, and follower graph lookup.

Fanout Service Architecture

What you'll learn: How to design a dedicated service that efficiently distributes posts to followers' feeds using workers, queues, and the follow graph.

The Core Idea

A fanout service is a specialized backend component responsible for the heavy lifting of post distribution. When someone publishes a post, the fanout service takes that single event and replicates it to all relevant followers' feeds. Rather than having your main API server handle this expensive operation, you isolate it into a dedicated service with its own infrastructure.

Key Components

Message Queue

When a post is created, the API server drops a fanout task (containing post ID, author ID) into a message queue (like Kafka or RabbitMQ). This decouples post creation from distribution—the user sees immediate confirmation while fanout happens asynchronously.

Worker Pool

Multiple worker processes consume tasks from the queue in parallel. Each worker fetches the follower list from the follow graph (typically a graph database or cache), then writes the post to each follower's feed (usually in a key-value store or feed cache).

Follow Graph Lookup

Workers query the follow graph to determine: "Who follows this author?" This might be a Redis cache backed by a database, optimized for fast fan-in/fan-out queries.

Delivery Strategy

Workers batch writes to reduce overhead and may prioritize active users over dormant accounts. They track delivery progress to handle failures and retries gracefully.

The Workflow

  1. User creates post → API returns success
  2. Fanout task → Queue
  3. Worker picks up task → Queries follow graph → Writes to N follower feeds

Key Takeaway: A fanout service architecture separates post creation from distribution using queues and workers, enabling asynchronous, scalable feed population while keeping the API responsive.