Mobile App Developer · Focus area 2: Mobile architecture
MA5: Offline-first sync: outboxes, retries and conflicts
Goal: build an app that saves first on the phone and syncs when it can: keep an outbox of changes, send each once even when answers are lost, retry patiently with deadlines and backoff, fetch only what changed, settle conflicts by clear rules, and tell the user in plain words whether their work is safe.
You'll need: MA4, Module 24 (Asynchronous Programming), Module 47 (REST API Design), Module 57 (Transactions and Indexes), Module 94
(Distributed Systems), and the KhetNote practice kit (src/sync/, server/, tests/offline.test.js).
Where this is used: field apps, messaging, notes, email, maps and any app used on trains, in lifts or in villages. Offline-first apps feel fast everywhere, because saving never waits for the network.
How it differs: a simple app asks the server and shows an error when there's no signal. An offline-first app treats the phone's copy as the place work happens, and the network as something that comes and goes.
Time: reading about 3 hours · practice (the Try it tasks) about 3 hours · assignment about 5 hours.
Lessons
- 1Save first, sync laterReading 15–25 minutes, plus practice✓
- 2Sending each change onceReading 15–25 minutes, plus practice✓
- 3Deadlines, retries and backoffReading 15–25 minutes, plus practice✓
- 4Fetching what changedReading 15–25 minutes, plus practice✓
- 5Conflicts and what the user seesReading 15–25 minutes, plus practice✓
🛠️Assignment: Make KhetNote work offline
- Make saving write to the store and the outbox, without waiting for the network.
- Make the sync engine send changes oldest first with idempotency keys, and start when the connection returns.
- Add the 10-second deadline, backoff with jitter, and marking refused changes as failed.
- Fetch changes since the stored cursor, and keep waiting changes on screen.
- Handle 409s by the merge rule, recording clashes, and show one status message.
- Write
docs/sync-design.md, then runnpm run test:offline.
Self-check before you finish:
- [ ] Saving works with no connection, quickly (test 2).
- [ ] A change whose answer was lost is stored once (test 5).
- [ ] Refused changes don't block the rest (test 6).
- [ ]
npm run test:offlinepasses 10 of 10.
✅Module check
Explain in a few sentences, in your own words:
How does an offline-first app keep the user's work safe and get it to the server?
Show a good answer
A good answer mentions: saving to the phone first with a pending state and an outbox of changes in order, removed only when the server confirms; idempotency keys so repeated sends are stored once; syncing after saves, on reconnect and regularly; deadlines on every request, backoff with jitter for temporary failures, and failed marks for refused changes; fetching changes since a stored cursor while keeping waiting changes on screen; versions, 409s and a written conflict rule that keeps edits and flags clashes; and one plain status message, announced to screen readers.
📚Official references
Official documentation and guidance for this module's topics, chosen on 2 November 2026. Tools, laws and standards change, so check the current version before you rely on a detail. If a link has moved, search the same site.
📝Module quiz
10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·
