I started thinking about offline exam practice as a connectivity problem.
Download questions, store them in the browser, and let the learner continue when the network disappears.
That description misses the difficult part. The application is not merely displaying cached content. It is preserving an attempt: which question version was shown, when the clock began, which answers existed at submission, and whether later analytics can still explain the result.
Local-first exam software is a data-integrity problem with an interface attached.
The attempt needs its own identity
An attempt should not be derived from whatever happens to be in the current screen state.
I want a durable record created when the learner starts:
tstype Attempt = { id: string startedAt: string expiresAt: string status: class="syntax-string">"in_progress" | class="syntax-string">"submitted" | class="syntax-string">"expired" questionSetVersion: string questionIds: readonly string[] answers: Readonly<Record<string, string>> }
The exact types vary, but the principles are stable. The attempt has an identity, fixed timing boundaries, a content version, and a durable answer map.
Refreshing the page should reopen the same attempt rather than generating a convenient new one.
Store deadlines, not countdowns
A countdown value such as "1,742 seconds remaining" becomes unreliable when the tab sleeps, the app closes, or the device reboots.
The durable facts are the start and expiry timestamps. The interface derives the current countdown from the clock:
textremaining = expiresAt - now
When the application resumes, it recalculates. If the deadline has passed, it transitions the attempt once into an expired or submitted state according to the product rules.
This does not solve malicious clock changes by itself. It does make normal interruption and background suspension predictable.
Questions change after an attempt
Question banks are living datasets. Wording is corrected, answer keys are reviewed, options are reordered, and invalid items are removed.
If historical analytics always join an attempt to the latest question record, yesterday's score can change without the learner doing anything.
There are two common solutions:
- Snapshot the relevant question content into the attempt.
- Store a content version and retain the versioned question set.
The second approach uses less duplicated data but requires disciplined version retention. The first makes each attempt self-contained but increases storage.
What I avoid is silently calculating history against unrelated current content.
If the exact historical content is unavailable, analytics should say the attempt cannot be fully reconstructed. Guessing is worse than an explicit gap.
Submission must be idempotent
A learner can press submit, lose connectivity, and press again. The application may also resume while the first submission is still being synchronised.
Local submission should be one durable state transition. Remote synchronisation should carry the stable attempt identity and tolerate repetition.
textin_progress -> atomically store final answers and submittedAt -> submitted locally -> enqueue remote sync
The UI can acknowledge the local submission immediately while showing that account synchronisation is pending. It should not tell the learner the attempt vanished because the network did.
Offline does not mean anonymous state
When accounts are involved, local data must remain scoped to the right person. Logging out should not expose the previous learner's attempts to the next person using the device.
Depending on the sensitivity and platform, that may require:
- Separate local namespaces per account.
- Encryption backed by platform storage.
- Explicit deletion on logout.
- Clear device-sharing warnings.
- A guest-to-account migration flow.
Local-first architecture moves responsibility onto the device. It does not remove privacy requirements.
Synchronisation should preserve evidence
The server may receive an attempt long after it was completed. It should preserve client timing, content version, and original attempt identity while recording when synchronisation occurred.
Those are different clocks:
startedAt: when the attempt began.submittedAt: when the learner finished locally.syncedAt: when the server received it.
Collapsing them into one server timestamp makes offline history look dishonest.
Conflicts should also be explicit. If the server already has a final version of the same attempt, a late client should not overwrite it silently.
Test the interruptions people actually experience
The useful tests are not only "does the page render offline?"
I want to test:
- Refresh during an active attempt.
- Close and reopen after several minutes.
- Let the deadline pass while the app is closed.
- Submit with the network disconnected.
- Submit twice after a timeout.
- Update the question bank before viewing old analytics.
- Switch accounts on the same device.
- Reconnect with several pending attempts.
These are ordinary mobile and browser behaviours, not exotic failures.
Local-first changes the source of truth
In a conventional online application, the server usually decides whether an action exists. In a local-first exam, the device may hold the first durable truth about an attempt for hours or days.
That can create a faster and more resilient experience, especially where connectivity is unreliable. It also means the local schema, transition rules, and synchronisation protocol deserve the same seriousness as a backend database.
Caching makes content available. Correct local-first design makes the learner's history believable.