3 Topics
Chapter•125 Minutes

System Design Patterns: Notifications, Feeds, Chat, and Real-Time Updates

Apply core architecture concepts to common product features and understand their distinct bottlenecks.

Design a Notification Platform

A notification platform accepts domain events, decides recipients and channels, applies user preferences, renders templates, and sends through providers such as email, push, or SMS. Separate event ingestion from delivery so provider latency does not block the originating business transaction.

Use queues, provider-specific workers, retries with backoff, rate limits, and dead-letter queues. Deduplicate by a stable notification key when duplicate messages would confuse users. Store delivery state with clear meanings such as queued, attempted, delivered, bounced, or permanently failed; a provider accepting a request does not always prove that a human received it.

Respect user preferences, unsubscribe rules, quiet hours, and tenant limits. Prioritize transactional notifications differently from marketing messages, and ensure provider failures do not cause unbounded retry storms.

Notification pipeline
Key Takeaways
  • Decouple event creation from slow provider delivery.
  • Track delivery state and deduplicate appropriately.
  • Apply consent, preferences, and rate limits before sending.
Knowledge Check

Why might a notification system use a durable queue between domain events and provider workers?

Design a News Feed and Timeline

A feed combines content creation, relationship data, ranking, and low-latency reads. In a fan-out-on-write design, a new post is written into followers' feed timelines. Reads become fast, but a celebrity with millions of followers can create a huge write burst.

In fan-out-on-read, the service gathers posts from followed accounts at request time. Writes are cheaper, but reads can require many merges and may be slow for users following many accounts. Hybrid approaches precompute ordinary users' feeds while fetching very high-fan-out accounts at read time.

Store post metadata separately from media blobs, cache hot timelines carefully, and make ranking a distinct stage. Define pagination with stable cursors and consider deleted posts, blocked users, privacy changes, and eventual consistency. Feed correctness includes authorization and visibility, not just speed.

Key Takeaways
  • Fan-out-on-write optimizes reads but can amplify writes.
  • Fan-out-on-read moves work to the read path.
  • Hybrid designs address skew; visibility rules must remain correct.

Design Chat and Real-Time Communication

A chat system needs identity, conversation membership, message persistence, delivery, ordering, presence, and synchronization across devices. WebSockets provide a long-lived bidirectional connection, but the server must handle reconnects, heartbeats, backpressure, and connection distribution across instances.

Persist a message before acknowledging durable acceptance. Assign a conversation-scoped sequence or stable message ID to support pagination and deduplication. Global order across all conversations is usually unnecessary; per-conversation ordering is more meaningful and easier to scale.

Presence is approximate and ephemeral: a disconnected client may remain marked online until a heartbeat timeout. Separate transient presence from durable messages. For offline delivery, use a durable store or queue and synchronize from the last acknowledged cursor after reconnect. End-to-end encryption changes server-side search, moderation, recovery, and multi-device key-management trade-offs.

Key Takeaways
  • WebSockets require reconnect, heartbeat, and connection-capacity planning.
  • Persist messages before claiming durable acceptance.
  • Use conversation-scoped ordering and cursor-based synchronization.