Sync Service

Data synchronization between online/offline modes, conflict resolution, and delta sync

Sync Service (Port 8003)

The sync-service manages data synchronization between ODK Collect devices and the MQUAD platform, handling conflict resolution and delta sync.

Database

Database: sync_db

TablePurpose
devicesODK device registrations

API Endpoints

All sync endpoints are prefixed with /api/v1/sync to maintain compatibility with mobile client routing.

MethodPathPurpose
GET/api/v1/sync/devicesList registered devices
POST/api/v1/sync/devicesRegister a new device
POST/api/v1/sync/pullPull delta changes from server
POST/api/v1/sync/pushPush idempotent changes from device
GET/api/v1/sync/conflictsList unresolved sync conflicts

Sync Flow

ODK Collect ──► Traefik (:80) ──► sync-service (:8003) ──► data-service (:8002)
                                          │
                                     conflict check
                                          │
                                    ┌─────┴─────┐
                                    │  Accept    │
                                    │  or        │
                                    │  Reject    │
                                    └───────────┘

Conflict Resolution

The sync-service detects conflicts during push operations and supports multiple strategies:

  1. Last Write Wins (Default) — Uses the most recent updated_at timestamp.
  2. Server Wins — Keeps the server record and rejects the client change.
  3. Client Wins — Overwrites the server record with the client data.

Delta Sync

The service implements an efficient delta sync mechanism:

  • Only transfers records modified after the client's last_sync_at timestamp.
  • Returns a list of deleted IDs to ensure local client cleanup.
  • Uses a sync_token for sequential tracking of synchronization batches.