High-Concurrency Video Platform Architecture: Login and Content Delivery
This article breaks down the architecture of a high-concurrency video platform, covering layered decoupling, token-based login and session management, multi-device playback progress synchronization with eventual consistency, write amplification and peak shaving for danmaku and comments, adaptive bitrate content delivery, observability, and a phased rollout plan. It is intended for engineers designing scalable media platforms who need practical guidance on balancing consistency, latency, and cost.
1. Problem Background and Goals
On content platforms, once a user moves from guest mode to a logged-in state, they immediately gain three capabilities: high-definition playback, cross-device resume, and real-time interaction. These look like product features, but from an engineering standpoint they map to entirely different technical challenges: account and credential management, state synchronization and consistency, and high-concurrency writes with real-time broadcasting. Handling them in the same layer makes the system prone to cascading failures during traffic peaks.
The first principle of the architecture is therefore layered decoupling:
- The access layer handles traffic governance, identity verification, and rate limiting.
- The business layer handles domain logic such as playback, progress, and interaction.
- The storage layer is selected based on “strong consistency” versus “eventual consistency.”
- The asynchronous pipeline handles write fan-out and notification broadcasting.
The goals can be quantified into four points: low latency in the login path, fault-tolerant progress synchronization, interaction writes that do not block playback, and controllable content delivery costs.
2. Accounts and Login State: From Credentials to Sessions
Login is essentially “exchanging a one-time credential for a verifiable session.” In engineering terms, credentials and sessions should be strictly separated:
- Short-lived access tokens carry proof of identity for each request and should have as short a lifetime as possible.
- Long-lived refresh credentials are used only to obtain new tokens and must support revocation and rotation.
- Session state is stored centrally, making it easy to force logout across devices and to perform security audits.
The following pseudocode is illustrative and expresses the layering concept rather than a concrete API:
onLogin(credential):identity = verify(credential)session = createSession(identity, ttl=short)refresh = createRefresh(identity, ttl=long, rotate=true)return (session, refresh)onRequest(token):if not verifySignature(token): rejectif isRevoked(token): rejectreturn attachIdentity(token)
Three practical details deserve emphasis: token verification should happen at the access layer to avoid duplicate implementations in business code; refresh credentials must be single-use and checked for replay; and multi-device login must retain a device-level session index to support common capabilities such as “manage logged-in devices.”
3. Multi-Device Playback Progress Synchronization: Eventual Consistency First
Cross-device resume is a typical “write-heavy, read-heavy, but tolerant of brief inconsistency” scenario. Pursuing strong consistency means writing to the database on every pause, which causes obvious write amplification at peak times. A more reasonable approach is:
- The client writes to local storage first, so resume works even offline.
- Reporting uses throttling and merging, triggered by a fixed time interval or key events.
- The server applies a “monotonic advance” write rule and rejects older progress that would move backward.
- The read path hits the cache first and falls back to persistent storage on a cache miss.
The write semantics of progress records should be explicitly idempotent:
writeProgress(userId, itemId, position, updatedAt):key = "progress:" + userId + ":" + itemIdcurrent = cacheGet(key)if current == null or updatedAt > current.updatedAt:cacheSet(key, position, updatedAt, ttl=long)enqueueToStore(key, position, updatedAt) # async persistence
The key design here is “the cache is the source of truth, and persistence is filled in asynchronously.” A fallback for abnormal exits is also needed: on cold start, if the client finds its local progress is newer than the server’s, it can resume locally first and then reconcile in the background.
4. Danmaku and Comments: Write Fan-Out and Peak Shaving
The interaction module is characterized by extremely high instantaneous peaks, small individual payloads, and significant read amplification. The approach is to decouple “writing” from “visibility”:
- The access layer applies dual rate limiting at the user level and the content level to prevent spamming.
- Writes first enter a message queue for peak shaving, and consumers persist them in batches.
- Danmaku for popular content is distributed through caches and broadcast channels, avoiding a fallback to origin for every viewer.
- Comment lists use “snapshot plus incremental” reads to reduce deep-pagination overhead.
A typical form of batch consumption:
consume(batch):rows = sanitize(batch) # filter, truncate length, sensitive wordsstore.append(rows) # sequential append writebroadcast.publish(rows) # real-time broadcast to online viewersmetrics.observe(batch.size, latency)
A clear tradeoff between consistency and experience is required: danmaku tolerates second-level delay, while comments require “visible immediately after sending.” Comments can therefore use a pattern of “write to cache and return success first, then persist asynchronously,” but failure retries and user-visible status feedback must be provided.
5. Content Delivery and Adaptive Bitrate
Balancing the cost and experience of high-definition playback comes down to delivery and transcoding:
- Static content assets are placed in object storage and served by a content delivery network from the nearest origin.
- Multiple bitrate versions are generated during offline transcoding to avoid real-time transcoding overwhelming the cluster.
- The player adaptively switches bitrate based on bandwidth and buffer level.
- The logging service collects playback quality metrics to form an observability loop.
For cost control, use a lower cache priority for long-tail content, extend the cache lifetime for popular content, and intervene promptly on abnormal origin-fetch rates through monitoring and alerting. All capacity and billing details should follow the official documentation of the chosen cloud platform, and the architecture should avoid hard-coding any vendor-specific parameters into business logic.
6. Observability and Stability
Four types of signals must be in place: metrics, logs, tracing, and business instrumentation. Key signals to watch include login success rate, token verification latency, progress write latency, interaction message backlog, origin-fetch rate, and stall rate. Stability measures include circuit breaking and degradation (playback still works when interaction is unavailable), read/write separation, hot-key spreading, and regular capacity load testing and failure drills.
7. Rollout Roadmap
In the first phase, get accounts and sessions working end to end to ensure trusted identity. In the second phase, implement asynchronous progress synchronization with a local fallback. In the third phase, introduce a message queue to handle interaction peaks. In the fourth phase, complete delivery, transcoding, and quality monitoring. Using general-purpose capabilities such as object storage, message queues, container platforms, logging services, and monitoring and alerting on Baidu AI Cloud to carry the layers above can significantly reduce infrastructure operations overhead, letting the team focus on business and experience innovation.
