Background Network Queue Sync Service

Introduction and Problem Statement

Intro:

This documents describes the proposed design for tackling data sync over http for mobile client.

Problem:

  • Mobile client collects, aggregates and persists data that periodically gets sync’ed to the server. This data has no significance to the UI and is never queried and rendered. The sync is still initiated and resolved on the same main UI thread impacting performance.

  • Furthermore, this data is isolated into multiple sync pipelines corresponding to their sources. Some pipelines identified so far would be - telemetry sync, course state sync and assessment state sync. Each pipeline would raise its own coroutine again impacting performance and resources.

Proposed Solution

  • To build and utilise a native Cordova plugin raising its own process for sync pipelines. This would free the Webview process and improve performance.

  • To implement an abstract network queue as a priority queue. The only action applied on aggregated data is a network call to sync client data to server, this can be achieved with a single pipeline with single responsibility of data sync irrespective of data type using a priority queue. This unifies existing pipelines and is also extensible for any future pipelines.

Cordova Plugin Design

  • TODO

Network Queue Design

  • In order for the Queue to be extensible. The Queue can hold generic Network Http Requests.

  • The Queue needs to retain state, will handle mutations by persisting and querying a DB implementation.

Database DDL

  • Proposed DB Schema for persistence -

  • The Queue would prioritise over the field ‘priority’ and if equal would prioritise over lesser ‘timestamp’

Service API

  • The Queue API should not be coupled with any specific data-sync-type rather to type Network Request that wrap all data-sync-type(s)

  • Sensitive data like tokens should not be persisted, alternatively flags can be used

  • Proposed interface -

  • Following flow diagram represent queue method trigger points and sync flow -