Skip to the page

Trade-offs and mobile system design · senior

Mobile system design: a chat app

A mobile chat client keeps messages in a local database, sends optimistically with client ids over a WebSocket (and falls back to push plus re-sync when the OS kills the socket), orders messages by server sequence numbers, and shows history in a list that loads older messages upward without jumping.

The notes

What you must know

  • Requirements first: 1:1 and groups, media, delivery and read receipts, typing and presence, offline send, history, push.
  • Connection: one WebSocket manager with a heartbeat, reconnect with exponential backoff and jitter, and resume from the last server sequence number to fill gaps.
  • Send: insert locally with a clientId and status "pending" → send → server ack with seq → sent → delivered → read. Retry pending messages on reconnect; the server dedupes by clientId.
  • Order by server seq, not device time. Pending messages stay at the end until acknowledged.
  • Background: the OS suspends sockets; use push (FCM/APNs) to notify and sync on open. Do not try to keep a socket alive in the background.
  • List: FlashList v2 with startRenderingFromBottom + maintainVisibleContentPosition + onStartReached (or an inverted FlatList); page history by seq.
  • Media: upload separately (resumable, with progress), then send a message that points to the uploaded file.

The red pen

Common traps: mistake → fix

  • Mistake: Polling for new messages

    Fix: wastes battery and adds latency.

  • Mistake: Ordering by device timestamps.

  • Mistake: Drawing boxes before asking for requirements.

Easy to hard

Questions interviewers ask, easy to hard

  1. Design a WhatsApp-like chat app: the client architecture and enough backend to make it work.
  2. The app goes to the background and the socket dies. How does the user still get messages?
  3. How do you keep order and avoid duplicates across reconnects?
  4. A thread has 10,000 messages. How do you render it and load older ones?
  5. Everyone reconnects at once after an outage. What happens?

Practise

Practise with these questions

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview