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.
Diagram
| Step 1–2 | Scope and scale |
|---|---|
| In scope | list · read · compose/send · search · labels · offline |
| Out of scope | calendar · contacts · spam ML · attachments storage |
| Scale | 50k messages per mailbox · offline is a core requirement · multi-device: same account open in three places |
Lessons in this diagram6.5 Indexed DB
How it works
- Read path is local only — the UI queries IndexedDB, so the inbox opens instantly and works offline.
- Write path is optimistic: apply locally, enqueue in the outbox, replay on reconnect (9.1).
- Sync pulls a delta since the server watermark; full re-sync only on first login or corruption.
- Search runs locally over an IndexedDB index for cached mail, falling back to server search for older messages.
- Virtualize the message list (10.7) — 50,000 rows will not live in the DOM.
Trade-offs
| Choice | Cost |
|---|---|
| Local-first reads | Storage quota, eviction handling, migrations |
| Optimistic writes | Conflict resolution UI you must design |
| Local search index | Build cost and staleness |
| Full sync on login | Slow 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.