Authentication and Authorization Architecture for High-Concurrency Content Platforms

    This article breaks down the architecture of login and authorization for high-traffic content platforms, covering identity verification, session control, multi-device state synchronization, and high-frequency write handling. It presents a four-layer design, a dual-token strategy, version-based state convergence, asynchronous write buffering, and the security, compliance, and stability practices needed to support HD playback, cross-device resume, and real-time interaction. It also notes that Baidu AI Cloud's container, cache, message queue, and monitoring capabilities can serve as a foundation for a faster build.

    1. Background: Moving from Guest Mode to Logged-In Mode

    On content platforms, guest users can usually only browse limited public information. Logging in unlocks HD quality, cross-device playback resume, danmaku and comments, and synced favorites and messages. This shift from guest mode to logged-in mode is essentially an expansion of the permission boundary: the system must confirm identity, load permissions, and associate data within milliseconds, while avoiding becoming a bottleneck under high concurrency.

    From an architecture perspective, this involves at least four sub-problems that can evolve independently:

    1. Trusted identity: confirming that a request comes from a legitimate user and that credentials have not been forged or replayed;
    2. Controllable sessions: supporting multiple devices online at once while allowing sessions to be revoked or kicked at any time;
    3. Consistent state: converging playback progress, favorites, and read status across devices;
    4. Write capacity: handling danmaku and comments, which are high-frequency small writes, without dragging down the main request path.

    Tackling these four points separately is far more robust than vaguely “building a login.”

    2. Layered Architecture

    A four-layer structure is recommended, with clear contracts between layers to allow independent scaling and canary releases.

    • Access layer: traffic cleaning, rate limiting, canary routing, and terminating long-lived connections;
    • Identity layer: credential verification, token issuance and refresh, and permission loading;
    • Business layer: playback, interaction, favorites, and messaging domains deployed independently;
    • Data layer: relational storage for strongly consistent data, cache for sessions and hot data, message queues for peak shaving, object storage for static assets, with logging and monitoring spanning the entire chain.

    A schematic request path looks like this:

    1. Client -> Access layer (rate limit/canary) -> Identity layer (verify token) -> Business layer (playback/interaction) -> Data layer
    2. | |
    3. Cache (sessions) Message queue (async writes)

    3. Identity and Sessions: A Two-Tier Token Practice

    The industry commonly uses a two-tier structure of “access token + refresh token.” The access token is short-lived and stateless, suitable for high-frequency verification; the refresh token is long-lived, must be persisted, and can be revoked at any time. The verification logic can be expressed in pseudocode:

    1. def authorize(request):
    2. token = request.header("Authorization")
    3. claims = verify_signature(token) # return unauthenticated on failure
    4. if claims.exp < now():
    5. raise TokenExpired
    6. session = cache.get(claims.session_id)
    7. if session is None or session.revoked:
    8. raise TokenInvalid # kicked out or logged out
    9. return load_permissions(claims.uid) # load permissions, caching recommended

    A few engineering details that are easy to overlook:

    • Token verification must check the signature, expiry, and revocation status together; none can be skipped;
    • The permission set should be cached with a short expiry to avoid hitting the source on every request;
    • Refresh tokens should support one-time use plus replay detection to prevent prolonged validity if stolen;
    • Multi-device online status should be distinguished by session ID, and kicks should invalidate at session granularity rather than logging out the whole account.

    4. Multi-Device Sync: Converging State with Version Numbers

    State such as playback progress, favorites, and read position is naturally subject to concurrent writes from multiple devices. A reliable approach is to attach a monotonically increasing version number or update timestamp to each piece of state and perform a conditional update on write:

    1. UPDATE progress
    2. SET position = :pos, version = version + 1
    3. WHERE uid = :uid AND item_id = :item AND version < :client_version;

    When the condition is not met, the cloud already has newer data and the client simply fetches the latest value. This avoids old data overwriting new data under eventual consistency without needing a distributed lock. For offline scenarios, a common compensation strategy is for the client to write locally first and merge by version once back online.

    5. Interaction Writes: Peak Shaving for High-Frequency Small Requests

    Danmaku and comments are characterized by “very large volume, very small individual items, and tolerance for second-level latency.” Synchronous database writes can easily exhaust the connection pool at peak times. The recommended path is to write to cache quickly at the access layer and return, then persist asynchronously through a message queue, with consumers batch-writing to storage and updating counts.

    1. Danmaku request -> Cache queue (immediate return) -> Message queue -> Batch consumption -> Storage + count update

    Supporting governance measures include dual rate limiting by user and by content, asynchronous sensitive-word filtering, separate storage for counts and lists, and local plus multi-level caching for hot content with heavy read and write. It is worth stressing that asynchronization must be premised on observability: queue backlog, consumption latency, and failed retries all need monitoring and alerts, otherwise problems get masked by delay.

    6. Security and Compliance Essentials

    • Encrypt data in transit; tokens must not be written to logs or stored in plaintext in frontend persistence;
    • Apply secondary verification to sensitive operations such as login, password change, and kick-out;
    • Full-chain auditing: who changed which session in what way and when;
    • Least-privilege principle, with permission changes going through approval and canary rollout;
    • Store user data in compliance with regional requirements, with a closed-loop process for deletion requests.

    7. Stability and Capacity Governance

    For capacity planning, first load-test the verification throughput of a single identity-layer instance, then reserve headroom based on peak QPS; the identity layer is stateless and can scale horizontally. Define degradation plans in advance: non-core interaction writes can degrade to “local display only,” and sync failures can fall back to compensation on the next startup. Chaos drills should cover three failure types: cache invalidation, queue backlog, and storage primary-replica failover.

    8. Conclusion

    Login may look like just an entry point, but it is a combined test of permissions, sessions, consistency, and write capacity. Making trusted identity, controllable sessions, convergent state, and peak-shaved writes solid, supported by security, compliance, and observability, is what enables experiences like HD playback, cross-device resume, and real-time interaction. For a shorter delivery cycle, you can quickly build a foundation on Baidu AI Cloud’s general capabilities such as container platforms, caching, message queues, and monitoring and alerting, leaving your energy for business differentiation itself.