Design a Broadcast Live Streaming Platform
HardReal World SystemsStreamingReal-TimeObserver PatternConcurrencyCDN
Problem Statement
Design a live streaming platform like Twitch or YouTube Live where streamers broadcast video, viewers join streams, interact through live chat, and platform tracks concurrent viewership.
Requirements
Functional Requirements
- Streamer creates a channel and goes live; stream has title, category, description
- Viewers can join and leave streams
- Live chat: viewers send messages visible to all current viewers
- Concurrent viewer count tracking
- Stream categories/tags for discovery (browse by category)
- Follow streamers; notify followers when streamer goes live
- Stream recording: auto-record live streams; VOD (video on demand) available after stream ends
- Subscription model: paid subscription to streamer for ad-free experience and exclusive emotes
- Moderation: ban/timeout users in chat, assign moderators
Non-Functional Requirements
- Thread-safe viewer count and chat message management
- Async follower notifications
- Singleton StreamingPlatformService
Key Entities
- Streamer/Viewer: user profiles
- Stream: id, streamer, title, category, status (LIVE/OFFLINE), viewerCount, startTime
- Channel: streamer's page; follower list, past streams (VODs)
- ChatMessage: id, sender, stream, content, timestamp
- ChatRoom: streamId, activeViewers, messages (bounded buffer), moderators
- StreamingPlatformService: Singleton
Constraints
- Chat message history: last 500 messages per stream
- Viewer count is eventually consistent (update every 5 seconds)
- Banned users cannot send chat messages or rejoin the stream's chat
- VOD retention: 60 days for non-subscribers
!Constraints
- Chat history bounded at 500 messages per stream (circular buffer)
- Viewer count updated in batches every 5 seconds (eventually consistent)
- Banned users cannot rejoin chat
- Follower notifications are async and non-blocking for stream start
- VODs retained 60 days; subscribers retain indefinitely
Output
Run or submit your code to see output here.