WebSockets & MQTT
Studies in this cluster, in series order. Each one keeps its own URL.
Messaging
Kafka, event-driven architecture, outbox and CQRS, WebSockets, MQTT, and queues you can defend in interviews.
WebSockets & MQTT
6 studies- 1.WebSockets & MQTT — Real-Time Protocols for Senior InterviewsInterviewers ask how you push live updates without burning sockets, batteries, or ops. WebSockets give full-duplex browser streams; MQTT gives topic-based pub/sub for devices. SSE, long-polling, and Kafka-style logs fill different niches — this hub maps the cluster.
- 2.WebSocket Protocol — Handshake, Frames, Ping/Pong & Close CodesRFC 6455 upgrade is HTTP 101 plus Accept = base64(SHA1(key + GUID)). Frames carry opcodes and masking; ping/pong is the application keepalive. Close 1001 drains deploys; 1006 is an abnormal drop with no close frame.
- 3.MQTT Essentials — Topics, QoS 0/1/2, Retained Messages & SessionsMQTT is broker-centric pub/sub: hierarchical topics, hop-scoped QoS 0/1/2, retained last-value, and clean vs persistent sessions. Effective QoS is the min of publish and subscribe. QoS 2 is not Kafka exactly-once.
- 4.WebSocket vs SSE vs Long-Polling vs MQTT — When to Choose WhatChoose a realtime channel from directionality, client environment, proxies, battery, topic routing, and durability. Pick the simplest protocol that fits; bridge to Kafka only when replay is a product requirement.
- 5.Scaling WebSockets — Sticky Sessions, Fan-out & BackpressureA WebSocket is pinned to the process that accepted the TCP connection. Sticky affinity reduces reconnect churn, but multi-node rooms need a fan-out bus. Bounded queues, coalesce, and disconnect-slow-clients keep one laggy socket from OOM-ing the node.
- 6.MQTT Brokers, Auth & Bridging — ACL, Wildcards, Last Will & Bridge PatternsThe broker authenticates, ACLs by topic, stores retained and sessions, and publishes Last Will on unclean disconnect. Namespace tenants; never grant # to untrusted clients. Bridge with prefix rewrite so topics cannot loop. MQTT QoS 2 is still not Kafka exactly-once.