How to design a web app that works offline (frontend)
The first sections are free. The deep dives, level expectations and quiz are part of Pro.
On this page
- The problem
- Clarifying questions
- The requirements menu
- Non-functional requirements
- Core entities
- The API
- The high-level design
- What breaks first
- The deep dives
- Entity fields
- Changes made offline, sent later
- What the client keeps, and where
- Two devices changed the same thing
- Telling the person what state they are in
- Variants
- What each level is expected to show
- The 30-second answer
- Quiz
The problem
A web app that keeps working when the connection drops: people read and edit as before, and what they changed reaches the server once the network is back. The design turns on treating the device as the first copy of the data. Each edit is saved into the browser's database and shown right away, recorded as a change carrying an id of its own, and sent later in the order it was made, so a repeated send is applied once. The rest follows from that: a service worker caches the files the app starts from, IndexedDB holds the items and the waiting changes, the server merges field by field when two devices disagree, and the screen says what is saved on the device and what is still waiting to go out.
Clarifying questions
| Ask | Why it matters | A typical answer |
|---|---|---|
What kind of data do people edit: short items with a few fields, or large files like photos? | Items of a few fields fit in the browser's database and can be merged field by field. Files need uploads that resume, their own quota math and a different answer on conflicts. | Items with fields, such as notes or tasks. Large files such as photos and video are out of scope. |
How long is a device typically offline, and how many changes pile up? | Minutes on a train and a month on a trip call for different catch-up paths. The count of waiting changes sizes the queue and decides whether sending them one by one is fine. | No figure is given, so state your assumption: hours to a few days as the common case, with tens of changes waiting. A month offline is a follow-up the interviewer may raise. |
Do several people edit the same item at the same time, live? | Live shared editing needs a merge engine that handles concurrent edits to the same text. One person on two devices, with edits that land minutes or days apart, is a far smaller problem. | No. Several people editing the same item live is out of scope. The same person on a laptop and a phone, both editing the same item while one is offline, is in scope. |
Which browsers and devices, and is the app installed to the home screen or opened in a tab? | Browsers differ on how much a site may keep and when they clear it. Safari's clearing rule and the quota for a home-screen app change what you can promise about data kept on the device. | Phones and laptops, opened in a browser tab. Treat installation to the home screen as a separate case. |
How fast must a tap feel, with and without a connection? | It decides whether an edit can wait for the server before it shows. A budget shorter than a round trip rules out waiting for the network on the interaction path. | Within 200 milliseconds, online or not. |
Can we shape the server's API, or is it fixed to whole-item updates? | Sending changed fields with the version they were based on lets the server merge field by field. A fixed whole-item PUT pushes the design toward last arrival wins. | You shape it. Assume the server accepts changed fields with a base version and an idempotency key, and returns the merged item. |
Non-functional requirements
| Requirement | What it forces |
|---|---|
A tap answers within 200 milliseconds, online or not | The edit must be shown from a local write, with no network round trip on the interaction path. Interaction to Next Paint is the Core Web Vital that measures this, and the good threshold is 200 milliseconds. It also keeps heavy synchronous storage work off the main thread, which is one reason |
No change made offline is lost or applied twice | This is the requirement the design aims at, stated as a goal rather than a property it can promise. Waiting changes live in durable storage, not in memory, and leave the queue when the server has confirmed them. Each change carries an id of its own, sent in the |
The app never blocks the screen while it waits for the network | No full-screen spinner or modal tied to a request. Sending happens off the interaction path, in a sync layer or a service worker, and the screen shows state through marks and a short message instead. |
Kept data survives restarts, within what the browser lets the site keep | Items and the queue go in IndexedDB, the app's files in the service worker cache. The app asks for persistent storage, checks usage against quota, catches writes that fail for lack of space, and plans for the browser wiping the whole origin in one go. |
The connection state is shown in words, not by colour alone | Each state (offline, saved on the device, sending, sent) pairs a label with any icon or color, uses plain action words rather than jargon, and avoids graying out the whole app, which reads as disabled. |
Core entities
| Entity | What it holds |
|---|---|
Item | One thing the person reads and edits, as the device last knew it. |
Pending change | One edit waiting in the queue to reach the server. |
Local copy | Everything the device holds in IndexedDB, and how far it has synced. |
Connection state | What the app believes about the network right now, and what it tells the person. |
App shell | The static files that let the app draw itself before any data arrives. |
The API
| Endpoint | Notes |
|---|---|
| Pull what changed on the server since the last sync, including deletions, and a new token to send next time. Called on reconnect and on open; a long catch-up may page by repeating the call with the returned token. |
| One queued change. The key is the client's change id, so a resend after a timeout gets the stored result instead of a second application. The server merges the changed fields against its copy using |
| A fresh copy of one item, used when a change was refused or after a long gap, before waiting edits are applied on top. |
| The client API the screens use. |
The high-level design
Step 1 of 5
Screen to server
Start with the ordinary app: the screen fetches items from the server and sends each edit as it happens. It makes the data flow plain, and it fails the brief at once: with no connection the first load shows nothing, an edit has nowhere to go, and a tap waits on a round trip that won't come back within 200 milliseconds.
What breaks first
The deep dives
Changes made offline, sent later. Someone edits several items on a train with no signal, closes the tab, and opens the app again at home where the connection works. Walk through what happens to each edit, from the tap to the server.
What the client keeps, and where. Someone uses the app on a laptop for months and keeps a long list offline, then doesn't open the site for over a week while edits are still waiting. What does the app keep on the device so it opens and works with no connection, where does each part live, and what goes missing first?
Two devices changed the same thing. A laptop with no connection edits a note's title while a phone that is online changes the same note's title and text. The laptop reconnects. What does each device show, and how did each of them learn it?
Telling the person what state they are in. The connection drops while someone is editing, the device still reports being online though no page will load, and later the edits start sending again. What does the person see at each moment, and what does the app trust to decide?
Concepts this guide uses
Sources
- MDN: Storage quotas and eviction criteria
- web.dev: Storage for the web
- web.dev Learn PWA: Offline data
- web.dev: The offline cookbook
- web.dev: Offline UX design guidelines
- MDN: Background Synchronization API
- MDN: Navigator onLine property
- MDN: IndexedDB API
- IETF draft: The Idempotency-Key HTTP Header Field
- Figma blog: How Figma's multiplayer technology works
- web.dev: Web Vitals