Inside a pub-sub system
hard 35 minHow to build a publish-subscribe service: a control plane that knows topics and subscriptions, brokers that own replicated partitions, delivery by pull and push, leases and acknowledgements per subscription, retries, dead letters and retention, with the arithmetic that sizes it.
Where it shows up
The same pattern appears across everyday software.
Kafka
Topics are partitioned logs with replicas. Consumers pull and store an offset. A record is committed when all in-sync replicas have it.
Google Cloud Pub/Sub
Separates a data plane of forwarders from a control plane of routers. Subscriptions acknowledge single messages, with a deadline of 10 to 600 seconds.
Amazon SNS
A topic pushes to its subscribers and applies a filter policy for each subscription.
MQTT brokers
Keep an open connection to each device and push to it, with a quality of service level for each message.
Company event bus
One log, one topic per business event, and a subscription per team, with schemas checked when a message is published.
Change feeds
A database's changes are published to a topic by key, so caches and search indexes can follow in order.