Chapters

The whole book, in order.

Every part and chapter, linked. Read it top to bottom the first time through; each chapter also stands on its own once the lab exists. New here? Start with the Outline.

Part 0 Prerequisites

Get the toolchain and the Docker Compose lab running locally: Quarkus WebSockets Next, Python, LGTM observability, and the shipping/cargo domain this site's sockets share with the REST booking service.

  1. 0 Setup and the Lab Toolchain pins, the Docker Compose lab with opt-in LGTM tracing, and the shipping and cargo domain the sockets share with the REST booking service.

Part 1 Foundations

Why push beats polling, how to choose among WebSockets, SSE, long-polling, and webhooks, how the protocol itself works, and the shared domain every later chapter builds on.

  1. 1 The Real-Time Problem Why request/response falls short for a client watching something change, and what polling costs in requests, capacity and staleness.
  2. 2 Choosing the Right Tool WebSockets, Server-Sent Events, long-polling, webhooks and gRPC streaming compared on seven dimensions, with an ordered decision rule.
  3. 3 How WebSockets Work The HTTP upgrade handshake, frame layout, masking, close codes, subprotocols and extensions under RFC 6455.
  4. 4 The Shared Domain The shipping domain for a live handling-event feed: which nouns travel on the wire, the event vocabulary and the seam with the REST booking service.

Part 2 Contract-first for Sockets

Give a socket a contract with AsyncAPI 3, shape its messages, and version them without breaking a connected client.

  1. 5 AsyncAPI: Giving a Socket a Contract AsyncAPI 3 as the single source of truth for a WebSocket channel's messages, validated once and followed by both stacks.
  2. 6 Message Design One flat handling-event message, a discriminator enum and four field shapes that both stacks deserialize identically.
  3. 7 Versioning and Evolution Classify contract changes as safe or breaking, pick a versioning lever, and retire an old version without cutting off a connected client.

Part 3 Building It

Build the same socket in Quarkus WebSockets Next and in Python's native websockets, build clients that reconnect and respect backpressure, and verify both stacks against one contract.

  1. 8 Quarkus WebSockets Next Implementing the handling-event feed on Quarkus WebSockets Next with one annotated class, a Multi, and Jackson.
  2. 9 Python Native WebSockets Implementing the same feed in Python with the native websockets library beside a FastAPI app, with the message model generated from the contract.
  3. 10 Clients: Reconnect and Backpressure Writing a client that reconnects with jittered exponential backoff and buffers frames behind an explicit backpressure policy.
  4. 11 Polyglot: One Contract, Two Stacks Holding the Quarkus and Python implementations to the same AsyncAPI contract with generation, conformance tests and a CI drift gate.

Part 4 Production Concerns

Backpressure and flow control, error handling, liveness and heartbeats, stateless and Kafka-backed reconnect, security, and fan-out at scale: the concerns that show up once a socket is live.

  1. 12 Backpressure and Flow Control A bounded outbound path per connection, two signals that trip it, and a CLOSE or DROP policy for a server pushing to slow clients.
  2. 13 Error Handling Close codes, an in-band error envelope, and per-code retry rules for a connection that has no status line.
  3. 14 Liveness and Heartbeats Detecting a dead connection before the application does, with ping/pong and a pong-tracked liveness sweep.
  4. 15 Reconnect: Stateless What a client loses when it reconnects to a server that keeps no event history, and when that loss is acceptable.
  5. 16 Reconnect: Kafka-Backed Resuming a reconnecting client from a durable Kafka topic, and absorbing the duplicate delivery that replay can cause.
  6. 17 Security Authenticating a long-lived connection at the upgrade with a bearer JWT, and the attack surface specific to WebSockets.
  7. 18 Scale-Out and Fan-Out Fanning one event out to every connected client across several server instances, with a Kafka or a Redis backplane.

Part 5 Performance & Optimization

Binary Protobuf framing over WebSockets, and the throughput work that follows once a socket carries real load.

  1. 19 Binary Protobuf over WebSockets A binary Protobuf encoding of the same message, negotiated by subprotocol, about 40 percent smaller than the JSON text frame.
  2. 20 Optimizing Throughput Four throughput levers on a socket server: encoding, batching, permessage-deflate and size limits, and how to measure them.

Part 6 Testing, Debugging & Observability

Test a protocol you can't curl, debug a connection that drops without a client-side error, trace a message end to end, and recognize the anti-patterns that make all of this harder.

  1. 21 Testing WebSockets Five test layers for a protocol you can't curl: conformance, live integration, close-code probes, Newman and k6.
  2. 22 Debugging WebSockets Which tool taps which layer of a WebSocket connection, how to read close codes, and a symptom-to-tool path.
  3. 23 Observability Tracing a message end to end through the Grafana LGTM stack.
  4. 24 Anti-Patterns The recurring mistakes that make a WebSocket API harder to run than it needs to be.

Part 7 Runtime Progression

Run the stack on Docker Compose, then on Kubernetes via minikube, then as a separate OpenShift Local (CRC) appendix.

  1. 25 Docker Compose Running the full stack locally with Docker Compose.
  2. 26 Kubernetes (minikube) Running the four-instance WebSocket backplane on minikube behind ingress-nginx, with a Strimzi-managed Kafka and no registry.
  3. 99 Appendix A: OpenShift Local (CRC) Running the WebSocket services on OpenShift Local (CRC): operator install, in-cluster builds, restricted-v2, and edge-TLS Routes.

Part 8 The Bigger Picture

Know when a socket is the wrong tool, and bring every pattern in this site together in one final project.

  1. 27 When You Don't Need a Socket Recognizing when a WebSocket is the wrong tool, and what to reach for instead.
  2. 28 Final Project Assemble every concern built in isolation into one deployed system, and verify it with the scripts that already prove each part.