Designing Multi-Device Login and Playback Progress Sync

    This article covers how to keep login sessions and playback progress consistent across phones, tablets, computers, and TVs. It explains server-side session management, a versioned progress data model, reporting strategies that limit write load, conflict resolution rules, membership checks, and the reliability and monitoring practices that support them.

    1. Problem Definition

    When the same user watches the same content on a phone, tablet, computer, and TV, the system must answer three questions: Is the user currently logged in? Where did playback stop last time? Which device’s record should take effect? These questions map to login state management, progress synchronization, and conflict handling. The three affect one another. If a team designs only one of them, progress is easily lost or rolled back during cross-device switching.

    Three common failures occur:

    • On weak networks, duplicate reports can move progress backward.
    • When two devices play the same content at the same time, a later write can overwrite an earlier one.
    • After a membership expires, the client can still keep offline cache of paid content.

    2. Login State and Session Model

    The server session should be the source of truth. The client holds only credentials. A common approach has three parts:

    • Access tokens have a short lifetime and are used only for API authentication.
    • Refresh tokens have a longer lifetime. They are used only to obtain new access tokens, and the server can revoke them at any time.
    • Each logged-in device has one session record. The record contains the device ID, platform type, last active time, and session status.

    The multi-device policy must be defined explicitly. For example, a platform may allow only one active session, while sessions on different platforms may stay online in parallel. Store the policy in a central configuration so that the logic does not get scattered across individual API endpoints.

    Illustrative pseudocode:

    1. function validateSession(token):
    2. claims = verifySignature(token)
    3. if claims is expired: return UNAUTHORIZED
    4. session = sessionStore.get(claims.sessionId)
    5. if session is null or session.revoked: return UNAUTHORIZED
    6. sessionStore.touch(session.id, now())
    7. return session.userId

    3. Playback Progress Data Model

    The recommended minimum unit for a progress record is a triple of user, content, and episode. Each record should include these fields: playback position in milliseconds, content duration, update time, source device, and version number. The version number determines the order of writes. It is more reliable than the client timestamp alone, because device clocks can drift.

    Server storage is usually sharded by user ID. Hot data that is read and written frequently can live in an in-memory cache. Persistent data belongs in a general-purpose relational database or key-value store. The write order between the cache and the persistent layer must be defined clearly, so the two do not stay inconsistent for long.

    4. Reporting Strategy

    If the client reports every frame or every state change, write pressure grows quickly. A common approach combines the following methods:

    1. Periodic reporting: submit the current position at a fixed interval. Set the interval based on load test results for the business.
    2. Event reporting: submit immediately on key actions such as pausing, exiting, switching episodes, and switching quality.
    3. Local buffering: write updates to a local queue first, then submit them in batches after the network recovers.
    4. Submit only the latest position, not the full playback history.

    Illustrative code:

    1. on playerTick(position):
    2. if now() - lastReport < REPORT_INTERVAL: return
    3. buffer.put({content, episode, position, version: localVersion + 1})
    4. lastReport = now()
    5. on eventPauseOrExit:
    6. flush(buffer, immediate=true)

    5. Conflict Detection and Merge Rules

    When two devices write concurrently, the server applies these rules:

    • If the submitted version is greater than the current version, overwrite the record and increment the version.
    • If the submitted version is less than or equal to the current version and the position difference is small, treat the write as a duplicate or an out-of-order packet and discard it.
    • If the position difference is large, keep both candidate records. Use the user’s most recent deliberate action to decide which one applies, and show the user a prompt in the interface to choose where to continue playback.

    The merge principle is that the system must not silently discard a user’s explicit action. By default, progress can take the larger value. When a user deliberately goes back to an earlier position, however, the system should respect that intent.

    6. Membership Permission Boundaries

    Membership status is authorization data, so the server determines the final result. The client may cache permission results to improve the experience, but the cache should have a short validity period. Before playback starts, the client should confirm with the server that the playback credential is still valid.

    Playback URLs should carry time-limited signatures and stop working after they expire. This prevents the client from holding playable resources after a membership ends.

    7. Reliability and Observability

    • Reporting endpoints must be idempotent. Use the combination of user, content, and version number as the deduplication key.
    • Add degradation switches. When server load rises, the client should automatically extend the reporting interval.
    • Monitor report success rate, conflict rate, and end-to-end latency. Set thresholds through the logging service and alerting system.
    • Roll out new strategies gradually. Release them to all users only after the metrics stay stable.

    8. Summary

    Multi-device sync depends on three decisions: who performs the operation, which version the operation is based on, and what rules govern the merge. The server manages sessions, version numbers manage progress, reporting combines periodic and immediate triggers, and the server enforces permission checks. Applying these four principles usually covers most cross-device switching scenarios.