Check every reading, but only for now
"Can we check every reading against the meter's previous one for a week, without redeploying the billing loader?" The question came from the billing team at an electricity supplier. About two million smart meters send a reading every 30 minutes, roughly 1,100 messages a second, onto a channel the billing loader consumes. After a firmware update on one meter model, a few readings a day went backwards: a register that should only climb reported less than half an hour before, and those customers' bills showed negative consumption.
A permanent check would cost a lookup per reading, forever, for a fault the next firmware release may fix. Changing the billing loader means releasing the one component nobody wants to touch. What the team wanted was a step they could put into the flow and take out again while it runs.
A router that reads a switch, not the message
A Detour, in the Enterprise Integration Patterns catalogue, is a router on the path with two ways out. In one state it sends each message straight to the channel the billing loader reads. In the other it sends it to extra steps first, here a validator, and the validator puts each reading that passes back on that same channel. The billing loader cannot tell which way a reading came.
What sets the route apart from a Content-Based Router is where the decision comes from. A Content-Based Router looks inside each message. A Detour looks at a switch it holds, outside every message, which Hohpe and Woolf call a context-based router: while the switch stays where it is, every reading takes the same way, whatever it contains.
With the detour on, every reading goes through the validator, and those that pass come back to the billing loader unchanged; with it off, readings go straight there. The switch arrives on the Control Bus.
Who flips it
Once the router and the validator are deployed, the switch moves on a command, not a deploy. The Detour listens on the Control Bus, the integration's channel for operational messages, and the engineer on call publishes a detour on addressed to it; a week later, detour off puts the readings back on the short path. The switch is close to a Feature Toggle, a runtime flag that changes behaviour without a deploy, held by a router instead of inside application code. Two details decide whether the command does what the engineer thinks it did:
- The router runs as four replicas, one per partition of the channel, and each holds its own switch. A command on a queue the replicas share reaches only one of them, and only that replica's partition gets checked, about a quarter of the readings if the four partitions carry similar volumes; each replica needs its own copy of it, as Control Bus explains.
- A replica that restarts comes back in its default state, here off, unless the switch is stored somewhere it reads at start. A restart in the middle of the week quietly lets that replica's readings skip the check.
Back on the main path, unchanged
The validator's job is to look, comparing each reading with the last one accepted for that meter so that a rejected reading never becomes the reference, and to hold back the readings that fail. A reading that passes has to come back exactly as it left: same body, same headers the billing loader reads, same channel. If the validator also converts units, or adds a validated header that the billing loader starts relying on, the detour has become part of the main path without anyone deciding it, and the switch can no longer be turned off without changing what billing receives.
The readings that fail go to a channel of their own, which the billing team reviews each morning, not into nothing: a reading dropped without a record leaves a hole in a customer's bill that nobody can trace afterwards.
Flipping the switch can also reorder messages. When the detour turns off, readings still queued at the validator arrive after newer ones that went straight through. The billing loader stores each reading by meter and interval, so a late one lands in its slot. A consumer that depends on arrival order would need a Resequencer around each flip.
Looking at the flow, or standing in it
Had the team only wanted to watch the readings, a Detour would have been the wrong tool. A Wire Tap copies each message to a second channel and leaves the main path alone, so a slow observer does not hold up the main flow while that second channel has room. A Detour puts its steps in the path. That is the point when a step must be able to hold a message back, as validation must, and it is the price: while the detour is on, the validator carries all 1,100 readings a second, and if it falls behind or stops, billing falls behind or stops with it. Size the detour's steps for the full flow, not for the few messages they are looking for.
Sending only a share of the traffic through a new step before making it mandatory is a staged rollout done at the router, and its questions belong to Canary Deployment.
The week that never ends
The common mistake is leaving a debug detour switched on after the investigation ends: every message keeps paying for an extra hop nobody remembers to turn off. Here that hop is a lookup per reading and a validator sized for the whole flow, still running months after the firmware fix. Give each detour an owner and an end date when it goes on, and have the router keep announcing on the Control Bus that it is detouring, so a forgotten one shows up on the console instead of only on the bill for the validator.
The Message Transformation Challenge does not require a Detour, but its palette has one. Put the Detour in front of the Message Translator, send the detoured branch through a Message Filter, the step that drops whole messages that fail a check, and bring it back to the Translator's input. A valid message should reach the Translator the same way whichever branch it took; if the filter branch changes it, the detour has become part of the main path.