Fourteen minutes late, nine seconds to say so
At 07:52 a controller at a regional rail operator marks the 07:40 from Ashvale as running fourteen minutes late. The control-room system then makes four calls, one after another: the passenger app's push service, the departure screens at the 38 stations on the line, crew rostering, and the Delay Repay team that compensates delayed passengers. That morning the push service took nine seconds to answer, so the screens, next in line, went on showing the train as on time for nine more seconds.
Two other things had been bothering the control-room team. When Delay Repay's service was down for maintenance, its failed call appeared as an error on the controller's screen, in the middle of handling a real disruption. And the journey-planner team wanted the delays for an open-data feed, which meant a change to the control-room system: a system released once a month, by people who had never heard of the feed.
Say what happened, to no one in particular
Publish / Subscribe changes who decides who hears. The control-room system stops calling anyone. It publishes a message that states a fact, TrainDelayed with the train, the station, the minutes and a cause code, to a topic, here train-running. Each team that cares subscribes to the topic, and something in the middle, usually a broker, delivers a copy of every message to every subscription. The publisher never names a subscriber and no subscriber names the publisher; each side knows only the topic and the shape of the message.
The open-data feed becomes one more subscription. Nobody touches the control-room system to add it, and nobody would touch it to remove the feed either. That is what the pattern buys: the set of subscribers can be unknown to the publisher and can change every week.
The control-room system publishes TrainDelayed once, to the topic. Each subscription receives its own copy; adding the open-data feed changed nothing on the left.
When the broker delivers to each subscription independently, so that no subscriber's backlog holds up another's, a slow push service delays only the app's copy, and a Delay Repay outage no longer reaches the controller, whose publish only needed the broker to accept the message; the ends are decoupled from each other, not from the broker. Whether Delay Repay, back from maintenance, gets the delays it missed depends on what the broker keeps, and that infrastructure side, retention and replay included, belongs to Pub/sub: topics, subscriptions & replay.
What the controller can no longer find out
Ten minutes later the duty manager asks: were the passengers on the 07:40 told? Before, the control-room log at least showed the push service accepting the alert. Now the control-room system knows one thing, that the broker accepted TrainDelayed. Announcing instead of calling gives up three things, on purpose:
- Who acted. The publisher does not know who received the message, or whether anyone did. A topic with no subscriptions accepts it just the same, and depending on the broker it is kept for a while or simply dropped.
- A reply. A subscriber's answer has nowhere to go, because nothing in a published fact says where an answer is expected. When the control room needs an answer, such as a driver for a replacement train, it is asking a known recipient to do something: a command, not a fact. Command, Document & Event Messages draws that line, and Return Address shows how a reply finds its way back over messaging.
- Waiting. The publisher cannot hold its next step until the subscribers have finished, since it does not know how many there are. If a cancellation may only be announced once rostering has moved the driver, that order has to live in something that knows both steps, not in a publish.
The side that knows the outcome announces it: the passenger app can publish a fact of its own, DelayAlertSent for the 07:40, and whoever needs to know subscribes, without putting a dependency back into the control-room system.
Thirty-eight screens, each waiting for one station
Subscribed to train-running as it stood, the screen at Millbrook received every delay on the network: on a bad morning several hundred messages a minute, of which the few about trains calling at Millbrook mattered. Each screen downloaded, parsed and threw away the rest. The screens are small machines on the platforms, and the morning a signalling failure flooded the topic, they fell minutes behind, busy with trains they would never show.
Fanning every event out to every subscriber unfiltered makes each one pay for work it does not need. The fix is to subscribe to less. Either the topic is split along a line subscribers care about, one topic per route for instance, or the subscription carries a filter: the publisher adds the calling stations to each message as an attribute, and Millbrook's screen subscribes only to messages that list Millbrook. Many brokers evaluate such filters themselves (Amazon SNS subscription filter policies are one example), so a message that does not match is never delivered to that subscription. A consumer that hands such a condition to the messaging system is a Selective Consumer.
The filter has a price on the publisher's side. The stations attribute is now part of what the control room promises: drop it, or fill it only with stations where the train stops for more than a minute, and screens stop showing those trains, with no error anywhere. That is one case of a wider problem.
The field Delay Repay was reading
In March the control-room team changed what delayMinutes meant. It had been the delay expected at the train's final destination; now it was the delay at the last station the train had passed, which is what the screens wanted. The change was tested against the app and the screens, the two subscribers the team knew about. Delay Repay used it to flag journeys likely to qualify for compensation, which starts at 15 minutes late at the destination. It read the new number for two weeks before anyone noticed that trains expected at Ashvale Central 20 minutes late were not being flagged: their messages now said 9, the delay at the station each train had last passed.
A publisher that does not know its subscribers does not know what they rely on either. Every field, every event type, even the fact that an event is published at all, can become someone's dependency, and nothing in the publisher's code shows it. The control room kept its freedom to gain subscribers and lost, without noticing, its freedom to change what it says.
The defence is to treat the message as a published contract. Change a meaning by adding a field rather than redefining an old one: delayMinutes keeps its destination meaning, the screens read a new delayAtLastStationMinutes, and a field is retired only after asking who reads it. The code cannot answer that question, but the broker can narrow it: it knows which subscriptions exist on train-running, and recording an owning team for each one turns that list into people to ask. Schema evolution: event formats & compatibility shows how event formats can change without breaking their readers.
Two publishers, five subscribers, no shortcuts
The Publish / Subscribe Challenge asks for publishers that emit events, an Event Bus that distributes them, subscribers that consume them without knowing the publishers, and a design whose many-to-many intent is clear. Draw the many-to-many on purpose: two Publisher nodes on the bus, say the control room and a timetable planner that publishes platform changes, and four or five Subscriber nodes behind it, with each subscriber's edge labelled by what it subscribes to, such as "Millbrook only" or "all delays". No edge runs from a publisher to a subscriber. Then add one more subscriber: if that needs a new edge at either publisher, the contract has leaked. The node in the middle has an article of its own, Event Bus, about what that shared routing point does and does not promise.