Multi-Device Login and Progress Data Synchronization: Engineering Practices

    This article presents an engineering approach to multi-device login and cross-device progress synchronization for content platforms. It covers separating user accounts from device sessions, issuing and rotating short-lived access credentials and long-lived refresh credentials, revoking sessions, merging progress with version numbers and server timestamps, compensating for offline and weak-network writes through idempotent queues, and monitoring the synchronization pipeline securely.

    1. Requirements and Core Challenges

    Content platforms commonly need to support three types of requirements: users signing in to the same account on multiple devices; the same content resuming playback across devices; and user actions on one device, such as favorites, comments, and viewing history, being reflected on other devices in a timely manner. These requirements appear independent, but they actually share the same underlying data model: who performed which operation on which data, under which identity, on which device.

    Implementation typically involves four challenges:

    1. Credential security: Once a login credential leaks, an attacker can impersonate the account for an extended period. Credentials therefore must expire and be revocable.
    2. Device differences: Mobile phones, TVs, and web clients have different network environments and runtime constraints. A single session strategy is unlikely to cover every scenario.
    3. Concurrent conflicts: When two devices update the same progress record at the same time, the server must decide which record to keep.
    4. Weak networks and offline use: Operations generated by a client without network access must be reliably uploaded and merged after connectivity is restored.

    The following sections discuss sessions, progress, offline handling, and observability in that order.

    2. Session Model: Credentials, Devices, and Lifecycle

    The foundation of multi-device login is to model “users” and “device sessions” separately. A user is the account subject, while a device session records the login state of a given device during a given period. This has two direct benefits: sessions can be queried and terminated by device, and an anomaly on one device does not affect other devices.

    A recommended session structure includes the following fields:

    • session_id: The unique identifier of the session, used for revocation and auditing.
    • user_id: The account subject.
    • device_id: The device identifier. It should be generated and persisted by the client on first installation, rather than using hardware information that can be tampered with.
    • platform: The client type, used to differentiate policies. For example, the maximum number of concurrent sessions can differ between mobile and large-screen devices.
    • created_at, last_active_at, expires_at: Lifecycle timestamps.

    Credentials are usually split into short-lived access credentials and long-lived refresh credentials. Access credentials have a short validity period and are used for routine API calls, so even if they leak, the risk window is limited. Refresh credentials have a longer validity period and are used only to obtain new access credentials. They should be stored on the server so that they can be revoked at any time. Refresh credential rotation can be used: each use of a refresh credential issues a new credential, and the old credential immediately becomes invalid. If an old credential is used again, it usually means the credential may have been compromised. The server should revoke all credentials under that session and require the user to sign in again.

    3. Issuing, Refreshing, and Revoking Login State

    The key to the issuing flow is to complete identity verification and session creation on the server. The client only stores credentials and does not make authorization decisions locally. An access credential can carry the user identifier and expiration time, and a gateway or middleware can uniformly validate the signature and validity period. This avoids repeatedly querying the database in every business endpoint.

    Revocation needs to handle two cases. For stateless access credentials, it is difficult for the server to invalidate them before expiration, so their validity period should be short enough, and critical operations such as changing a password or unbinding a device should require identity verification again. For stateful refresh credentials, the server can directly delete the corresponding session record so that the credential becomes invalid immediately.

    A device management page usually displays all currently signed-in devices and allows users to sign out proactively. The backend implementation only needs to query the session list by user_id and then mark each session as invalid by session_id. Note that the sign-out operation should be idempotent, so repeated requests do not cause side effects.

    4. Synchronization Model for Playback Progress

    Playback progress may look like just a number, but it also involves write frequency, conflict resolution, and display timing.

    4.1 Sources of Conflict

    Conflicts mainly come from three sources. First, multiple devices may report progress at approximately the same time. Second, client reports may arrive out of order due to network jitter. Third, a user may watch a segment while offline, and after reconnecting, the progress may be earlier than the record already stored on the server.

    4.2 Merge Strategy

    A common approach is to maintain a monotonically increasing version number for each progress record and use the server receive time as the final arbitration basis. The version number addresses the ordering of reports from the same device, while the timestamp addresses which update is newer across different devices. Below is a simplified merge logic example:

    1. from dataclasses import dataclass
    2. @dataclass
    3. class ProgressRecord:
    4. content_id: str
    5. position_ms: int # Playback position in milliseconds
    6. device_id: str
    7. version: int # Monotonically increasing client-side version number
    8. updated_at: int # Millisecond timestamp assigned when the server writes the record
    9. def merge_progress(local: ProgressRecord, remote: ProgressRecord) -> ProgressRecord:
    10. if local.content_id != remote.content_id:
    11. raise ValueError("Can only merge progress records for the same content")
    12. # Different versions indicate different reports from the same device; keep the higher version
    13. if local.device_id == remote.device_id:
    14. return local if local.version >= remote.version else remote
    15. # Different devices: use server write time; if equal, use device ID to make the result deterministic
    16. return max(local, remote, key=lambda r: (r.updated_at, r.device_id))

    This logic has two key points. First, the merge function must be deterministic: the same inputs should produce the same result regardless of arrival order; otherwise, data on different clients will gradually diverge. Second, timestamps should be assigned uniformly by the server to avoid relying on client clocks, since device clocks may be skewed.

    Report frequency also needs to be controlled. During playback, progress can be reported at a fixed interval, and it should be reported immediately on pause, content switch, or exit from playback. Too high a frequency increases write pressure, while too low a frequency means users cannot find their most recent position when switching devices.

    5. Offline and Weak-Network Compensation

    In offline scenarios, the client should write progress changes to a local queue and attach a version number and generation time to each change. After network connectivity is restored, the changes are uploaded in batches in generation order, and the server performs the merge for each change.

    The upload process needs to handle duplicate submissions. If a request reaches the server but the response is lost, the client will retry, so each change should carry a unique operation identifier, and the server should deduplicate based on it. This design is called idempotent writing and is the basis for ensuring data correctness in weak-network environments.

    The local queue should also have an upper limit. When the limit is exceeded, only the latest progress for each content item can be retained, because progress is overwrite-type data and historical intermediate values have no retention value.

    6. Observability and Security Boundaries

    The session and synchronization paths should record key metrics, including login success rate, refresh failure rate, progress report latency, and number of merge conflicts. These metrics can be collected through log services and monitoring and alerting systems. A sudden increase in conflicts often indicates a defect in the client version or reporting logic.

    Logs must not record access credentials, refresh credentials, or full device identifiers. For troubleshooting, recording only a hash of the session identifier is sufficient. The API layer should also limit concurrent refresh requests for a single account to prevent brute-force credential attempts.

    7. Conclusion

    The core of multi-device login and progress synchronization is to design sessions, credentials, and data versions in layers: sessions are split by device, credentials are short-lived and revocable, progress is merged deterministically through version numbers and server timestamps, and offline changes are uploaded through idempotent writes. With this framework, teams can gradually extend to more devices and more complex synchronization scenarios while ensuring security and data consistency.