The common mistakes
- Treating the server as the only source of truth, so every action blocks until a request returns.
- Showing a failed request as an error the driver must solve, in the middle of a delivery.
- Uploading photos and signatures in the same request as the status update, so a weak connection loses both.
- Recording the time the server received an event, rather than when it happened.
- Having no visible sign of what has synced and what has not.
Write locally first
The fix is to change the order of events. Every action is saved to the device first, then synchronised in the background. The driver gets instant confirmation and moves on, and the network becomes a detail the app handles on its own.
Capture
Photo, signature, location and timestamp are collected on the device.
The outbox pattern
An outbox is a durable local queue. Each event carries an ID generated on the device, and that ID doubles as an idempotency key. If a response is lost and the app sends the event again, the server sees the same ID and does not record a second delivery.
interface DeliveryEvent {
id: string; // crypto.randomUUID(), set when captured
stopId: string;
capturedAt: string; // device time, ISO 8601
photoRef: string; // uploaded separately
}
async function recordDelivery(event: DeliveryEvent): Promise<void> {
await outbox.add(event); // durable local write comes first
void flushOutbox();
}
async function flushOutbox(): Promise<void> {
for (const event of await outbox.pending()) {
try {
const res = await fetch('/api/deliveries', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Idempotency-Key': event.id,
},
body: JSON.stringify(event),
});
if (!res.ok) return; // keep it queued, retry later
await outbox.remove(event.id);
} catch {
return; // offline: try again on the next trigger
}
}
}
The outbox and the API are yours to implement. On native apps, schedule flushing with WorkManager on Android or background tasks on iOS, so sync continues when the app is not on screen. Upload media as a separate step and link it to the event by ID.
Show the driver what is happening
Good offline design is honest. A small indicator such as "3 waiting to sync" reassures the driver that nothing is lost, and it warns them before they log out or hand over the device. Dispatchers need the same honesty: label a stop as "last seen 12 minutes ago" rather than presenting old data as live.
Test it where it fails
Add scenarios to your test plan for airplane mode during an upload, a connection that drops mid-request, the app being killed with events in the queue, and a full day of queued work syncing at once. Then ride along with a driver for a shift. A day on a real route will show you more about your app than any office test.