Real-Time Interactive Live Streaming: System Architecture and Engineering Practices
This article breaks down how to design a real-time interactive live streaming system that stays low-latency, highly concurrent, and reliable. It walks through a four-layer architecture that separates the media stream from the signaling channel, compares low-latency protocol choices (RTMP, HTTP-FLV, LL-HLS, WebRTC), and explains how to build the interaction message channel, the follow-relationship system, elastic scaling with multi-AZ failover, and end-to-end observability. Engineers will learn the key design principles and trade-offs for building a live streaming platform that holds up under tidal traffic spikes.
1. Scenario and Problem Definition
In a live stream, a host pushes video in real time while hundreds or thousands of viewers watch, alongside danmaku (bullet comments), chat, and “follow” actions. Behind this seemingly simple behavior lies a set of genuinely hard technical domains: real-time audio/video transport, massive numbers of long-lived connections, and strongly consistent relationship-graph storage. The core challenges come down to three points:
- Low latency: Viewers expect to see the picture within a few seconds of clicking, or ideally in sub-second time.
- High-concurrency long connections: Interactions such as danmaku, likes, and follows rely on long-lived connections; a single popular stream can hold hundreds of thousands of concurrent connections.
- High reliability: The stream must not drop, interaction messages must not be lost in bulk, and relationship-graph data must not become corrupted.
The sections below break the system down layer by layer around these three problems.
2. Overall Layered Architecture
A typical real-time interactive live streaming system can be divided into four layers, each with clear responsibilities and independent scalability:
- Access Layer (Push): The host client pushes the audio/video stream to the access gateway, which handles authentication, transcoding scheduling, and stream-validity checks.
- Stream Processing Layer: Handles transcoding, recording, frame capture, content moderation, and generating multiple bitrate streams for adaptive bitrate playback.
- Distribution Layer: Distributes the stream to edge nodes / CDN to shorten the network distance between the stream and viewers.
- Pull & Interaction Layer: Viewers pull and decode the stream for playback, while an independent signaling channel handles interactions such as danmaku, comments, and follows.
A key design principle: the media stream travels over the “stream” channel, while interaction messages travel over the “signaling” channel — the two are physically separated and scale independently. This way, even a surge in interaction volume won’t degrade the playback experience.
3. Low-Latency Protocol Selection
Different protocols vary significantly in latency, compatibility, and extensibility, so the choice must be weighed against the business:
| Protocol | Typical Latency | Advantages | Limitations |
|---|---|---|---|
| Traditional RTMP push | Seconds | Mature ecosystem, broad push-client support | Limited native browser playback support |
| HTTP-based FLV / segments | 1–3 seconds | Good compatibility, easy gateway traversal | Relatively high latency |
| Low-Latency HLS (e.g., LL-HLS) | Sub-second to 2 seconds | Standardized, CDN-friendly | Complex tuning of the segment strategy |
| WebRTC | Sub-second | Ultra-low latency, supports bidirectional | Higher distribution cost at scale |
A common combination in engineering practice: use a mature, stable approach for pushing, use a low-latency segmented protocol for large-scale viewer distribution, and use WebRTC locally for strong real-time scenarios like co-hosting (multi-guest) and highly interactive moments. The goal isn’t to minimize latency across the entire pipeline, but to optimize overall across cost, coverage, and stability.
4. Designing the Interaction Message Channel
Danmaku and comments are the classic case of high-concurrency, short messages. Key design points:
- Long-lived connections: Use full-duplex channels such as WebSocket to maintain massive numbers of long-lived connections.
- Gateway layering: Connection gateways only maintain connections, while business gateways handle message routing, avoiding a single point of pressure.
- Asynchronous peak shaving: High-frequency messages enter a message queue, are consumed asynchronously, and are aggregated per room before being pushed, so instantaneous spikes don’t overwhelm downstream services.
- Degradation strategy: When a room gets too hot, danmaku can be sampled or merged (e.g., “N people sent the same message”) to keep the core experience from breaking.
The snippet below illustrates a room message broadcast (pseudocode, to explain the idea):
def on_message(room_id, user_id, content):msg = build_message(room_id, user_id, content)# 1. Enqueue first to absorb the spike, then consume asynchronouslymessage_queue.publish(topic=f"room:{room_id}", payload=msg)# 2. Handle side tasks (relationship graph, sensitive-word filtering) asynchronously without blocking the main pathasync_tasks.submit(moderation.check, msg)# Consumer side: aggregate per room, then deliver in batchesdef consume_room_messages(room_id):for batch in message_queue.consume_batch(f"room:{room_id}"):merged = merge_by_content(batch) # Merge high-frequency identical contentgateway.broadcast(room_id, merged) # Push to online connections in batches
The key point is “enqueue at the entry, deliver after aggregation”, turning unpredictable spikes into controllable batch processing.
5. The Follow Relationship Graph
“Follow” is a classic scenario with uneven read/write load and a demand for strong consistency:
- Write: A follow action updates a directed relationship; you can use dual writes for a “follower set + followee’s fan set” (push/pull models), covering both types of queries — “people I follow” and “my fans.”
- Read: Accounts with huge followings need a hybrid approach that combines asynchronous fan-out (write fan-out) with on-demand fetching (read fan-out).
- Storage: Store relationship data in a key-value or relational store with high availability and scalability; for hot accounts, add local caching plus multi-level caching.
- Counters: High-frequency counters like fan counts can be handled by a dedicated counter service or cache, tolerating brief eventual consistency.
6. Elastic Scaling and High Availability
Live streaming traffic shows a clear “tidal” pattern — concurrent load spikes sharply during popular sessions. Ways to handle it:
- Containerized deployment: Deploy stateless services such as access, transcoding, and interaction gateways on a container platform, scaling instances up and down by load.
- Edge distribution: Use content delivery capabilities to push streams closer to viewers, reducing latency and origin-fetch pressure.
- Multi-AZ failover: Deploy key components across availability zones with failover, so a single point of failure doesn’t take down the entire stream.
- Recording and replay: Store recordings in object storage for on-demand playback and later moderation review.
7. Observability and Stability
Online stability depends on a complete observability system:
- Log service: Centrally collect logs for stream disconnects, message backlogs, and API errors to speed up troubleshooting.
- Monitoring and alerting: Set up monitoring and tiered alerts on core metrics such as first-frame time, stall rate, interaction-message latency, and long-connection count.
- Tracing: Connect the full “push — transcode — distribute — pull — interaction” pipeline to quickly locate latency bottlenecks.
- Load testing and drills: Run full-pipeline load tests and failure drills on a regular basis to verify that scaling and degradation plans actually work.
8. Best Practices Summary
- Separate stream and signaling: The two channels evolve and scale independently.
- Choose protocols by need: Optimize overall across latency, cost, and coverage rather than narrowly chasing the lowest latency.
- Enqueue interactions, then aggregate: Use asynchronous processing and merging to absorb spikes.
- Hybrid fan-out for the relationship graph: Balance read-heavy and write-heavy loads plus hot accounts.
- Elasticity + failover + observability as a whole: This trio keeps the system stable under tidal traffic.
Master these layered designs and engineering trade-offs, and you can build a real-time interactive live streaming system that balances low latency, high concurrency, and operability.
