Skip to content

UC-ING-501: Multi-Protocol Data Ingestion

1. Metadata

Property Value
ID UC-ING-501
Actor System (Integrated Mobile App)
Trigger Restoration of network connectivity or manual 'Sync Now'
Pre-conditions Locally queued health records exist in SQLite; Backend API is reachable
Post-conditions Records moved to PostgreSQL; Local queue cleared; Verification hash logged
Side Effects Trigger Daily Report recalculation if the record date is current

2. Description

Manages the reliable transfer of sensitive nutritional and health data from field devices to the central Cloudflare/PostgreSQL backend, ensuring zero data loss during connectivity transitions.

3. Success Scenario

  1. Connectivity Detection: Mobile app detects a transition to 'Online' state (status code 200 from heart-beat endpoint).
  2. Batch Selection: System retrieves all records with sync_status = PENDING from the local database.
  3. Payload Preparation: System bundles records into a JSON array, including a Client-Side Hash for integrity checks.
  4. Transmission: App initiates an HTTPS POST request to the /v1/ingest/sync endpoint.
  5. Server-Side Validation:
    • Backend validates JWT authentication.
    • Backend re-calculates the hash to ensure the payload wasn't tampered with in transit.
  6. Persistence:
    • Backend performs an 'Upsert' operation on the PostgreSQL table using the Unique record_id.
    • Backend marks records as persisted and returns a 201 Created acknowledgment.
  7. Cleanup: Mobile app receives the success response and updates the local SQLite status to SYNCED or removes the record based on rotation policy.

4. Acceptance Criteria

  • [ ] Reliability: 100% data delivery for packets up to 5MB over 3G connections.
  • [ ] Integrity: Hash mismatch must trigger an immediate re-transmission of the specific packet.
  • [ ] Data Efficiency: Payloads must be Gzipped if the record count > 20.
  • [ ] Security: No health data should be transmitted in plain text; TLS 1.3 is mandatory.

5. Sync Logic (Retry Strategy)

flowchart TD Sync[Sync Trigger] --> Batch[Batch pending records] Batch --> Hash[Generate SHA-256 Hash] Hash --> Transmit[HTTPS POST /v1/ingest/sync] Transmit --> Resp{Status 201?} Resp -- Yes --> Clear[Clear Local Queue] Resp -- No --> Retry[Exponential Backoff Retry]