Skip to the page

System design prompts · senior

Chat app, news feed and file storage

Three big prompts with a common shape: split the fast path from the heavy path, partition by the right key, and make retries safe. They are chat, a social feed and cloud file storage.

The notes

What you must know

  • Chat: long-lived WebSocket connections to gateway servers and a session registry (user to gateway) in Redis. The phone sends with a client message id; the chat service writes it durably and gives a sequence number per conversation, then pushes it to the receiver gateway. Offline users have an inbox and a push notification.
  • Order by the server sequence per conversation, never the phone clock. Dedupe retries by (sender, client message id) with a unique constraint. Storage: a wide-column store partitioned by conversation id and sorted by sequence.
  • Numbers: 50 crore users times 40 messages is 2,000 crore messages a day, about 2.3 lakh a second on average and more at peak. Duplicates and disorder happen when retries are treated as new messages, or when group events are keyed by message id and spread across partitions: use the conversation id as the partition key.
  • News feed: very read-heavy. Fan-out on write (push post ids into follower feed lists in Redis) makes reads cheap. Fan-out on read suits huge accounts. Use a hybrid: push for normal accounts, pull and merge for celebrities.
  • Feed lists hold post ids only, capped (say 500 to 1,000). Cursor pagination, never offset. Fan-out runs async through Kafka workers. If ranking times out, fall back to chronological order or a cached feed. Like counts are in a separate approximate counter service.
  • File storage: split metadata (SQL, sharded by user) from bytes (object storage). Chunked resumable uploads of 4 to 8 MB direct to object storage with pre-signed URLs. A hash per chunk allows dedupe and re-upload of only changed chunks.
  • Sync: a change journal per user with a cursor. Conflicts: compare the base version and keep both copies, never silently overwrite. 10 crore users times 5 GB is 500 PB, so dedupe, compression and cold storage classes matter.
  • Never upload files through app servers, store files in the database, or fan out to 5 crore followers synchronously.

The red pen

Common traps: mistake → fix

  • Mistake: Phones poll every second

    Fix: use persistent connections and push.

  • Mistake: Order by the phone clock

    Fix: use a server sequence.

  • Mistake: Fan out to all followers synchronously

    Fix: use async workers and a hybrid.

  • Mistake: Last write wins for files

    Fix: it loses an edit silently.

Easy to hard

Questions interviewers ask, easy to hard

  1. Design a chat app like WhatsApp.
  2. Messages show twice and out of order. Why and how do you fix it?
  3. Design a news feed. How do you handle a celebrity?
  4. Design file storage like Google Drive.
  5. How do you resolve sync conflicts?

Practise

Practise with these questions

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