Vibe Engines
YouTube
SYSTEMS & BACKEND

Real-time & Messaging

Pushing data the moment it changes — WebSockets, fan-out, streaming and message queues — across chat, feeds, notifications and collaborative editing.

36 pieces · 6 formats Follow this topic (RSS)

Real-time systems push changes to users the moment they happen instead of waiting for the next request: a chat message, a driver’s position on a map, a collaborator’s cursor in a shared document. Messaging is the backbone underneath, the queues and event logs that let one part of a system hand work to another reliably without both being available at the same instant.

Core ideas and trade-offs

  • Pull, push or callback. Polling is simple but wastes requests and adds, on average, half the polling interval of delay. Server-Sent Events hold one connection open for server-to-client updates; WebSockets add full two-way messaging; webhooks reverse the roles, so the provider calls your endpoint when something happens.
  • Persistent connections are state. Each WebSocket lives on one server, so you need a registry of who is connected where, a pub/sub layer to route messages between servers, and a reconnection strategy for mobile clients that drop constantly.
  • Fan-out has two shapes. Fan-out on write copies each new post into every follower’s precomputed feed, which makes reads fast and gets expensive for accounts with millions of followers. Fan-out on read assembles the feed when it is opened. Many large feeds use a hybrid.
  • A queue forgets; a log remembers. RabbitMQ-style brokers route each message and delete it once it is acknowledged. Kafka-style logs retain messages, so each consumer tracks its own position and can replay history.
  • Delivery is at least once. Retries create duplicates, so consumers must be idempotent, and ordering usually holds only within a partition or key, not across a whole topic.

How the formats fit together

The handbooks cover the transport choices, WebSockets and the poll-versus-push math, Kafka as a distributed log, and the comparisons that trip teams up: Kafka versus RabbitMQ, Kafka versus Kinesis and streaming versus batch. The system designs are the heart of this hub, because chat apps, notification systems, news feeds, collaborative editors, live streaming and ride matching each stress a different part of the problem. The algorithm games and challenges cover the streaming structures that summarize endless data in small memory, such as reservoir sampling, Count-Min sketches and HyperLogLog, and the partition calculator sizes a Kafka topic from your throughput.

Common mistakes

  • Choosing WebSockets when one-way updates over Server-Sent Events, or plain polling, would do.
  • Assuming messages arrive exactly once and in a single global order.
  • Using Kafka as a task queue that needs per-message routing and delays, or RabbitMQ as a replayable event store.
  • Forgetting the offline user: messages need durable storage and delivery on reconnect, not just a live socket.

Start here, in this order

  1. REST vs Webhooks vs SSE — Pick the right transport first, by asking who exposes the endpoint and whether the connection stays open.
  2. The WebSockets & Real-Time Handbook — Work through the poll-versus-push latency math, when Server-Sent Events are enough and the scaling traps of persistent connections.
  3. Design WhatsApp — See persistent connections in a full product, with a session registry, offline inboxes, delivery receipts and group fan-out.
  4. The Kafka Handbook — Learn the distributed log underneath most event pipelines: partitions, offsets, consumer groups and delivery semantics.
  5. Kafka vs RabbitMQ — Get the remember-versus-forget difference that decides between a log and a broker.
  6. Design a News Feed — Compare fan-out on write with fan-out on read, and see the hybrid that tames accounts with huge followings.

Questions

When should I use WebSockets instead of polling or Server-Sent Events?

Use WebSockets when both sides send frequent messages over the same connection, as in chat, multiplayer games or collaborative editing. If only the server needs to push updates, such as notifications, live scores or streamed model output, Server-Sent Events are simpler: they run over ordinary HTTP and the browser reconnects automatically. Polling is still reasonable when updates are rare or a delay of several seconds is acceptable, because it needs no long-lived connections. Persistent connections add operational work, such as connection registries and load balancer settings, so choose the simplest option that meets the latency you need.

What is the difference between Kafka and RabbitMQ?

Kafka is a distributed, append-only log. Messages are retained for a configured time whether or not anyone has read them, each consumer group tracks its own offset, and consumers can replay history, which suits event streaming, analytics pipelines and feeding several independent systems from one stream. RabbitMQ is a message broker that routes each message to queues using flexible rules and removes it once a consumer acknowledges it, which suits task distribution and per-message workflows. Both can be made durable; they differ in whether a message is remembered or forgotten after delivery.

How do chat apps deliver messages to users who are offline?

The server stores every message durably before acknowledging it to the sender, then tries to deliver it. If the recipient has an open connection, the message is pushed immediately. If not, it waits in a per-user inbox, and the app may get a push notification through the phone platform’s notification service. When the recipient reconnects, the client asks for everything after the last message it saw and the server sends the backlog. Delivery and read receipts are separate acknowledgments flowing back to the sender, which is how apps show sent, delivered and read states.

What does fan-out mean in a news feed?

Fan-out is the work of getting one post in front of everyone who follows its author. With fan-out on write, the system pushes the post into each follower’s precomputed feed when it is created, so reading a feed is fast, but that becomes expensive when an account has millions of followers. With fan-out on read, the feed is assembled when the user opens it by pulling recent posts from everyone they follow, which is cheaper to write and slower to read. Large systems often combine the two, pushing posts from typical accounts and pulling from very large ones.

Handbooks 6

Handbook

The Kafka Handbook

Apache Kafka as a distributed append-only log, not a queue — topics, partitions and offsets, producers, consumers and consumer groups, per-key ordering, replication and ISR, delivery semantics (at-least-once and exactly-once), retention vs log compaction, and when Kafka beats a message queue.

Engineering
Handbook

Kafka vs RabbitMQ

They both "move messages", which is exactly why teams pick the wrong one. Kafka is a durable, replayable log where consumers track their own offset; RabbitMQ is a smart broker that routes each message and deletes it on ack. The remember-vs-forget core difference, throughput and ordering trade-offs, and how to choose.

EngineeringComparison
Handbook

The WebSockets & Real-Time Handbook

Why "live" is hard on a protocol that can't push. Polling makes you wait on average half the interval to learn of an event (a 10s poll = ~5s staleness) and wastes a request every time nothing changed — and shrinking the interval only multiplies the waste. A WebSocket keeps one persistent full-duplex line open so the server pushes the instant something happens: latency ≈ one network hop, zero empty requests. The poll-vs-push latency math, when to use SSE instead, and the stateful-scaling pitfalls. With worked math and runnable code.

Engineering
Handbook

Kafka vs Kinesis

Same partitioned-log model underneath, different operational surface: Kafka is self-run and portable with a huge ecosystem; Kinesis is fully AWS-managed with a hard per-shard throughput ceiling. Retention, cost model, and the lock-in trade-off.

EngineeringComparison
Handbook

REST vs Webhooks vs SSE

Three ways client and server move data, split by who exposes an endpoint and whether the connection stays open: REST pulls, webhooks flip who runs the server, SSE keeps one connection open for a live push. How real systems run all three at once.

EngineeringComparison
Handbook

Streaming vs Batch

Batch processes on a schedule; streaming reacts per-event. The real engineering cost of streaming isn’t speed, it’s correctness under disorder — event time vs processing time, watermarks, exactly-once semantics. The Lambda and Kappa architectures that combine both.

EngineeringComparison

System Designs 20

System Design

Design Uber

Build a planet-scale ride-hailing system. Learn how to handle real-time location tracking, matching algorithms, scalability, and payments.

Distributed SystemsReal-timeScalability
System Design

Design WhatsApp

Build a real-time messaging system. See how persistent WebSockets, a session registry, offline inbox queues, the ✓✓ delivery receipts, group fan-out, media on a CDN, and end-to-end encryption fit together.

Real-timeWebSocketsMessaging
System Design

Design Twitter

Build Twitter's news feed. Learn the social graph, why fan-out on write beats read-time merging, how a precomputed timeline cache makes feed reads O(1), how ranking surfaces the best tweets, and how a hybrid model solves the celebrity problem.

Fan-outCachingScalability
System Design

Design a Notification System

Build a multi-channel notification system. See how one API, a message queue and a worker fleet decouple slow third-party delivery, how preferences and quiet hours gate every send, how templates fan out to push, SMS and email, and how delivery tracking, retries, dedup and rate limits keep it reliable.

Fan-outMessagingReliability
System Design

Design a Message Queue

Build a distributed message queue like Kafka. See how an append-only commit log, partitions keyed for order, consumer groups with server-side offsets, leader/follower replication, controller-driven leader election, retention and compaction, and exactly-once guarantees fit together.

Distributed SystemsStreamingReplication
System Design

Design a News Feed

Build a social news feed. See how the social graph, pull vs push fan-out, a precomputed feed cache, relevance ranking, the hybrid model that tames the celebrity problem, blending multiple content sources, and cursor pagination fit together.

Fan-outCachingRanking
System Design

Design Google Docs

Build a real-time collaborative editor. See how edits become tiny operations, how OT and CRDTs resolve concurrent edits so every copy converges, how ops broadcast over WebSockets, how an op log plus snapshots give history and recovery, and how presence, offline sync and per-document sharding fit together.

Real-timeConsistencyCollaboration
System Design

Design Netflix

Build a planet-scale video streaming service. See how the play path splits authorization from byte delivery, how origin storage and CDN edges serve immutable segments, how an adaptive-bitrate ladder adapts to any connection, how a parallel transcoding pipeline builds it, and how Open Connect, recommendations and QoE events fit together.

StreamingCDNScalability
System Design

Design Instagram

Build a photo-sharing app. See how splitting media from metadata, a CDN for immutable images, async image processing, a precomputed feed cache, asynchronous like/view counters, TTL-based ephemeral stories, and sharding fit together to serve billions of photos.

StorageCDNFan-out
System Design

Design an Ad Click Aggregator

Build a real-time ad click aggregator. See how a thin ingest API and event stream absorb millions of clicks a second, how a stream processor aggregates into time windows, how dedup keys give exactly-once counts, how a raw event lake and batch recompute reconcile the numbers, and how fraud filtering and watermarks handle the sharp edges.

StreamingAggregationScalability
System Design

Design Slack

Build a team chat app. See how channel messaging and per-channel history, real-time delivery over WebSockets with a session registry, cross-server fan-out via pub/sub, ephemeral presence and typing, message search, unread counts and notifications, and channel sharding fit together.

Real-timeWebSocketsFan-out
System Design

Design a Leaderboard

Build a real-time leaderboard for millions of players. See why SQL ORDER BY + COUNT rank melts at scale, how a sorted set (Redis ZSET) gives O(log N) update/rank and O(log N + K) top-K, how relative "around me" boards work, why sharding a global ranking is uniquely hard, how time-windowed boards reset cleanly, and how a durable store backs the rebuildable in-memory index.

CachingScalabilityReal-time
System Design

Design a Fraud Detection System

Build a real-time fraud detection system like Stripe Radar. See why static rules fail against an adaptive adversary, how real-time features (velocity, device, geo) from a feature store carry the signal, how an ML model blends with rules under an ~80ms budget, how streaming aggregations keep features fresh, how the chargeback/label feedback loop retrains the model, and how allow/deny/step-up decisioning and graph features handle nuance and fraud rings.

Machine LearningReal-timeScalability
System Design

Design a Video Conferencing System

Build a video conferencing system like Zoom or Google Meet. See why real-time media needs UDP/WebRTC not TCP, why a peer-to-peer mesh explodes at N², how an SFU lets each peer upload once and forwards streams, how simulcast adapts quality per receiver, how signaling with SDP and ICE/STUN/TURN connects peers across NATs, and how geo-distributed cascaded SFUs scale to huge global calls.

Real-timeWebRTCScalability
System Design

Design a Live Streaming System

Build a live video streaming system like Twitch or YouTube Live. See why it optimizes for cheap CDN fan-out instead of ultra-low latency, how ingest accepts one broadcaster push, how transcoding builds an adaptive bitrate ladder, how HLS/DASH segmenting turns live video into cacheable HTTP files, how a CDN fans them to millions, the latency-vs-scale dial, and how live chat and DVR/VOD fit in.

StreamingCachingScalability
System Design

Design a Food Delivery System

Build a food delivery system like DoorDash or Uber Eats. See why it's a three-sided marketplace plus a real-time logistics engine, how the order lifecycle is a durable state machine, how the dispatch engine optimizes courier assignment (who and when, not nearest-now), how location tracking and geo-indexing work, how ETA is an ML sum of prep + travel + wait, and how geo-sharding and surge balance supply and demand.

Real-timeGeospatialScalability
System Design

Design a Collaborative Editor

Build a real-time collaborative document editor like Google Docs, Notion or Figma. See why a whole-document lock kills concurrency, how naive position-based edits corrupt a document, how Operational Transformation's central sequencer works and where it bottlenecks, how CRDTs remove that bottleneck with causal, order-independent merges, why presence/cursors live outside the document's durable history, and how offline-first editing and tombstone garbage collection round out the design.

Real-timeConsistencyCollaboration
System Design

Design a Calendar System

Build a shared calendar like Google Calendar or Outlook. See why storing every recurring occurrence explodes storage, how RRULE-based recurrence is expanded at read time with exceptions layered on top, how free/busy conflict detection stays fast via interval overlap, the timezone/DST trap that can silently shift a recurring meeting by an hour, how invite/RSVP fan-out avoids blocking the organizer, how reminders scale via a time-bucketed trigger index, and how devices sync incrementally.

ConsistencyReal-timeScalability
System Design

Design a Dating App

Build a swipe-based dating app like Tinder or Hinge. See why a live full-table nearby scan doesn't scale, how a geospatial index plus a swiped-exclusion set fixes candidate generation, the mutual-match race condition and how a database uniqueness constraint guarantees exactly one match, how ranked feeds are precomputed rather than live, why blocking is deliberately the strictest-consistency path in the whole system, and how bot/fake-profile detection runs quietly, asynchronously, off the hot path.

Real-timeShardingScalability
System Design

Design a Ride-Matching Engine

Build the matching and dispatch engine at the heart of a ride-hailing platform — the specific subsystem deciding which driver gets which rider, not the trip lifecycle or payments. See why straight-line distance is a bad proxy for real ETA, why greedy one-at-a-time matching is globally suboptimal, how batch matching solves an assignment-optimization problem across a short window, surge pricing as supply/demand balancing, ingesting driver locations at write-heavy scale, and fairness for idle drivers.

Real-timeConsistencyScalability

AI System Designs 2

Algorithm Games 5

Algorithm

The Last One Standing: Boyer-Moore Majority Vote

Don't memorize the majority vote — watch the votes cancel out. Find the value that appears more than half the time in one pass with just two variables: keep a candidate, add for a match, cancel for a mismatch, and whoever survives is the majority. O(n) time, O(1) space, works on streams — plus full theory, the code and a quiz.

ArraysStreaming
Algorithm

The Fair Draw: Reservoir Sampling

Don't memorize reservoir sampling — watch it stay fair. Pick one element uniformly at random from a stream of unknown length, holding just one slot: keep the i-th arrival with probability 1/i, and every element ends up equally likely. The one-pass, O(1)-space trick behind sampling logs and huge files — plus full theory, the code and a quiz.

ArraysStreaming
Algorithm

Bloom Filter: Maybe Yes, Never No

Don't memorize the Bloom filter — play it. Add items by lighting k bits with k hashes, then query: all bits set means 'probably present', any bit unset means 'definitely absent'. Hunt down a live false positive and see why a Bloom filter can give a false yes but never a false no — the tiny, key-less probabilistic set behind caches, databases, and crawlers. Made playable, with theory and a quiz.

HashingProbabilisticStreaming
Algorithm

Count–Min Sketch: Counting in Tiny Space

Don't memorize the Count–Min Sketch — play it. Count how often items appear in a stream using a fixed grid of counters and d hashes: bump one cell per row on each event, and estimate a frequency by taking the minimum across rows. Watch a collision inflate an estimate, and see why it can over-count but never under-count — the structure behind heavy-hitters and streaming analytics. Made playable, with theory and a quiz.

ProbabilisticStreamingHashing
Algorithm

MinHash: Similarity in a Signature

Don't memorize MinHash — play it. Estimate the Jaccard similarity of two sets by comparing k tiny hash-based signatures: for each hash, the minimum value over a set's elements matches between two sets with probability equal to their Jaccard similarity. Add hash functions and watch the estimate converge on the true overlap. The trick behind near-duplicate detection at web scale — made playable, with theory and a quiz.

ProbabilisticHashingStreaming

Coding Challenges 2

Interactive Tools 1

About real-time & messaging

Some systems can't wait for the next request to show you what changed — a chat, a live feed, a collaborative document need updates pushed the moment they happen. That means persistent connections (WebSockets), fan-out to many subscribers, and streaming instead of polling.

Underneath sits message queues and event streams: the decoupling layer that lets a fast producer hand work to slower consumers without either blocking the other, and that turns "do it now, synchronously" into "publish an event, process it reliably later". This topic covers both the user-facing real-time surfaces and the messaging backbone that makes them dependable.

More in Systems & Backend

← Browse all topics