Design chat, a news feed or notifications

11 system design interview questions on chat, news feeds and notifications, each with the correct answer and a full explanation.

Messages in a conversation must appear in the same order on every device. What provides that order?
Show answer

Answer

A per conversation sequence number assigned where the conversation is owned
One owner per conversation (its partition or leader) can assign a monotonically increasing sequence, and clients sort by it. Client clocks skew and can be set to anything. Wall clocks on different servers also drift. A global sequence is a needless bottleneck when ordering only matters within a conversation.

Source: System Design Interview: An Insider's Guide, Volume 1, How Discord Stores Trillions of Messages

A phone was offline for 2 hours. On reconnect, how does it get exactly the messages it missed?
Show answer

Answer

It sends its last seen sequence per conversation and the server returns everything after
A sync cursor makes catch up cheap and exact. Resending everything wastes bandwidth. Push delivery is best effort and coalesced, not a reliable transport. Client clocks are skewed, so a time based query misses or repeats messages.

Source: System Design Interview: An Insider's Guide, Volume 1

You show online status. Clients can vanish without disconnecting (dead battery, tunnel). How do you detect offline?
Show answer

Answer

Clients heartbeat every few seconds and are marked offline when the heartbeat TTL expires
Heartbeats with a TTL (for example in Redis) catch silent disappearances within seconds. Users rarely log out. Last login says nothing about now. Default TCP keepalive waits around 2 hours before probing.

Source: System Design Interview: An Insider's Guide, Volume 1

Design WhatsApp or Slack messaging. Requirements, connection model, storage and two deep dives.
Show answer

Answer

  • Requirements: 1:1 and group chat, delivery and read receipts, offline delivery, multi device, ordering per conversation.
  • Connections: WebSocket gateways, registry of user to gateway, pub/sub between gateways.
  • Storage: messages in a wide column store partitioned by conversation id, sorted by sequence.
  • Deep dive 1, delivery: client message id for dedupe on retry, ack flow, per device sync cursor, push via APNs or FCM when offline.
  • Deep dive 2, large groups: write once per conversation, fan out notifications to online members only, rate limits for huge channels.

Source: System Design Interview: An Insider's Guide, Volume 1, Hello Interview: Amazon L6 interview guide, OpenAI system design interview

A feed service: average user has 200 followers, a few accounts have 50 million, reads far outnumber writes. Which fanout?
Show answer

Answer

Hybrid: push to followers' timelines for normal users, pull celebrity posts at read time
Push makes reads cheap for the common case; pulling the few celebrity accounts at read avoids 50 million writes per post, which is Twitter's approach. Pure push melts on celebrity posts. Pure pull makes every read merge hundreds of sources. A global timeline filtered per user does not scale.

Source: The Infrastructure Behind Twitter: Scale, System Design Interview: An Insider's Guide, Volume 1

Precomputed timelines live in Redis. Why store only post IDs (capped at a few hundred per user) instead of full post bodies?
Show answer

Answer

IDs keep memory small and edits or deletes apply once in the post store
Copying bodies into millions of timelines multiplies memory and makes every edit or delete a fanout. IDs are hydrated from a post cache. Redis strings can be up to 512 MB. Consistency does not come from storing bodies. You still need a post cache to hydrate the IDs.

Source: The Infrastructure Behind Twitter: Scale

Design a news feed (Facebook or Twitter home timeline). Requirements, API, fanout choice and deep dives.
Show answer

Answer

  • Requirements: post, follow, read home feed in reverse time or ranked, low read latency, eventual consistency OK.
  • API: POST /posts, GET /feed?cursor=.
  • Fanout: hybrid push for normal users, pull for celebrities; timeline cache of post IDs.
  • Deep dives: celebrity handling, cursor pagination, ranking stage, cache warmup for inactive users, social graph store (TAO style).

Source: System Design Interview: An Insider's Guide, Volume 1, The System Design Primer, TAO: Facebook's Distributed Data Store for the Social Graph, Hello Interview: Meta E5 interview guide

Your iOS app is closed. How does your backend notify the user about a new message?
Show answer

Answer

Send a push through APNs using the device token
Only Apple's push service can wake or alert a closed app; your server sends to APNs with the device token (FCM on Android). iOS suspends background sockets. SMS costs money and is a different channel. A closed app cannot poll.

Source: Apple Developer: Sending notification requests to APNs, System Design Interview: An Insider's Guide, Volume 1

A webhook platform: one merchant's endpoint returns 500 for every request, and retries are delaying delivery to all other merchants. What fixes it?
Show answer

Answer

Per destination queues or rate limits with backoff, and a dead letter queue after N attempts
Isolating by destination stops one bad endpoint from blocking the rest, and backoff plus DLQ bound the work spent on it. A shared retry queue keeps the head of line blocking. Tight retry loops burn workers. Dropping after one failure breaks at least once delivery for transient errors.

Source: OpenAI system design interview, Fairness in multi-tenant systems

Customers register webhook URLs that your servers call. An attacker registers a hostname that resolves to 169.254.169.254. What protects you?
Show answer

Answer

Resolve and check the IP at send time against private and metadata ranges, through an isolated egress proxy
SSRF is blocked by validating the resolved address on every request (DNS can change after registration) and sending from a network that cannot reach internal services. https does not limit the destination. A registration time check is defeated by DNS rebinding. POST requests to internal endpoints can still do damage.

Source: OWASP: Server-Side Request Forgery Prevention Cheat Sheet

Design a webhook delivery platform (Stripe or OpenAI style). Requirements, delivery semantics and failure handling.
Show answer

Answer

  • Requirements: at least once delivery, per endpoint ordering optional, signed payloads, retries for days, visibility for customers.
  • Flow: events written via outbox, queue, delivery workers, per destination scheduling.
  • Retries: exponential backoff with jitter, DLQ, auto disable broken endpoints with notification, manual replay.
  • Isolation: per merchant concurrency and rate limits so one slow endpoint cannot starve others.
  • Security: HMAC signature with timestamp, SSRF protection on egress.
  • Receivers: must dedupe by event id since delivery is at least once.

Source: OpenAI system design interview, System Design Interview: An Insider's Guide, Volume 1

These questions come from the System Design Interview Practice pack in Bertopia.

More system design topics

Practise these on your commute