Offline work needs causal order where one action depends on another. Creating a request before updating it matters; uploading two unrelated photos may not require a global queue that blocks everything behind the first failure.
Model dependencies rather than relying solely on device timestamps or one long first-in-first-out list. That allows recovery to preserve meaning without unnecessarily serialising independent work.
Identify which operations depend on established results
Record logical operation identity, target resource, predecessor or base revision where needed, and the condition that makes the operation eligible. A later action may require a server-created identifier or a confirmed state transition.
Keep ordering separate from duplicate control. Executing actions in order does not prevent a retried create from producing a second record unless the server also applies the operation's identity policy.
Sequence a fictional offline request lifecycle
Suppose a user creates a request, adds a note, attaches a photo, and then cancels it while offline. Define whether the app can compact those intentions locally or must send a meaningful history. Business requirements determine whether intermediate events matter.
Test create accepted but confirmation lost, note arriving before create, attachment completed after cancellation, and an unrelated request queued behind a failed item. The final state and history should follow the chosen rules rather than network arrival order.
Reconnect with two workers and deliberately vary completion timing. Verify dependent actions wait appropriately while independent resources can progress. Preserve unresolved operations instead of marking the whole queue failed or complete.
Handle changed server state explicitly
A server edit can invalidate the base state of a queued action even when local order is correct. Check the current revision or transition precondition and apply the conflict policy. Local causal order does not establish authority over newer remote work.
Use durable sequence or dependency information so restart does not reshuffle operations based on incidental storage order. Device clocks can help display history but should not be the only source of causality.
The tradeoff is simplicity versus throughput and correctness. One serial queue is easy to reason about for a small workflow but can let one permanent failure block unrelated work. More parallelism needs explicit dependencies, concurrency controls, and clearer diagnostics.
Flutter's offline-first reference provides context. The Social App portfolio account documents related offline engineering. This request lifecycle is fictional and includes no tested queue implementation.
Questions about offline queue order
Is timestamp sorting sufficient?
Not reliably. Clocks differ, equal timestamps occur, and dependencies can matter more than wall-clock order. Preserve explicit causal information.
Should one failed operation block every later item?
Only when they depend on it. Identify independent work and define how dependent failures are surfaced or resolved.
What should a review inspect?
Inspect dependencies, duplicate rules, restart order, remote conflicts, and final business state across timing permutations. Bring the graph to a sync-ordering review.