Backend Development 7 min read

Design and Architecture of a Live Streaming Gift System

The live‑streaming gift system is built with a producer‑consumer message queue, KV store, cache, SQL and SSD layers, employing asynchronous leaderboard updates, unique transaction IDs with redo handling, end‑to‑end encryption and replay protection to ensure high‑consistency, real‑time, secure processing of monetary gifts.

Tencent Music Tech Team
Tencent Music Tech Team
Tencent Music Tech Team
Design and Architecture of a Live Streaming Gift System

Features of the Live Gift System

High data consistency is required because gifts involve real monetary transactions; errors are unacceptable.

High real‑time requirement. Users care about the host’s immediate feedback after sending a gift, and hosts monitor gift leaderboards to interact with fans promptly. Therefore, gift accounts and leaderboards must be updated in near real‑time.

Many related modules. A single gift transaction triggers updates to various leaderboards, user level adjustments, and message broadcasting.

High security requirement. A gift account is comparable to a bank account.

Message importance. During popular live streams, massive gift messages must be delivered reliably and quickly without loss or duplication.

Gift System Architecture Choices

Module Interaction Mode Two options are considered: a direct notify mode and a message‑queue mode. The recommendation is to adopt a producer‑consumer model using a message queue for inter‑module communication. This approach decouples modules, allows independent scaling, and avoids long notify chains that become hard to maintain as new features (e.g., new leaderboards, honor systems) are added.

Computation Mode Gift leaderboards are read‑heavy, write‑light. A write‑diffusion (write‑asynchronous) mode is suggested: write operations push updates to a queue, and a separate process calculates the leaderboard asynchronously. Reads then fetch the pre‑computed results, ensuring low latency.

Storage Mode Different data have different requirements.

KV store: Core data such as leaderboards are persisted in a KV store for fast read/write.

MEM cache: Frequently accessed KV data are cached to reduce network latency.

SQL database: Gift transaction logs are stored for reconciliation and low‑frequency statistical analysis.

SSD storage: Transaction logs are also written to SSD for disaster recovery, issue tracing, and log replay. Data is sharded and replicated to balance cost and reliability.

Data Consistency

The CAP theorem is acknowledged. In high‑concurrency, real‑time scenarios, traditional SQL databases often cannot meet performance needs, leading to the adoption of KV stores that lack full transactional support. Consistency challenges arise mainly from data corruption (mitigated by backups) and timeout‑induced state uncertainty in distributed systems.

Solution for the gift service: each gift transaction generates a unique ID that propagates through the entire workflow. If a timeout occurs, the event is logged and a Redo process retries the operation, first checking whether the ID has already been processed to avoid duplicate accounting.

Security

End‑to‑end encryption of the gift protocol to prevent tampering.

Replay‑attack protection. The gifting process is split into two steps—order placement and consumption—governed by a state machine. If an order packet is captured and replayed, a new order ID is generated; if a consumption packet is replayed, the state machine validates the order’s legitimacy and consumption status.

Internal security measures: strengthen internal controls, enforce strict process standards, separate duties (DO separation), and perform periodic reconciliations.

backend architecturelive streamingdata consistencysecuritygift system
Tencent Music Tech Team
Written by

Tencent Music Tech Team

Public account of Tencent Music's development team, focusing on technology sharing and communication.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.