Module 14 Β· Persistence & Offline-First β Lesson 4 of 4 Β· ~9 min
A sync engine, honestly
Queued writes: a pending-operations list
WalkRepository.record(_:) from the last lesson saves locally first, then tries the network β but try? on that upload silently drops the failure. Offline-first means that failed write can't just vanish: it needs to be retried once a connection comes back. The standard shape is a pending-operations list β its own persisted model, separate from WalkRecord β that records "this thing still needs to reach the server."
On reconnect, replay in order: walk the pending list oldest-first, retry each one, remove it once the server confirms. Order matters β replaying a cancel before its booking even reached the server would be nonsense.