Skip to content

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
Asked at
Practice this question

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

AskWhy it mattersA 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.

The requirements menu

RequirementScopeWhy

Open the app and read what was there with no connection

Core

The starting point of offline work: the app's own files and the data it showed last time both have to be on the device.

Create and edit items offline, each change kept on the device at once

Core

Reading without editing is a cached site. Editing offline is what forces a local copy, a queue and a conflict story.

Send changes made offline to the server when the connection returns, in the order they were made

Core

Order keeps a create ahead of the edit that depends on it, and an edit ahead of the delete that follows.

Settle changes when two devices edited the same item

Core

One person with a laptop and a phone is the case this question is about, and whole-item overwrites lose work silently.

Show the person whether they are offline and which changes are not sent yet

Core

Without it, a saved-on-device edit looks identical to a synced one, so a person can't tell what would be lost if the device were wiped.

Keep sending waiting changes after the tab is closed

Optional

Take it where the browser offers background sync and the interviewer asks about closed tabs. Leave it if time is short: sending on the next open covers most cases and works in more browsers.

Pull changes other devices made since the last sync when the connection returns

Optional

Take it: the API already has a since parameter for it, and without it the local copy drifts. Leave the details, such as paging a very long catch-up, for the follow-up about a month offline.

Let the person choose which items to keep for offline reading

Optional

Take it when the data set is large, so the device keeps what the person pinned. Leave it when the whole list fits comfortably in the browser's database.

Undo an edit made offline before it is sent

Optional

Take it if the interviewer raises it: removing a queued change before it leaves is cheap. Leave it otherwise; undo after the server has merged is a different and bigger problem.

Keep two open tabs of the app consistent with each other

Optional

Take it when asked. Both tabs share IndexedDB, but the queue must be drained by one of them at a time, which brings in cross-tab coordination.

Sign-in and accounts

Out of scope

Assume a signed-in person whose session outlives the offline stretch; expired sessions during sync are a follow-up, not the core.

Push notifications

Out of scope

A separate permission and delivery path. Nothing in offline editing depends on it.

Large files such as photos and video

Out of scope

They change the quota math and need resumable uploads, which would take the whole round.

Several people editing the same item live

Out of scope

Live shared editing needs operational transforms or a CRDT. This question is one person on two devices with edits that land apart in time.

Non-functional requirements

RequirementWhat 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 localStorage is the wrong home for the data.

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 Idempotency-Key header, which lets the server recognize a retry after a timeout and apply the change once. Two limits remain and the design should name them: a browser that evicts the whole origin before an unsent change leaves the device, which is why the app sends as soon as a request can succeed, and a key the server has already expired, which is why the server's retention window matters for a device that was away a long time.

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

EntityWhat 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

EndpointNotes

GET /items?since={sync_point} → { items, deleted_ids, sync_point }

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.

POST /changes, Idempotency-Key: {change_id}, { item_id, fields, base_version } → { item, version }

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 base_version and returns the whole merged item.

GET /items/{id} → item

A fresh copy of one item, used when a change was refused or after a long gap, before waiting edits are applied on top.

Client: save(item) writes locally and queues the change; status() → { online, waiting, last_synced_at }

The client API the screens use. save writes the item and its change to IndexedDB in one transaction and returns once the local write is done, so the tap answers from the device. status feeds the message and the marks.

The high-level design

edititemsScreenServer

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.

installshellsavechangeorderedPOSTGETmergedconfirmedoutcomehintcountstatuspersistquotawakeService workerApp shell cacheScreenItems inIndexedDBChange queueSync layerServerConnection stateOnline eventsStorage managerBackground sync
The whole design

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.

A concept that helps here: Sync queues and client idempotencyA concept that helps here: Idempotency keysA concept that helps here: Optimistic updates and rollback

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?

A concept that helps here: Offline-first storageA concept that helps here: Where state lives

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?

A concept that helps here: Conflict resolution on the clientA concept that helps here: Conflict resolution

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?

A concept that helps here: Partial failure in the UIA concept that helps here: Reconnect and resume

Concepts this guide uses

Sources

  1. MDN: Storage quotas and eviction criteria
  2. web.dev: Storage for the web
  3. web.dev Learn PWA: Offline data
  4. web.dev: The offline cookbook
  5. web.dev: Offline UX design guidelines
  6. MDN: Background Synchronization API
  7. MDN: Navigator onLine property
  8. MDN: IndexedDB API
  9. IETF draft: The Idempotency-Key HTTP Header Field
  10. Figma blog: How Figma's multiplayer technology works
  11. web.dev: Web Vitals
Sign in to report a mistake