Geo Tracking - Specs

Queue and synchronization

Persistence before upload, acknowledgment by ID, deduplication, and recovery from route transport failures.

The delivery rule

A location leaves the device queue only when the server acknowledges its eventId. The normal sequence is capture → persist → send → acknowledge → remove.

This acknowledgment is known as an ACK. HTTP 2xx alone is not enough: the upload response must contain IDs from the submitted batch and a valid remote configuration.

The mechanism supports retries. It aims to preserve events through network failures, but does not promise that an HTTP request will run exactly once.

What is persisted

ItemAndroidiOS
Pending positionsSQLite geo-tracking.dbSQLite outbox.sqlite
Local orderAuto-incrementing sequenceAuto-incrementing sequence
Local uniquenessUnique event_idUnique event_id
Latest position and countersmetadata tableTransactional JSON in the state table
Remote configurationPersisted metadataPersisted state
Local authorizationPrivate preferencesPersisted state
Native tracking tokenPrivate preferencesKeychain

Both databases use WAL and synchronous=FULL. Inserting a location and updating its associated state happen in the same transaction.

The record stores the complete event, including its source, timestamp, and configuration version. A retry reads that record; it does not create another UUID or change capturedAt to the retry time.

Batches and ordering

The next upload contains up to 100 positions in local database insertion order. This matches the maximum accepted by the upload API.

Only one synchronization can be in progress per native service. While a request awaits its response, new events can enter the queue and will be processed afterward.

Upon receiving a valid ACK, the service removes acknowledged IDs, updates uploadedCount, and checks for pending records. If any remain, it starts the next batch.

Local upload order does not determine how history is displayed. The server queries positions by capturedAt and eventId, preserving the temporal meaning of samples received late.

Synchronization contract

SituationRequestExpected result
Empty queueGET /api/devices/:deviceId/configRemote configuration
Records in the queuePOST /api/devices/:deviceId/locationsacknowledgedEventIds and config
AuthenticationAuthorization: Bearer … headerCredential authorized for the device
Normal transportHTTPSLocal HTTP only in development builds

The token is not sent in the URL, and redirects are disabled in the native transports. The queue's identity is the endpoint and device pair; changing it cannot redirect existing pending records.

Android requires a stopped session, an empty queue, and no upload in progress to change identity. iOS requires an empty queue and resets session state when identity changes.

Partial acknowledgment and invalid responses

The client determines which response IDs belong to the submitted batch. An ID from another batch cannot delete an arbitrary pending position.

If the server acknowledges only part of a batch, only that part leaves SQLite. The remaining records stay available for another upload.

If no ID from the batch is acknowledged, the operation is treated as a failure and the queue remains intact. Invalid JSON, invalid configuration, HTTP errors, or persistence failures also prevent normal acknowledgment.

Local counters track the removal of acknowledged events. uploadedCount is not a live query of the server's global total; records sent by other sources or installations do not automatically contribute to this counter.

How the server prevents duplication

The Worker routes the device to its Durable Object with SQLite. The batch is written in a transaction; the server returns acknowledged IDs only after the persistence step.

For each event, the server checks eventId:

  1. New ID: inserts the record and receivedAt.
  2. Existing ID with identical content: acknowledges the retry without duplicating the row.
  3. Existing ID with different content: returns 409 event_conflict and rolls back the batch.

This handles lost ACKs: the server may have saved a position before the connection dropped. The device sends it again with the same ID; the server acknowledges the existing row; the client then removes it from the queue.

WebSocket notifications include only newly inserted records. An identical retry does not need to produce a second position on the dashboard.

Retries and connectivity recovery

BehaviorAndroidiOS
Initial delay after failure2 seconds2 seconds plus 0–1 second of jitter
ProgressionExponentialExponential
Current effective maximum delay256 seconds256 seconds plus 0–1 second of jitter
Network recoveryConnectivity callbackNWPathMonitor
Periodic checkEvery 15 seconds with a session or queued records2-second timer while executing
Empty-queue query after successApplicable periodic checkNext configuration query after at least 10 seconds

The calculation includes a 300-second ceiling, but the failure counter saturates at 8, so the exponential value reaches 256 seconds. These timings are process policies, not guarantees that the system will wake the app.

Manual synchronization can bypass the retry delay, but does not create a second simultaneous request. Captures and connectivity events can also provide opportunities to synchronize.

Storage limits

The client does not discard positions at a 10,000-record threshold. The SQLite queue grows according to available storage. Native tests include scenarios with 10,005 records; this demonstrates an exercised scenario, not a guaranteed storage reservation on every device.

If a new sample cannot be persisted, collection pauses or stops with an explicit error. The code preserves previous rows and does not silently select older events for deletion.

On the server, the current limit is 100,000 events per device. A batch that would exceed capacity receives 507 device_capacity and is rolled back. Retries of existing IDs continue to be acknowledged when they do not require new rows.

There is no automatic implementation of time-based retention, archiving, or export followed by cleanup. Reaching capacity requires an operational decision; retrying the request does not free space.

Diagnosing state in the interface

IndicatorInterpretation
Increasing pendingCountCaptures are being persisted, but the queue has not yet been acknowledged
Increasing uploadedCountThe client removed acknowledged positions
Recent lastSyncAtSynchronization succeeded; it may have only fetched configuration
lastErrorStorage, collection, operation, or transport failure, depending on the platform
lastLocationLatest locally persisted position, including synthetic positions

A zero count does not prove that GPS produced positions: a newly configured session can also have an empty queue. To validate collection, compare the source, timestamps, counts, and dashboard history.

Transport errors are reduced to operational messages; the module's public state does not contain the token. Shared logs and evidence should preserve this separation too.

Two different queues in the project

The queue described on this page is the HTTP route queue. The polygon demo keeps events such as polygon_enter and polygon_proximity in native preferences, with pending, delivering, failed, delivered, and superseded states.

In that demo, simulate delivery only changes local state. It is not an acknowledgment from the Worker and does not use the SQLite/ACK mechanism described above. See Polygons.

Repository sources

  • geo-demo/modules/geo-monitoring/android/src/main/java/expo/modules/geomonitoring/TrackingStore.kt
  • geo-demo/modules/geo-monitoring/android/src/main/java/expo/modules/geomonitoring/TrackingEngine.kt
  • geo-demo/modules/geo-monitoring/android/src/main/java/expo/modules/geomonitoring/TrackingTransport.kt
  • geo-demo/modules/geo-monitoring/ios/GeoTrackingStore.swift
  • geo-demo/modules/geo-monitoring/ios/GeoTrackingService.swift
  • tracking-server/src/index.ts
  • docs/tracking-contract.md

On this page