A lightweight, real-time distributed pub/sub message broker built purely on QUIC using Python 3.13 and aioquic.
This broker eschews TCP for QUIC to achieve secure, low-latency messaging. Every peer connection is automatically authenticated via mutually-exchanged Ed25519 certificates, ensuring zero-trust security without passwords.
This project consists of three main layers:
- Transport Layer (
transport/) - A customQuicNodethat wrapsaioquic. It handles UDP sockets, QUIC connection lifecycle, 0-RTT session resumption tickets, and fully automated TLS verification using Ed25519 identity keys encoded as certificate SANs. - Broker Layer (
broker/) - The server side that accepts connections and implements the pub/sub protocol. AProtocolRouterdecodes the first 1-byte prefix of any incoming QUIC stream to route it (e.g.0x01for Publish,0x02for Subscribe) to theTopicRegistry, which tracks active subscribers and handles message fan-out over persistent push streams. - Client (
run_client.py) - A CLI client implementing the wire protocol for publishing strings or subscribing to live updating topics.
- Python 3.13+
- Installed virtual environment
Activate the environment and install the development dependencies:
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"Starting the broker automatically generates the Ed25519 identity keys (stored in keys/broker) and binds to UDP:
python run_broker.py -vBy default it listens on 0.0.0.0:4433.
In a separate terminal, subscribe to a topic. The client acts as a long-lived subscriber, receiving QUIC stream pushes without closing the connection.
source .venv/bin/activate
python run_client.py sub system-alertsIn a third terminal, publish a message. The publisher sends the message using a request-response flow, receives an ACK from the broker, and disconnects.
source .venv/bin/activate
python run_client.py pub system-alerts "Deploy completed successfully"The system uses a custom wire format, routing entirely on the first byte of a stream.
| Action | Prefix Byte | Wire Format (Client → Broker) | Wire Format (Broker → Client) |
|---|---|---|---|
| Publish | 0x01 |
[0x01][4B topic_len][topic][4B msg_len][msg] + FIN |
[0x00] + FIN (ACK) |
| Subscribe | 0x02 |
[0x02][4B topic_len][topic] + FIN |
<Persistent Stream> |
| Push Data | (Broker to Subscriber on active sub stream) | [4B msg_len][msg] (Repeated as needed) |
|
| Unsubscribe | 0x03 |
[0x03][4B topic_len][topic] + FIN |
[0x00] + FIN |
MIT

