Proposed Approach:
Local Database as SSOT:
The UI always reads data from the local database (e.g., using Flow from Room DAO).
Online Mode:
User actions update the local database first and asynchronously make an API call to update the server.
During a conflict, the server applies a resolution strategy (e.g., Last Write Wins, Operational Transformation) and sends the updated data.
WebSockets push real-time updates, ensuring the local database (and therefore the UI) stays in sync.
Offline Mode:
Changes are stored in the local database as well as in a another Sync DB table (to track pending actions).
A background worker (e.g., WorkManager) syncs pending changes from Sync DB table once the network is available.
Advantages I See:
✔ Consistent UI state since data always comes from the local database.
✔ Seamless offline support without handling different flows for online/offline.
✔ Reduced API load, as only necessary sync operations can be performed in batch.
✔ Backend handles conflict resolution, avoiding UI inconsistencies.
Potential Concerns:
< /code>
Вопросы: < /p>
Is this a scalable and maintainable approach for real-time applications?
Are there any downsides compared to a hybrid approach (directly interacting with the server when online)?
Would love to hear your insights!
Подробнее здесь: https://stackoverflow.com/questions/794 ... or-real-ti