FSD Frontend System Design

Part VI — The Blueprint · Lesson 11.8

HLD – Email Client

In one lineAn offline-first local database that syncs both ways — the design is the sync protocol.

Where you've seen itTriaging your inbox offline, then watching every action apply correctly once you reconnect.

  • Time20 min
  • DiagramIndexedDB schema + two-way sync with a watermark
  • Chapter11 · High Level Design

Diagram

Step 1⁠–⁠2Scope and scale
In scopelist · read · compose/send · search · labels · offline
Out of scopecalendar · contacts · spam ML · attachments storage
Scale50k messages per mailbox · offline is a core requirement · multi-device: same account open in three places
diagram

Lessons in this diagram6.5 Indexed DB

diagram
diagram

How it works

  1. Read path is local only — the UI queries IndexedDB, so the inbox opens instantly and works offline.
  2. Write path is optimistic: apply locally, enqueue in the outbox, replay on reconnect (9.1).
  3. Sync pulls a delta since the server watermark; full re-sync only on first login or corruption.
  4. Search runs locally over an IndexedDB index for cached mail, falling back to server search for older messages.
  5. Virtualize the message list (10.7) — 50,000 rows will not live in the DOM.

Trade-offs

ChoiceCost
Local-first readsStorage quota, eviction handling, migrations
Optimistic writesConflict resolution UI you must design
Local search indexBuild cost and staleness
Full sync on loginSlow first run; simple correctness

Interview angle

"The user archives 20 emails offline. What happens?"

  • Each action applies to IndexedDB immediately and appends to an ordered outbox; the UI reflects it at once.
  • On reconnect the outbox replays in order with idempotency keys, so retries can't double-apply.
  • Conflicts resolve by type — label changes merge, deletes win over edits, and conflicting drafts are kept as two versions rather than silently dropped.

Recap

  • The UI reads only from the local database; the network is a background concern.
  • Sync is a server-issued watermark plus an ordered outbox, never a client clock.
  • Classify conflicts: merge commutative ops, define rules for destructive ones, never discard user text.