Design Instagram Stories / WhatsApp Stories

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-02-05

Problem Statement

Designing a Stories Feature (like Instagram or WhatsApp Status), where users can upload short-lived content (images, videos, or text) that disappears after 24 hours. The system should support billions of users, ensure low latency content delivery, and provide high availability.


Functional Requirements (FR)


Story Creation / Upload

•Users can upload photos, short videos, or text to their story.
•Support optional features: captions, stickers, tags, filters, etc.

Story Lifecycle

•Each story must expire and become invisible after 24 hours.
•Automatic cleanup / archiving after expiry.

Story Consumption

•Users can view stories from the people they follow / are connected with.
•Stories should load quickly and smoothly (low latency).
•Stories are shown in order (most recent first).

Privacy & Controls

•User can control who can view their story (public, close friends, selected users).
•Ability to hide stories from certain followers.

Engagement

•Viewers can reply or react to stories (message or emoji).
•Story owner should see a list of viewers.

Notifications

•Followers may be notified when a new story is uploaded.


Non-Functional Requirements (NFR)


•Scalability: Must support billions of users with millions of concurrent story uploads and views.
•Latency: Uploads should propagate quickly (< a few seconds). Viewing should feel real-time.
•Availability: High availability system with minimal downtime.
•Storage Management: Ephemeral storage with TTL (time-to-live) of 24 hours; efficient cleanup.
•Consistency: Strong consistency required for view counts and privacy rules; eventual consistency okay for notification propagation.
•Security: Encrypted uploads (in transit & at rest), privacy enforcement, and secure access to stories.


Core Components


Story Service

•Handles story upload, metadata management, expiry logic.

Media Storage Service

•Stores photos/videos (e.g., object store like S3 / Blob storage).
•Supports CDN for fast content delivery.

Metadata Store

•Stores story references, user, timestamps, privacy settings, TTL.

Expiry & Cleanup Service

•Automatically deletes expired stories or archives them.

Feed / Story Retrieval Service

•Efficiently fetches and orders stories for each user (friends/followers only).
•Uses caching for quick retrieval.

Notification Service

•Notifies followers when new stories are uploaded.

View Tracking Service

•Tracks who viewed each story; updates counts in near real-time.

Access Control Service

•Enforces privacy settings and ensures only authorized users can view a story.

CDN / Edge Caching

•Ensures fast content delivery globally.

Analytics & Monitoring Service

•Collects metrics like story uploads per second, story views, engagement.


Data Flow (High Level)


1.User uploads story → API Gateway → Story Service → Media stored in Object Store → Metadata in DB.
2.Story metadata is indexed for retrieval (with TTL set).
3.Followers query Story Feed → Story Retrieval Service → fetch metadata → retrieve media via CDN.
4.Expiry Service deletes / marks expired stories after 24 hours.
5.View Tracking updates view counts and notifies the story owner of viewers.
6.Notifications are sent when stories are uploaded.


Key Design Challenges


•Handling huge scale (billions of daily uploads and trillions of views).
•Efficient expiry & cleanup without scanning full datasets.
•Maintaining low latency retrieval for story feeds.
•Managing privacy controls in a distributed environment.
•Optimizing storage costs for short-lived but high-volume data.


Solution

Comments