Designing a Video Bullet Comment System: A Complete Guide from Architecture to Production
This article explains how to design and implement a production video bullet comment system. It covers architecture layers, WebSocket room models, peak shaving and degradation, timeline-sharded storage and prefetching, moderation and risk controls, client rendering optimizations, and observability. Readers learn how to balance low latency, high concurrency, content safety, and rendering performance.
Why a Video Bullet Comment System Deserves Its Own Design
On the surface, bullet comments are just “comments that scroll over a video.” From an engineering perspective, however, they form a classic real-time messaging system: high-concurrency writes, high-concurrency reads, strict low-latency requirements, strong content moderation needs, and performance optimization at the player rendering layer. Many teams initially implement bullet comments as ordinary comments, then encounter message loss, latency spikes, and client stuttering on popular videos.
The core differences between bullet comments and ordinary comments can be summarized in three points:
- Timeliness: Bullet comments are tightly bound to the video timeline. A comment that arrives a few seconds late is almost meaningless, so end-to-end latency usually needs to be in the seconds or sub-second range.
- Density: Popular videos may generate thousands of bullet comments per second during peak moments, while users actually need “representative comments” rather than a full push of every message.
- Rendering constraints: Bullet comments scroll continuously over the video, so the client must complete layout, drawing, and recycling within a limited rendering budget.
These three points determine that a bullet comment system must be designed holistically across messaging, storage, moderation, and rendering.
Overall Architecture Layers
A mature bullet comment system is usually divided into the following layers:
- Access layer: Manages long connections such as WebSocket, authentication, rate limiting, and connection heartbeats. Long connections are more resource-efficient than polling and make low-latency push easier.
- Message service layer: Receives send requests, performs validity checks, frequency limits, and initial sensitive-word filtering, then writes to a message queue for asynchronous distribution.
- Storage layer: Uses a hot/cold separation strategy. Recent bullet comments are kept in cache or time-series structures, while historical comments are persisted to object storage or databases.
- Moderation layer: Machine moderation runs first, with human review as a fallback. Moderation results are written back asynchronously and trigger retraction when necessary.
- Rendering layer: The client pulls comments for the corresponding interval based on the video timeline, then performs track allocation and drawing.
The key benefit of this layering is that the send path and receive path are decoupled, moderation does not block the user sending experience, and storage pressure is spread evenly.
Message Channel Design
Long Connections and Room Model
Bullet comment push is usually organized into rooms by “video/live room.” After users enter a playback page, they join the corresponding room. The connection gateway needs to handle:
- Connection lifecycle management: authentication, heartbeat, and reconnection;
- Room broadcast: fan out a bullet comment to all online connections in the room after it arrives;
- Backpressure control: actively degrade when the message rate of a single room exceeds client processing capacity.
A schematic subscription flow is shown below:
// Client joins a room{"action": "join","room_id": "av123456","token": "xxx"}
Peak Shaving and Degradation
The instantaneous flood of bullet comments on popular videos cannot be fully pushed. A common industry practice is server-side aggregation sampling: aggregate comments within a short window, such as 500 ms, select a batch by popularity and weight, and store the rest for users to replay. This controls bandwidth while preserving the “sense of presence” of bullet comments.
At the same time, multi-level degradation strategies are needed: when the number of connections is too high, disable non-core push and keep only on-demand replay; when moderation pressure is too high, raise the machine moderation threshold and delay the display of suspicious comments.
Storage and Retrieval: Timeline Sharding
Bullet comments are bound to video seconds, so the most natural storage model is sharding by video time:
{"video_id": "av123456","segment": 300,"dm_list": [{"t": 301.2, "user": "u1", "text": "Here comes the iconic scene", "mode": "scroll"},{"t": 301.5, "user": "u2", "text": "Front row", "mode": "top"}]}
Using five minutes as a shard, the client prefetches the next shard when playback progress enters a given interval. Shard data can be compressed and cached to a CDN or object storage, while historical cold data is archived to low-cost storage. Compared with the approach of “querying the database by second,” shard reads require fewer requests and achieve a higher cache hit rate, making this a mainstream approach for on-demand video scenarios.
Content Moderation and Risk Control
Bullet comments are real-time public content, so the moderation system must be placed upfront:
- Sender-side rate limiting: Set send frequency caps by user and by room, and use a token bucket algorithm to prevent flooding.
- Machine moderation pipeline: Sensitive-word matching, text classification models, and user reputation scores run in parallel. Comments that hit risk signals enter a delay queue or become visible only in a gray release.
- Asynchronous retraction: For violating comments that have already been pushed, system messages trigger client-side removal, and user behavior is recorded for later penalties.
The principle for risk control design is to combine “better slow than miss” with “retractable”: low-risk comments pass directly to preserve experience, high-risk comments are delayed for display, and violating content can be recalled afterward.
Client Rendering Performance Optimization
Bullet comment rendering is one of the easiest front-end areas to get wrong. Running DOM animations for thousands of comments at the same time causes obvious frame drops. Common optimizations include:
- Track allocation algorithm: Divide the screen into several horizontal tracks. A new comment looks for a non-conflicting track; when there is a conflict, it is dropped by priority or waits.
- Canvas or compositing layer rendering: Draw bullet comments with Canvas, or promote each comment to an independent compositing layer, handing animation to the GPU to avoid triggering layout reflow.
- Object pool reuse: After a comment scrolls off screen, return the node to the pool for reuse, reducing the overhead of frequent creation and destruction.
- Density cap: When display capacity is exceeded, sample by popularity to prioritize smoothness.
A simplified example of track selection is shown below:
def pick_track(tracks, duration):now = time.time()for i, t in enumerate(tracks):# The last comment on this track is far enough from the right edgeif now - t.last_time > t.clearance:return ireturn -1 # Full: drop or degrade
Observability and Operations Loop
Launch is only the beginning. A bullet comment system needs continuous monitoring:
- Pipeline metrics: Send success rate, P99 end-to-end latency, push drop rate, and connection reconnect rate;
- Content metrics: Machine moderation blocks, human review volume, and user report rate;
- Experience metrics: Client rendering frame rate and bullet comment density distribution.
These metrics should be integrated into a unified monitoring and alerting system, with drill-down by video and by room to quickly locate hotspot anomalies.
Conclusion
A bullet comment system is the intersection of three technical challenges: real-time messaging, content moderation, and high-performance rendering. The core design approach can be summarized as follows: asynchronous send pipeline, aggregated and degraded push pipeline, timeline-sharded storage pipeline, tiered parallel moderation pipeline, and hardware acceleration plus object pool reuse in the rendering pipeline. With this methodology, video communities, live interaction, and other real-time messaging scenarios can reuse the same architectural skeleton, adjusting parameters and strategies to fit business characteristics and build real-time interaction capabilities that balance experience, cost, and safety.
