Cross-Device Playback Sync and Interaction Systems: Engineering Practices

    This article describes an engineering approach to synchronizing playback progress and interaction data across multiple devices. It covers data modeling, throttled and idempotent reporting, conflict merge rules, local-first resume playback, danmaku and comment handling, favorites and notifications, login and device management, observability, and capacity estimation. Readers can use these practices to design a system that keeps high-frequency playback state eventually consistent while preserving a smooth playback experience.

    1. Problem Background and Requirement Breakdown

    In video, audio, and content platforms, users often switch between phones, tablets, computers, and TVs. They expect the progress they reached on one device to continue on another. This is a typical user-state synchronization problem: playback records under the same account need to remain eventually consistent across multiple terminals, while causing no noticeable disruption to playback.

    From a product perspective, this type of system usually includes the following categories of functionality:

    • Playback records: content identifier, episode or chapter, playback position, update time, and device identifier.
    • Interactive content: publishing, displaying, reporting, and moderating danmaku or comments.
    • Personal assets: favorites, subscription lists, and history.
    • Account and messages: login and registration, identity verification, in-app messages, and activity push.

    These features have very different data characteristics. Playback progress is written frequently, each record is small, and latency matters. Favorites and messages are written less often, but they require higher consistency and traceability. If they are handled by the same storage and API layer, the high-frequency path will slow down the low-frequency path. Therefore, the design should separate them by data characteristics from the beginning.

    The requirements can be summarized in three points:

    1. Cross-device resume: after switching devices, the playback position error should remain within an acceptable range. A few seconds can serve as a starting point for acceptance criteria.
    2. Reporting should not disrupt playback: reporting must not block playback, and when the network fails, data should be stored locally first.
    3. Merging should be explainable: when multiple devices write concurrently, conflict rules must be clear and the result predictable.

    2. Data Model for Playback Progress

    The minimal playback progress record can be designed as a structure. Key fields include user identifier, content identifier, episode identifier, playback position in milliseconds, total content duration, device identifier, logical version number, and server receive time.

    1. PlaybackRecord {
    2. user_id: string
    3. content_id: string
    4. episode_id: string
    5. position_ms: int64
    6. duration_ms: int64
    7. device_id: string
    8. version: int64 // Monotonically increasing logical version number
    9. updated_at: timestamp
    10. }

    The primary key can use (user_id, content_id) so that only one latest progress record is retained for the same content. If the product needs to retain independent progress for each episode, episode_id should be included in the primary key. The tradeoff between the two approaches depends on whether the product displays progress for multiple episodes, and the choice should be based on business requirements rather than intuition.

    A version number is more reliable than a client timestamp. System clocks on different devices may be skewed, and using client time directly to determine order can cause newer progress to be overwritten by older data. The server can assign a version number when writing, or the client can carry a monotonically increasing sequence number. Either approach avoids this problem.

    3. Reporting Strategy: Throttling, Batching, and Local Cache

    The player continuously generates position information. If a network request is sent on every change, it will produce a large number of invalid writes. Common approaches include the following three:

    • Periodic reporting: report once every fixed interval, such as every 15 to 30 seconds.
    • Event reporting: report immediately on pause, episode switch, page exit, or when the app enters the background.
    • Local buffering: when the network is unavailable, write to a local queue first, and replay in order after the network recovers.

    The pseudocode is as follows:

    1. on_tick(position):
    2. local_cache.put(content_id, position, now())
    3. if now() - last_sent >= INTERVAL:
    4. flush_async(local_cache.latest(content_id))
    5. on_event(PAUSE | EXIT | BACKGROUND):
    6. flush_async(local_cache.latest(content_id))
    7. flush_async(record):
    8. enqueue_upload(record) // Send on a background thread; keep in the queue and retry on failure

    The reporting API should be idempotent. When the same record is submitted multiple times due to retries, the server uses the version number to decide whether to overwrite it, so the final result remains consistent. The retry interval should use exponential backoff with random jitter to avoid a large number of clients hitting the server at the same time.

    4. Conflict Merge Rules

    Multiple devices being online at the same time is common. For example, a user watches up to minute 12 on a phone and minute 8 on a TV. The server needs clear merge rules. There are three common rules:

    1. Last write wins: the record with the largest version number overwrites the old record. This is the simplest to implement, but it may lose farther playback progress.
    2. Take the maximum position: suitable for linear content, since users usually want to keep the furthest position they have watched. However, if the user intentionally seeks backward, this rule will not match expectations.
    3. Keep a candidate list: the server returns multiple candidates and the user chooses. This has a higher interaction cost and is suitable for important content.

    In most scenarios, last write wins can be used as the default rule, and the client can explicitly specify a position in specific scenarios, such as when the user explicitly clicks “resume from last position.” Merge rules should be written into the API documentation, and tests should cover boundary cases such as seeking backward, concurrent writes, and network latency.

    5. Read Path for Resume Playback

    The read side should follow a local-first, remote-second principle. When entering the page, read the locally cached progress and immediately display the resume entry, while asynchronously requesting the server. If the server returns a higher version number, update the position of the resume entry. In this way, even if the network is slow, the user will not see a blank screen.

    The response of the read API should return only necessary fields and support batch queries by content, avoiding one request per item on list pages.

    6. Interaction Modules: Danmaku and Comments

    Danmaku and comments have different data characteristics from playback progress. They are content-type data and need moderation, filtering, and risk control.

    Danmaku is usually bound to the playback timeline. The data structure can record content identifier, episode identifier, appearance timestamp, text, display style, and sender identifier. During display, the client fetches data in time-window segments and renders incrementally during playback. To reduce bandwidth pressure, data for adjacent time segments can be preloaded.

    Comments are closer to a traditional tree structure. Each comment record includes parent comment identifier, root comment identifier, floor number, like count, and status. Deletion and blocking should use logical deletion and retain audit records for later traceability.

    Main risks include sensitive content filtering, send rate limiting, duplicate content recognition, and report handling. These capabilities are usually handled by an independent moderation service. The interaction API is only responsible for recording write requests and initial status, and moderation results are written back to the data store asynchronously.

    7. Favorites, Subscriptions, and Notifications

    Favorites and subscriptions are user assets and should be guaranteed not to be lost or duplicated. A unique constraint can be created on “user identifier + content identifier.” When a user favorites the same content repeatedly, the API returns the existing result instead of an error.

    Notifications are usually event-driven. Events such as content updates, comment replies, and favorited content going online enter a message queue. Consumers generate in-app messages and send them according to the user’s push preferences. Push failures should not affect the main flow; the system should record the failure reason and support retries.

    8. Login State and Device Management

    Multi-device synchronization depends on a unified identity system. After a client logs in, it obtains a short-lived access token and a long-lived refresh token. When the access token expires, the client uses the refresh token to obtain a new access token. The refresh token should be bound to the device identifier, and users should be allowed to view logged-in devices in account settings and revoke a specific device as needed.

    After a device is revoked, the server should reject subsequent reports from that device, and the client also needs to clear its local cache. This step is easy to overlook, but it is important for account security and privacy protection.

    9. Observability and Capacity Estimation

    Core metrics for the synchronization system include reporting success rate, end-to-end synchronization latency, conflict overwrite count, and local queue backlog length. It is recommended to set alert thresholds for each metric and observe them split by device type and region.

    Capacity estimation can start by estimating the number of daily active devices and the average number of reports per device, then multiplying by the size of a single record. The following is a hypothetical example: 1 million daily active devices, 200 reports per device per day on average, and about 200 bytes per record. This gives about 200 million write requests per day and about 40 GB of data per day. Actual numbers should be based on real business data, with peak headroom reserved.

    10. Summary

    Cross-device playback records may look simple, but they actually involve data modeling, throttled reporting, version merging, offline caching, and identity management. Separating high-frequency progress data from low-frequency asset data and using clear version rules to resolve conflicts is the foundation for stable operation of this type of system.