Multi-Device Playback Progress Sync: Data Modeling and Conflict Resolution

    This article presents a practical design for synchronizing playback progress across phones, tablets, TVs, and web clients. It covers the playback record data model, reporting strategy, conflict resolution using version checks with a Last Write Wins fallback, clock and ordering concerns, offline and weak-network handling, storage and read patterns, and observability and test scenarios.

    1. Problem Background

    When users watch the same content on a phone, tablet, TV, and web client, they expect consistent playback progress across devices. The feature looks simple, but it involves client-side offline operation, network jitter, and concurrent writes from multiple devices. Before designing it, clarify three things: the granularity of the record, how often to report progress, and which progress record should win when multiple records conflict.

    2. Data Model Design

    A playback record should contain at least the following fields:

    • user_id: user identifier
    • content_id: content identifier
    • episode_id: episode identifier; can be null for single-episode content
    • position_ms: playback position in milliseconds
    • duration_ms: total content duration, used to calculate completion
    • device_id: identifier of the device that produced the record
    • updated_at: client-reported millisecond timestamp
    • version: incremental version number maintained by the server

    The primary key is recommended to be (user_id, content_id), so only the latest state is kept for each content item. Historical traces can be written to a separate log table for data analysis.

    Illustrative code:

    1. from dataclasses import dataclass
    2. @dataclass
    3. class PlaybackRecord:
    4. user_id: str
    5. content_id: str
    6. episode_id: str | None
    7. position_ms: int
    8. duration_ms: int
    9. device_id: str
    10. updated_at: int # Client millisecond timestamp, used only as an auxiliary ordering value
    11. version: int # Incremental version number maintained by the server

    3. Reporting Strategy

    Reporting once per second creates a large number of unnecessary requests. Common approaches include:

    1. During playback, report every 15 to 30 seconds; the interval can be adjusted according to business scale.
    2. Report immediately on pause, episode switch, or exit from the playback page so that key events are not lost.
    3. Have the client write to a local cache first and submit in batches after the network recovers.

    The reporting interval is a design parameter. It should be determined based on request volume and the precision required for user perception, and validated through load testing.

    4. Conflict Handling

    When multiple devices play the same content at the same time, multiple progress records may be produced. There are three common strategies:

    • Last Write Wins (LWW): simple to implement, but depends on clock accuracy and may overwrite valid later progress from another device.
    • Version-based optimistic locking: the client submits the version it last read; if server validation fails, the server returns the latest record and the client decides how to merge.
    • Active session merge: use the most recently active device as the authority, while progress from other devices is recorded only in history.

    In practice, version validation can be used as the primary mechanism, with Last Write Wins as a fallback. Example logic:

    1. def upsert_progress(store, record, expected_version):
    2. current = store.get(record.user_id, record.content_id)
    3. # Version mismatch means another device has updated; return conflict and latest record
    4. if current and current.version != expected_version:
    5. return {"status": "conflict", "latest": current}
    6. record.version = (current.version + 1) if current else 1
    7. store.put(record) # In production, use a conditional write in the database to ensure atomicity
    8. return {"status": "ok", "version": record.version}

    In the code above, there is a race window between read, compare, and write. In production, the comparison and write should be combined into a single conditional update statement so that the database guarantees atomicity.

    5. Clocks and Ordering

    Client time is unreliable: device time may be manually changed by the user or may differ from the server. The server should therefore use the time it receives the request as the authority, while client time is used only as auxiliary information. If the business requires strict ordering, version should be the primary basis, with receive time as a supplementary basis.

    6. Offline and Weak Network Conditions

    • Persist the pending synchronization queue locally so that unsubmitted data can be recovered after a process restart.
    • Each report should carry a unique request_id, which the server uses for deduplication to ensure request idempotency.
    • After a failure, use exponential backoff for retries and set a maximum retry count to avoid continuously consuming resources on weak networks.
    • Keep only the last pending record for the same content to reduce meaningless duplicate requests.

    7. Storage and Reads

    • Put hot data such as recently played items in a cache with a reasonable expiration time.
    • Store persistent data in a relational database or wide-table storage; the primary key design should match the query path.
    • List pages should use a batch query API to retrieve progress for multiple content items at once, avoiding the performance problems caused by one-by-one requests.

    8. Observability and Validation

    After launch, continuously monitor the following metrics:

    • Reporting success rate and average latency
    • Version conflict rate
    • Number of progress rollbacks, i.e., the proportion of cases where new progress is less than old progress, used to detect merge strategy issues
    • Retry count distribution

    For testing, cover the following scenarios: two devices alternately playing the same content; continuous playback during a network outage and batch submission after network recovery; the same request arriving at the server repeatedly; and the client clock being manually set faster or slower. Each scenario should verify that the final progress meets expectations.