Danmaku (Bullet Comments) Systems: Architecture and High-Concurrency Practices for Real-Time Video Interaction

    Danmaku—the stream of comments scrolling across a video in real time—is one of the most engaging interactive features on video platforms. This article breaks down the technical challenges behind danmaku systems, including high-concurrency writes, strict latency requirements, ordering, and storage for playback. It covers a layered architecture (connection, logic, and storage tiers), key optimizations such as message merging, multi-level caching, rate limiting, and content moderation, plus observability and stability practices for production-scale real-time messaging.

    Danmaku (Bullet Comments) Systems: Architecture and High-Concurrency Practices for Real-Time Video Interaction

    Technical Challenges of Danmaku Scenarios

    On video content platforms, danmaku is the most representative form of real-time interaction. Users send comments while watching a video, and others viewing the same video see these comments scroll across the screen almost instantly. Behind this seemingly simple feature lie several classic engineering problems:

    1. High-concurrency writes: A popular video can have hundreds of thousands of simultaneous viewers during peak hours, producing pulse-like write pressure from comment submissions.
    2. Real-time requirements: The value of danmaku lies in its “sense of shared experience.” High latency makes users feel like they are watching alone, significantly degrading the interactive experience.
    3. Ordering and deduplication: When a flood of comments arrives at the same moment, ensuring a reasonable display order without duplicates or loss is a classic distributed systems problem.
    4. Storage and playback: Comments must be stored aligned with the video timeline so that when a user drags the progress bar, the corresponding segment of comments can be fetched precisely.

    Overall Architecture Design

    A typical danmaku system is divided into three tiers: the access layer, the logic layer, and the storage layer.

    Access layer: This layer maintains massive numbers of persistent connections. Because danmaku demands high real-time performance, long-lived push connections are generally used instead of polling. Access layer nodes handle only connection management and message forwarding, keeping a stateless design that facilitates horizontal scaling. When a node reaches its connection limit, the load balancer routes new connections to other nodes.

    Logic layer: This layer handles core business logic, including sensitive-word filtering, rate limiting, and room broadcasting. For room broadcasting, all viewers of the same video can be abstracted into a “room.” The logic layer maintains subscription relationships among room members: comment messages are first written to a message queue, then a push service fans them out to the access layer nodes. This decoupling of writes from pushes effectively smooths traffic spikes:

    1. User submits a comment
    2. → Access layer receives it
    3. → Logic layer validation (authentication / rate limiting / content moderation)
    4. → Write to message queue
    5. → Push service consumes
    6. → Fan out to access layer nodes by subscription
    7. → Deliver to other users in the room

    Storage layer: This layer splits into hot and cold data paths. For live streams or trending videos, comments live primarily in in-memory databases or caches to guarantee millisecond-level reads and writes. As playback popularity declines, comments are archived—partitioned by video ID and time slice—into object storage or columnar databases for historical playback and analytics.

    Key Optimizations Under High Concurrency

    1. Message merging and sampling-based delivery. When a room has an extremely large audience, pushing every comment individually creates double pressure on bandwidth and client rendering. A common approach is to merge messages within time windows on the push side, or to sample comments according to policy once volume exceeds a threshold—trading some completeness for smoothness. The client rendering layer also needs to cap the number of comments on screen at once, keeping DOM or drawing overhead under control.

    2. Multi-level caching and sharding. The comment-fetching API organizes cache keys by “video ID + time slice,” for example one slice per minute. Cache hits return directly; misses fall back to the origin query. Slices for hot videos can be pre-warmed, and CDNs or edge nodes can further reduce origin pressure.

    3. Rate limiting and degradation strategies. On the sending side, per-user frequency caps prevent spam and malicious attacks. On the system side, an overall watermark triggers automatic degradation when message queue backlog exceeds a threshold—for example, temporarily reducing push density or disabling non-essential features like like-reaction notifications—to keep the core comment pipeline stable.

    4. Content safety upfront. Danmaku is a typical user-generated content (UGC) scenario, so machine moderation must complete before a message enters the broadcast pipeline, with suspicious content routed to an asynchronous human review queue. Moderation latency should be isolated through asynchrony so it never blocks the main message path.

    Observability and Stability

    A danmaku system’s monitoring should center on metrics such as: online persistent connections, end-to-end message latency, push success rate, queue backlog depth, and moderation interception rate. Build tiered alerting through logging services and a monitoring/alerting platform, and use full-stack distributed tracing to locate slow nodes. For release strategy, use canary deployments and chaos drills to validate the system’s self-healing capability under extreme scenarios such as connection storms and queue failures.

    Conclusion

    Danmaku is a microcosm of real-time interaction technology, built on the combined application of general-purpose capabilities: long-connection gateways, message queues, multi-level caching, and content safety. Understanding three core ideas—decoupling writes from pushes, separating hot and cold data, and graceful (lossy) service degradation—not only helps you build a solid danmaku system, but also transfers directly to other high-concurrency real-time scenarios such as live stream chat, online collaboration, and real-time market data. Teams looking to build these capabilities quickly can lean on standard cloud services—message queues, caching, object storage, and monitoring/alerting—to handle the infrastructure, letting them focus on business logic itself.