WebSockets ยท AsyncAPI 3 ยท Quarkus WebSockets Next ยท Python ยท Kafka ยท Redis

API Patterns and Practices: WebSockets

Designing WebSocket APIs well, with runnable examples in Quarkus WebSockets Next and Python FastAPI/websockets against one AsyncAPI 3 contract, fanned out through a live handling-event feed.

๐Ÿ“One AsyncAPI 3 contract as the single source of truth for every message
๐Ÿ”ŒEvery example in both Quarkus WebSockets Next and Python
๐Ÿ“กThe same handling event fanned out over both Kafka and Redis
๐Ÿ“ŠTraced end to end through the Grafana LGTM stack

What this site is

A chapter-based, hands-on path to designing WebSocket APIs well, built around a single AsyncAPI 3 contract for a shipping and cargo domain. The socket here pushes a live handling-event feed (the stream of container moves, customs holds, and delivery confirmations a shipment generates as it moves) to any client watching a booking, instead of making that client poll the sibling REST booking service for a status that hasn't changed. Every hands-on chapter ships the same example in both Quarkus WebSockets Next and Python (FastAPI/Starlette plus the native websockets library), generated against that one contract. You work through message design and versioning, backpressure and flow control, heartbeats and reconnect (both stateless and Kafka-backed), security, fan-out contrasted on Kafka and on Redis, binary Protobuf framing, testing and debugging a protocol you can't just `curl`, and the anti-patterns that show up once a socket is in production. It assumes you can read Java and Python; it is not a tutorial in either language. The code tabs are built to admit Go and C++ later. All container images are UBI-based, and the stack runs on Docker Compose, minikube, and OpenShift Local.

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.

2 chapters Explore โ†’
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.

4 chapters Explore โ†’
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.

3 chapters Explore โ†’
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.

4 chapters Explore โ†’
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.

7 chapters Explore โ†’
Part 5

Performance & Optimization

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

2 chapters Explore โ†’
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.

4 chapters Explore โ†’
Part 7

Runtime Progression

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

3 chapters Explore โ†’
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.

2 chapters Explore โ†’