Designing Real-Time Systems

1. Designing WebSocket Architecture

ElementDetail
Protocolws/wss; HTTP upgrade
ServerNode, Spring WebFlux, ASP.NET, Phoenix Channels
Connection limitsTens of thousands per node
Sticky sessionsLB binds connection to instance
Pub/sub backplaneRedis, NATS for fan-out
HeartbeatPing/pong to detect dead

2. Designing Server-Sent Events

AspectDetail
DirectionServer → client only
TransportHTTP; auto-reconnect by browser
Last-Event-IDResume after reconnect
Use casesNotifications, dashboards, AI streaming
Vs WebSocketSimpler, no bidirectional

3. Designing Real-Time Notification System

   Producer ─▶ Topic ─▶ Notification Service ─▶ Channel Adapters (push/email/SMS/in-app/WS)
                                  │
                                  └─▶ User Preferences + Rate Limiter
      

4. Designing Pub-Sub Messaging

SystemStrength
Redis Pub/SubSimple, fire-and-forget
NATS / JetStreamLightweight, persistent option
KafkaDurable, replay
Google Pub/Sub / SNSManaged, global
MQTTIoT, low bandwidth

5. Designing Real-Time Data Synchronization

PatternDetail
Optimistic + versionDetect conflict on write
CRDTsYjs, Automerge for collaborative
Operational TransformGoogle Docs-style
Delta syncSend diffs only
Snapshot + opsPeriodic full sync to recover

6. Designing Presence and Status Tracking

ElementDetail
StorageRedis hash with TTL
HeartbeatClient pings every N sec
Fan-outPub/sub to subscribers
ScaleShard by user_id; debounce updates

7. Designing Chat Application Architecture

ComponentDetail
Connection layerWebSocket gateway, sticky LB
Message storeCassandra/Scylla/DynamoDB partition by chat_id
Fan-outChannel pub/sub
Delivery receiptssent / delivered / read
E2E encryptionSignal protocol (optional)
OfflinePush notification + DB queue

8. Designing Live Updates and Feeds

ApproachDetail
PushStream new items via WS/SSE
Polling fallbackIf WS unavailable
Cursor-basedsince=last_id
Debounce/throttlePrevent UI thrash

9. Designing Connection Scaling

LeverDetail
Many small nodesSpread connections
BackplaneCross-node fan-out via Redis/NATS
Tune ulimit / fdOS level
Dedicated WS tierIsolate from REST
Edge WebSocketCloudflare/Ably for global

10. Designing Real-Time Analytics

StackDetail
IngestKafka / Kinesis
ComputeFlink / ksqlDB / Materialize
ServingClickHouse / Druid / Pinot / Rockset
Latency targetSeconds end-to-end

11. Designing Long Polling vs WebSocket

AspectLong pollingWebSocket
DirectionPullBidirectional
OverheadHTTP per cycleOne handshake
CompatibilityUniversalModern
LatencyHigherLower
UseFallback / restricted networksDefault for real-time

12. Designing Real-Time Collaboration

ElementDetail
CRDT / OTConflict-free merging
AwarenessCursors, selections of other users
PersistenceSnapshot + op log
OfflineQueue ops, replay on reconnect
ToolsYjs, Automerge, Liveblocks, Convex