High-Concurrency Content Platform Architecture: Login and Personalized Recommendations
This article breaks down the architecture of a high-concurrency content platform, covering identity and permissions, media playback with cross-device resume, real-time interaction, and recommendation feeds. It explains a five-layer design, a dual-token authentication model, progress-sync consistency, danmaku and comment pipelines, offline-plus-online recommendation assembly, and a practical rollout plan with stability, security, and cost controls.
1. Problem Background and Goals
The source material describes a typical content community homepage. Guests can browse membership services, content categories, events, and trending content, and are prompted to download the client or sign up. After logging in, users unlock HD playback, cross-device resume, danmaku and comments, and a continuously refreshed trending feed.
Abstracted into technical terms, these interactions map to four core capability domains:
- Identity and access: distinguishing guests, regular users, and paid members, plus registration, login, session management, and permission checks.
- Media playback: adaptive quality, playback credential issuance, anti-hotlinking, and multi-device resume.
- Real-time interaction: high-frequency writes and low-latency distribution for danmaku, comments, and likes.
- Content aggregation: category navigation, rankings, recommendation feeds, and a continuous consumption experience.
This article does not focus on any specific third-party product. Instead, it treats the page intent as a general engineering problem: how to build a content platform foundation on the cloud that handles high-concurrency reads while keeping interaction latency low.
2. Layered Architecture
A five-layer structure is recommended, with clear contracts between layers:
- Access layer: load balancing plus gateway, handling TLS termination, rate limiting, upfront authentication, and canary routing.
- Business service layer: account, content, playback, interaction, and recommendation services, split by domain.
- Real-time channel layer: long-connection gateway and message broadcast for danmaku and presence.
- Data layer: a relational database for transactions and permissions, a cache cluster for hot data and progress, object storage for media files, a message queue for asynchronous decoupling, and logging plus monitoring for observability.
- Operations and governance layer: configuration center, service registry and discovery, tracing, alerting, and capacity plans.
On the cloud, these layers map to general product categories: a container platform hosts stateless services, object storage holds media and covers, a message queue carries danmaku and behavior events, and logging plus monitoring form an observability loop. The general cloud capabilities offered by Baidu AI Cloud can serve as a foundation for this kind of architecture, but the actual selection should depend on business scale and team capability.
3. Identity and Permissions: A Trust Chain from Guest to Member
The key to the login module is not “verifying a password” but establishing a trust chain that is verifiable, revocable, and shareable across devices.
1. Credential design. A dual-token model is recommended: a short-lived access token plus a long-lived refresh token. The access token lives only a few minutes and is used for API authorization; the refresh token is bound to the device and user and can be revoked proactively. An illustrative structure:
{"access_token": "opaque-or-jwt-string","refresh_token": "opaque-string","expires_in": 900,"device_id": "d-9f2c","scopes": ["play", "comment", "danmaku"]}
2. Multi-device session consistency. Sessions are recorded by user_id + device_id, with a session version number stored server-side. Any password change, ban, or logout increments the version, invalidating old tokens immediately. The client sends the token in the request header, and the gateway parses it once and passes the user context downstream, avoiding repeated parsing in business services.
3. Permission model. Access control follows “role + resource + action.” Guests can read public content, logged-in users can comment and send danmaku, and members additionally get HD quality and ad-free benefits. Entitlement checks should be centralized in the permission service, with no hard-coded checks scattered across business modules:
allow(user, resource, action):if user.role == GUEST and action in READ_PUBLIC: return trueif user.role == USER and action in READ_PUBLIC + INTERACT: return trueif user.role == VIP and action in ALL: return truereturn false
4. Risk control and anti-abuse. Registration and login endpoints need CAPTCHA or behavioral verification, rate limits, device fingerprinting, and anomalous-region detection. For credential stuffing, use “failure counting + increasing delay + temporary lockout” to prevent bulk account probing.
4. Playback and Cross-Device Resume: Consistency of Progress Sync
“Syncing playback records across devices” looks simple but is a classic distributed consistency exercise.
1. Progress reporting strategy. The client reports {user_id, content_id, position_ms, duration_ms, updated_at} every 5–10 seconds or on key events (pause, episode switch, exit). The server arbitrates by updated_at and writes only when the new timestamp is later, preventing stale requests from overwriting newer progress.
2. Storage tiering. Hot progress goes to cache with a reasonable TTL; cold data is persisted asynchronously. Stats such as play count and completion rate go through the message queue and are aggregated by offline jobs, so the online path is not slowed by analytics.
3. Quality and credentials. Quality switching is adaptive and handled by the player based on bandwidth. The server only issues time-limited playback credentials and validates anti-hotlink parameters. Media itself sits in object storage and is served through edge distribution to reduce origin load.
4. Idempotency and retries. All write APIs use request_id as the idempotency key, so client timeout retries do not cause duplicate counting. Illustrative pseudocode:
def update_progress(user_id, content_id, pos, ts, request_id):if seen(request_id): return OKkey = f"p:{user_id}:{content_id}"old = cache.get(key)if old is None or ts > old.ts:cache.set(key, Progress(pos, ts), ttl=7*DAY)queue.send("progress", old.to_dict() if old else None, new.to_dict())mark_seen(request_id, ttl=2*DAY)return OK
5. Real-Time Interaction: High-Throughput Channels for Danmaku and Comments
Danmaku is essentially a real-time message pattern: high-frequency writes, broadcast within a time window, and loss-tolerant. Comments are business data: low-frequency writes, strong consistency, and moderation required. The two must be handled separately.
- Danmaku pipeline: the client batches and merges sends, the access layer applies rate and content-safety filtering, the message queue smooths peaks, and the long-connection gateway broadcasts per room. Expired messages may be dropped, because late danmaku has no value.
- Comment pipeline: writes go to the relational database for strong consistency, sensitive-word and risk-control review runs asynchronously, and content enters the display feed after approval; counter fields are accumulated in cache and calibrated on a schedule.
- Connection governance: the long-connection gateway handles heartbeats, reconnect backoff, sticky sessions, and per-user connection limits; when scaling horizontally, consistent hashing routes the same room to a fixed node group to reduce broadcast storms.
6. Content Aggregation and Recommendations: Engineering the “Keep Watching” Experience
The homepage rankings, categories, and recommendation feed need a dual-track design of offline computation plus online assembly.
- Offline side: behavior events (impressions, clicks, completions, interactions) train recall and ranking models, producing candidate sets and features written to cache and a feature store.
- Online side: the gateway aggregates multiple candidate sources, then applies deduplication, interleaving, diversity constraints, and business-rule filtering (such as already-watched filtering and regional compliance) before returning a unified card structure.
- Fallback strategy: when the recommendation service times out or returns empty results, it falls back to the trending ranking; the ranking itself is refreshed by a real-time stats job to keep content fresh.
- Compliance and explainability: retain recommendation-reason fields and experiment-bucket identifiers to support canary comparison and issue tracing.
7. Stability, Security, and Cost Governance Checklist
- Tiered rate limiting: limit at four levels — user, device, API, and room — prioritizing the playback and login main paths.
- Degradation plans: recommendations degrade to rankings, danmaku degrades to read-only, comments degrade to asynchronous display.
- Observability: a unified
trace_idspans from gateway to data layer; core metrics include login success rate, playback stall rate, end-to-end danmaku latency, and recommendation empty-result rate. - Data security: encryption in transit throughout, sensitive fields masked or encrypted before persistence, and keys managed by a dedicated service with periodic rotation.
- Cost optimization: tier media and covers in object storage, moving cold data to infrequent-access storage; cache hit rate and origin-fetch ratio are hard metrics in capacity reviews.
8. Suggested Rollout Path
Phase one connects the account and playback main paths and establishes dual tokens plus progress idempotency. Phase two adds danmaku and comments, asynchronous first and then real-time. Phase three introduces recommendations and the experimentation system to close the data loop. Phase four completes chaos drills and capacity plans. Each phase should be accepted only when it is rollback-capable, observable, and canary-ready, avoiding a one-shot big-bang launch.
