Overview of Cross-Device Data Synchronization Within the Same Application
Note:
Currently in the beta phase.
Scenario Introduction
Cross-device data synchronization (also known as distributed functionality) refers to synchronizing data to other devices within a networked environment. It is commonly used for freely synchronizing, modifying, and querying user application data content across different devices with trusted authentication.
For example: When Application A on Device 1 adds, deletes, or modifies data in a distributed database, Application A on Device 2 can also detect these database changes. This functionality can be applied in scenarios such as distributed photo galleries, memos, contacts, file managers, etc.
Based on the lifecycle of cross-device synchronized data, it can be categorized into:
- Temporary Data: Has a shorter lifecycle and is typically stored in memory. For example, process data generated by gaming applications is recommended to use distributed data objects.
- Persistent Data: Has a longer lifecycle and needs to be stored in a database. Depending on data relationships and characteristics, either a relational database or a key-value database can be chosen. For instance:
- Attributes like photo albums, covers, and images in a gallery application are recommended to use a relational database.
- Thumbnails of specific images in a gallery application are recommended to use a key-value database.
Basic Concepts
In distributed scenarios involving multiple devices, the consistency of data observed across networked devices is referred to as distributed database consistency.
Distributed database consistency can be classified into:
- Strong Consistency: After a device successfully adds, deletes, or modifies data, any device in the network can immediately read the updated value.
- Weak Consistency: After a device successfully adds, deletes, or modifies data, other devices in the network may or may not read the updated data. There is no guarantee on how long it will take for all devices to reach consistency.
- Eventual Consistency: After a device successfully adds, deletes, or modifies data, other devices in the network may not immediately read the updated data. However, after a certain time window, all devices will eventually reach a consistent state.
Strong consistency imposes extremely high requirements on distributed data management and is typically encountered in server-based distributed scenarios. Due to the intermittent connectivity and decentralized nature of mobile terminal devices, cross-device data synchronization within the same application does not support strong consistency but only eventual consistency.
Cross-Device Synchronization Access Control Mechanism
During cross-device data synchronization, data management is governed by device levels and data security labels for access control. For details, refer to Cross-Device Synchronization Access Control Mechanism.