Design a News Feed with APIs
Design a Personalized News Feed System with APIs
Context
Design a large-scale personalized news feed for a consumer application. The system must support both push (server-initiated delivery/notifications) and pull (client-initiated fetch) consumption patterns, while ensuring strong ranking, safety, and operational guarantees.
Scale and Latency Targets
- Users: 100 million monthly active users (MAU)
- Publishers: 1 million
- Ingestion Rate: 200,000 writes per second
- Read Rate: 2 million reads per second
- Latency: p99 < 200 ms for feed reads
Functional Requirements
- Social Graph and Controls:
- Follow/unfollow functionality.
- User-level and publisher-level mute and block capabilities.
- Feed Quality:
- Deduplication (both exact and near-duplicate content).
- Diversity across content types, sources, and topics.
- Freshness and recency constraints for displayed content.
- Push Channel Safeguards:
- Daily notification caps per user.
- Content Lifecycle:
- Support for publisher-initiated content retractions (takedowns).
API Design Deliverables
Design external APIs, including request/response schemas and idempotency strategies, for the following operations:
publish(for content creation)subscribe(follow) /unsubscribeget_feed(must support pagination and consistent cursors)ack_consume(to acknowledge content consumption)retract(for content takedowns)feedback_logging(for user interactions)
For each API, provide:
- Endpoint path and HTTP method.
- Request and response JSON schemas.
- Idempotency strategy.
Architecture Choices and Justification
- Fan-out Strategy: Choose between fan-out-on-write, fan-out-on-read, or a hybrid approach. Justify your decision based on the provided scale and Service Level Objectives (SLOs).
- Storage Layers: Describe the different storage layers, including hot cache/timeline store and cold storage, and their respective roles.
- Event Streaming: Detail the event streaming topology.
- Ranking Pipeline: Outline the components of the ranking pipeline, covering candidate generation, feature engineering, filtering, scoring, re-ranking, and online inference.
Reliability, Safety, and Operations
Address the following non-functional requirements:
- Abuse and spam controls.
- Multi-region replication and read locality.
- Backfill and replay strategies for data consistency and recovery.
- GDPR deletion and data lifecycle management.
- Rate limiting and quotas.
- SLOs, observability (monitoring, logging, alerting), and on-call signals.
- Failure modes and graceful degradation strategies, including handling partial outages.
Experimentation
- Describe how to run online experiments on the ranking algorithm while ensuring user-level traffic consistency across sessions and pagination.
- Propose safe rollout plans and guardrails for new features or model updates.
AI interview prep
Core dilemma
Balancing extremely high read throughput (2M reads/sec, p99 < 200ms latency) with high write throughput (200k writes/sec), complex real-time personalization, and dynamic social graph filtering, while ensuring data consistency for critical operations like content retraction and GDPR compliance in a distributed, multi-region environment.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design a News Feed with APIs
Design a Personalized News Feed System with APIs
Context
Design a large-scale personalized news feed for a consumer application. The system must support both push (server-initiated delivery/notifications) and pull (client-initiated fetch) consumption patterns, while ensuring strong ranking, safety, and operational guarantees.
Scale and Latency Targets
- Users: 100 million monthly active users (MAU)
- Publishers: 1 million
- Ingestion Rate: 200,000 writes per second
- Read Rate: 2 million reads per second
- Latency: p99 < 200 ms for feed reads
Functional Requirements
- Social Graph and Controls:
- Follow/unfollow functionality.
- User-level and publisher-level mute and block capabilities.
- Feed Quality:
- Deduplication (both exact and near-duplicate content).
- Diversity across content types, sources, and topics.
- Freshness and recency constraints for displayed content.
- Push Channel Safeguards:
- Daily notification caps per user.
- Content Lifecycle:
- Support for publisher-initiated content retractions (takedowns).
API Design Deliverables
Design external APIs, including request/response schemas and idempotency strategies, for the following operations:
publish(for content creation)subscribe(follow) /unsubscribeget_feed(must support pagination and consistent cursors)ack_consume(to acknowledge content consumption)retract(for content takedowns)feedback_logging(for user interactions)
For each API, provide:
- Endpoint path and HTTP method.
- Request and response JSON schemas.
- Idempotency strategy.
Architecture Choices and Justification
- Fan-out Strategy: Choose between fan-out-on-write, fan-out-on-read, or a hybrid approach. Justify your decision based on the provided scale and Service Level Objectives (SLOs).
- Storage Layers: Describe the different storage layers, including hot cache/timeline store and cold storage, and their respective roles.
- Event Streaming: Detail the event streaming topology.
- Ranking Pipeline: Outline the components of the ranking pipeline, covering candidate generation, feature engineering, filtering, scoring, re-ranking, and online inference.
Reliability, Safety, and Operations
Address the following non-functional requirements:
- Abuse and spam controls.
- Multi-region replication and read locality.
- Backfill and replay strategies for data consistency and recovery.
- GDPR deletion and data lifecycle management.
- Rate limiting and quotas.
- SLOs, observability (monitoring, logging, alerting), and on-call signals.
- Failure modes and graceful degradation strategies, including handling partial outages.
Experimentation
- Describe how to run online experiments on the ranking algorithm while ensuring user-level traffic consistency across sessions and pagination.
- Propose safe rollout plans and guardrails for new features or model updates.