Messaging Patterns: Change Detection Events

Listen to a stream of events and produce a new event when a value changes.

By Mathias Verraes
Published on 23 May 2019



Change Detection Events

Listen to a stream of events and produce a new event when a value changes.

Problem

A consumer is interested in an event stream, but the consumer only wants to know when a particular value changes, and doesn’t care about the events where that value didn’t change. Optionally, the consumer only cares when the value changes more than a given interval.

Solution

A second intermediary consumer is placed in front of the original consumer. It acts as a filter, emitting Change Detection Events when the observed value is different from the previous event. It may also ignore changes that are too small for the original consumer.

Change Detection Events are often used in combination with Ephemeral Events.

Example

The producer emits TemperatureWasMeasured multiple times per second. A consumer is only interested in changes of 1°C or more. An intermediate consumer listens to the TemperatureWasMeasured events. When an event arrives, it compares the temperature with the temperature from the previous event. If it differs by more than 1°C, it emits a TemperatureHasChanged event.