Technical Design of High-Concurrency Interactive Systems: Insights from Danmaku Video Platforms
This article explores the technical design of high-concurrency interactive systems using danmaku (bullet-screen) video platforms as a background. It covers core architectural challenges such as write hotspots, real-time reads, and multi-client consistency, detailing solutions including asynchronous peak shaving, multi-level caching, push-pull messaging models, and layered content moderation.
Introduction
Danmaku (bullet-screen) video platforms are characterized by the deep integration of viewing and interaction. Users can send real-time floating comments, post reviews, favorite content, and follow updates while watching videos. Behind these seemingly simple features lies a distributed system designed for high concurrency, low latency, and strong consistency. This article abstracts general technical solutions for interactive systems based on these platforms, analyzing common architectural practices.
Core Challenges of Interactive Systems
1. Concentrated Write Hotspots
When popular videos are released, comments and danmaku experience explosive growth in a short period, potentially reaching tens of thousands of writes per second for a single video. Traditional single-database and single-table architectures cannot handle this load, requiring database sharding and asynchronous peak shaving.
2. High Volume and Real-Time Reads
Danmaku must be pushed precisely according to the video timeline. When users drag the progress bar, they need to fetch the corresponding segment of danmaku immediately, imposing strict latency requirements on the read path.
3. Multi-Client Consistency
Users access the same account across multiple clients (mobile, tablet, web). States such as playback history, favorites, and messages must sync in real-time across devices, involving message pushing and state merging.
Typical Architecture of Danmaku Systems
1. Storage Model for Danmaku
Danmaku inherently has two key dimensions: video ID and time offset. A common storage design involves sharding by video ID and sorting indexes by time offset. An example structure is:
{"video_id": "v_10086","offset_ms": 65320,"user_id": "u_2048","content": "High energy ahead","created_at": 1700000000}
Queries retrieve data by video_id and offset range. Combined with inverted or range indexes, this efficiently returns the list of danmaku around a specific second.
2. Peak Shaving in the Write Path
Danmaku writes typically use an asynchronous pipeline: Gateway authentication -> Message Queue (MQ) buffering -> Consumer batch database writes.
- The gateway handles pre-filtering, such as rate limiting and basic content security checks.
- Valid danmaku is written to the MQ, where consumers aggregate and write batches to the database, reducing write pressure.
- Danmaku content must pass sensitive word filtering and machine moderation; only approved messages become publicly visible.
3. Read Path Optimization
Danmaku is read-heavy and write-light (relative to a single video), making it suitable for multi-level caching:
- Local Cache: Segments of danmaku for trending videos are cached in the gateway memory, enabling microsecond-level responses.
- Distributed Cache: Uses
video_id+ time segment as the cache key with a reasonable expiration time. - Cache Protection: When cache expires, mutex locks or logical expiration strategies are used to prevent cache breakdown.
Consistency Design for Comments and Activity Feeds
1. Pagination and Sorting of Comments
Comment lists usually support two modes: “Hot” and “Latest”. The hotness score is typically a weighted calculation of likes, replies, and a time decay factor. In practice, pre-computation combined with scheduled refreshes is often used to avoid the database pressure caused by real-time calculations.
2. Push and Pull Models for Messaging
Notifications (likes, replies, follows) commonly use two models:
- Push Model: Events are pushed to online users in real-time. It offers low latency but causes high write diffusion pressure for accounts with massive followings.
- Pull Model: Users fetch and aggregate messages on demand when opening the notification center. It has low write pressure but higher read costs.
A common industry solution is a hybrid approach: the push model for regular users, and the pull model for accounts with huge follower counts, merging and deduplicating during reads.
3. Multi-Client Synchronization
The key to syncing playback history and favorites across clients is using the server as the single source of truth. Clients report state changes to the server, which merges them using Last Write Wins (LWW) based on timestamps. The changes are then pushed to other online devices via persistent connections.
Content Security and Risk Control
Interactive systems must have built-in content security capabilities:
- Text Level: Dual filtering using sensitive word libraries and semantic models, with layered interception.
- Behavior Level: Identifying anomalies like spamming and flooding based on frequency control, device fingerprints, and behavior sequences.
- Execution Level: Supporting both post-moderation (visible first, reviewed later) and pre-moderation (reviewed first, visible later) strategies, switching dynamically based on risk levels.
Observability and Stability Assurance
Large-scale interactive systems require a comprehensive monitoring and alerting system:
- Core Metrics: API success rate, P99 latency, message queue backlog, and cache hit rate.
- Degradation Plans: Switching to delayed visibility when moderation services fail, or enabling local fallback caches during database outages.
- Stress Testing: Regular full-link stress testing on write paths to verify the effectiveness of scaling and rate-limiting strategies.
Conclusion
Interactive features like danmaku, comments, messages, and feeds represent typical scenarios characterized by “high read/write volume, concentrated hotspots, and strong interaction.” The general solutions can be summarized as: asynchronous peak shaving for write pressure, multi-level caching for read pressure, hybrid push-pull for message distribution, server-centralized design for multi-client sync, and layered risk control for content security. Understanding these design principles provides direct reference for building any large-scale interactive business system.
