What a broker decouples

N x M -> N + M

A broker turns a mesh into a star, and each side runs at its own rate, while stored offsets let consumers ask the same question again.

A broker buys two things, and neither one is about the message itself. It replaces direct producer-to-consumer connections with a single connection per participant, so the count grows with N plus M instead of N times M. It also holds messages in a buffer, which lets each consumer read at its own pace and lets the producer keep writing while a consumer restarts. The consequence is that adding a consumer no longer means touching producers.

Each producer opens one connection to the broker, and each consumer opens one connection to the broker. Inside, the broker appends every message to a partitioned log on disk, in arrival order within each partition. A consumer group tracks an offset per partition, the position of its last committed read. When a consumer asks for more, the broker sends records starting at that offset, and the consumer commits the new offset only after it finishes processing. Nothing is deleted on read. Retention removes old data after a configured window, measured in days, and replicas on other machines hold copies of each partition so a failed machine does not lose the log. Producers never learn who is listening, and the broker never needs to know how fast a consumer runs.

The star hides the cost of commit timing. Suppose a consumer writes a row to its database, then crashes before committing its offset. On restart it reads from the last committed offset and processes the same record again, so the database holds two rows for one event. The broker did nothing wrong, and it has no way to see that the work already happened. Consumer lag, measured in offsets, shows how far behind a restarted consumer is, but it says nothing about whether the rows are correct, so a dashboard can look healthy while the data is wrong. Delivery guarantees at the broker are only half the story. The consumer must make its own side safe to repeat.

Before you pick a broker, list every consumer and answer three questions. Does any consumer need history? If yes, choose a log with retention measured in days, and let new consumers start from an earlier offset instead of now. Does any consumer need order for one key? If yes, send every event for that key to the same partition, because order holds only inside a partition. Can a consumer see the same message twice? If yes, store each message's unique key and skip keys already processed. Size the system by consumer count and connections, not message bytes, since the broker's job is to absorb the gap between producer and consumer rates.

orders of magnitude
Connections, direct
N x M

Every producer holds a connection to every consumer of its events, so the count multiplies.

Connections, via broker
N + M

Each participant holds one connection to the broker, so the count adds.

Retention
days

The log keeps messages for a configured window, and a new consumer can read back inside it.

Consumer lag
offsets

The gap between the newest offset and a consumer's committed position.

field note

The first design looked simpler than running anything in the middle. Each service called the services that needed its events directly, over plain connections. For a few services this worked, and nobody saw a reason to add infrastructure. The team wrote the calls by hand and moved on.

The wall arrived as connection count and coupling. With N producers and M consumers, each pair needed its own link, so the mesh grew as N times M. A slow consumer pushed backpressure into its producers, and checkout slowed because a reporting job lagged. A redeploy dropped whatever messages were still in flight.

The fix put a partitioned log between the two sides, which is the model Apache Kafka uses. Producers append to a topic and never learn who reads it. Each consumer keeps its own offset, its position in the log, and reads forward at its own speed. A consumer that falls behind simply reads more slowly, and producers keep writing.

The lesson was that the useful part is a buffer with a position. Once consumers own their offsets, a retry means reading from a saved point, a replay means moving that point back, and adding a consumer means adding a reader without asking producers for anything.