Interview conceptSystem Design

Real-Time Messaging And News Feed Systems

Asked of: Software Engineer

Last updated

Left-to-right architecture for messaging and news feeds, showing idempotent APIs, conversation ordering, durable event streaming, fanout workers, caches, and cursor-based delivery.

What's being tested

These designs test whether you can decompose a high-scale social product into APIs, storage, asynchronous pipelines, caches, and delivery paths while making consistency and failure semantics explicit. The recurring challenge is moving user-generated data quickly and reliably to many readers or recipients without making every request expensive. Meta cares because small mistakes in fanout, ordering, privacy enforcement, or retries become severe at billions of interactions. Interviewers are probing your ability to quantify bottlenecks, choose appropriate tradeoffs, and explain operational behavior under failure.

Core knowledge

  • Requirements clarification should establish traffic, payload sizes, latency targets, durability, retention, read/write ratios, group sizes, privacy rules, and acceptable loss. Separate user-visible guarantees—such as “a sent message is durable”—from implementation choices like Kafka or a particular database.

  • API contracts should use stable identifiers, explicit status codes, pagination cursors, and retry-safe semantics. A send endpoint commonly accepts a client-generated idempotency key; repeating the same key returns the original result rather than creating duplicate messages.

  • Message ordering is usually guaranteed per conversation, not globally. Assign a monotonically increasing conversation sequence from a single logical sequencer or partition owner; clients reconcile gaps using conversation_id plus seq_no, while globally ordered timestamps remain unsuitable as the sole ordering guarantee.

  • Delivery semantics should be stated precisely: at-most-once risks loss, at-least-once requires deduplication, and exactly-once end-to-end is generally an illusion. Durable append followed by asynchronous delivery usually gives at-least-once delivery, with consumer-side message IDs and inbox state making retries harmless.

  • Polling without persistent connections can use short polling, long polling, or push notifications. Long polling reduces empty responses while retaining request/response APIs; return messages after a timeout or immediately when available, then have the client reconnect with a cursor and exponential backoff.

  • Cursor-based synchronization is safer than page numbers under concurrent writes. Return an opaque cursor such as (conversation_seq, message_id) and a has_more indicator; handle expired cursors, deleted records, duplicate pages, and gaps by allowing a full resynchronization.

  • Fanout-on-write copies a post reference into followers’ inboxes, giving cheap reads but expensive writes for celebrity accounts. Fanout-on-read stores the post once and merges followees’ recent posts at read time; hybrid systems commonly fan out ordinary users and merge high-degree accounts dynamically.

  • Feed storage should separate durable canonical posts from materialized feed entries. A feed entry may contain post_id, author, creation sequence, visibility version, and expiration metadata; the reader rechecks deletion, blocking, and privacy so stale materializations cannot leak content.

  • Partitioning and hot keys require choosing a stable access boundary: conversation ID for chat ordering, author or post ID for writes, and user ID for inbox reads. A single celebrity or huge group can overload one shard, so use partition splitting, append-only logs, batching, or special fanout paths.

  • Caching and CDN design should cache immutable media by content hash and serve it through a CDN, while metadata and personalized feeds use shorter-lived caches. Invalidate or version objects rather than relying only on deletion broadcasts; cache authorization-sensitive responses carefully to prevent cross-user leakage.

  • Asynchronous propagation decouples the write path from feed fanout, search indexing, notifications, and media processing. A durable queue such as Kafka supports replay and backpressure, but consumers need idempotent writes, dead-letter handling, lag monitoring, and a clear policy for temporarily stale results.

  • Capacity planning starts with simple estimates: storage per day is approximately writes_per_second × average_bytes × 86,400, and fanout work is approximately posts_per_second × average_follower_count. Track p50, p95, and p99 latency separately for writes, reads, propagation lag, and media delivery.

Worked example

For “Design a real-time messenger”, I would first clarify whether 100M MAU implies a particular concurrent-user level, the expected group-size distribution, message retention, multi-device behavior, and whether the 150 ms target covers server acknowledgment or recipient rendering. I would state assumptions, then organize the answer around API contracts, durable message storage, ordered delivery, and connection/session management. The send path would validate membership, assign a conversation-local sequence, durably append the message, and publish an event for recipient delivery. Recipient devices would maintain per-conversation cursors and deduplicate by message ID, allowing retries without duplicate display. I would distinguish online delivery from offline synchronization, with unread state and missed-message recovery handled by cursor-based reads. A key tradeoff is whether to use a centralized sequencer per conversation for simple ordering or decentralized writes for availability and lower coordination cost. I would explicitly discuss group fanout, hot conversations, backpressure, and observability for send-to-receive p99. If I had more time, I would cover multi-region failover, encryption boundaries, abuse controls, and device receipt semantics.

A second angle

For “Design an Instagram-style news feed”, the central problem shifts from strict per-conversation ordering and low-latency delivery to scalable materialization and freshness. I would compare fanout-on-write, fanout-on-read, and a hybrid strategy based on follower degree and read/write amplification. Feed reads need opaque cursors, stable pagination, privacy rechecks, and behavior when posts are deleted after materialization. The important latency tradeoff is often precomputing more work at publish time versus doing more merging and filtering at read time. I would also isolate media delivery through object storage and a CDN so large photos do not consume feed-service capacity.

Common pitfalls

Pitfall: A common analytical mistake is promising “exactly-once delivery” as if it were a simple database setting. End-to-end retries, crashes between persistence and acknowledgment, and device reconnects make that guarantee unrealistic; say at-least-once transport plus idempotent deduplication instead.

Pitfall: A communication mistake is jumping directly into Kafka, Redis, and database schemas without stating traffic, latency, or consistency assumptions. The interviewer needs a requirements-to-design chain, so announce the workload first and explain why each component follows from it.

A depth mistake is describing fanout but ignoring privacy, deletion, ordering gaps, or retries. “Write the post to every follower’s feed” is incomplete; explain stale-entry handling, celebrity hot spots, asynchronous lag, and how readers recover when a materialized entry is missing or invalid.

Connections

The interviewer may pivot to consistent hashing, leader election, replication and multi-region consistency, or backpressure and queue semantics. They may also ask about API pagination, cache invalidation, observability, or designing a notification service that shares the same event stream.

Further reading

Practice questions

Related concepts