Chapter 7. Putting events in context
Context is presented as a core idea for event processing because the same event can require different handling depending on timing, location, entity membership, or external system state. Rather than building large networks of filters and routes, the book treats context as an explicit construct that groups events into partitions so that each partition can be processed independently, often by a separate agent instance with its own local state. This makes context especially useful for stateful processing, but also valuable for stateless agents when it acts as a natural filter.
The chapter then explains the main context dimensions and the kinds of partitions they create. Temporal context organizes streams into time-based windows, including fixed intervals, event-triggered intervals, and sliding windows based on time or event counts. Spatial context groups events by geographic meaning, such as fixed locations, distance from an entity, or distance from an initiating event, often using geocoding and spatial relations. State-oriented context depends on the status of an external entity, while segmentation-oriented context groups events by values inside the events themselves, such as customer, driver, or request identifiers.
Finally, the chapter shows how contexts can be combined into composite contexts, where the set of partitions is built from multiple member contexts and the order of application can matter. Priority order becomes important when a temporal grouping is relative rather than absolute, as different sequences of classification can produce different results. The Fast Flower Delivery application is used throughout to show practical context definitions such as monthly, daily, delivery, bid, pickup, and driver-evaluation contexts, illustrating how contexts support alerts, aggregation, and coordination across the event-driven system. It closes by noting that many real event processing languages provide windowing features that correspond closely to these context ideas.
The context definition element
The different types of context showing their context parameters and partition parameters. This diagram also shows the principal dimension associated with a type, for example, the fixed location type is concerned with the spatial context dimension.
Different types of temporal context with their context partitions
Examples of spatial context
Various spatial relation types. Each row illustrates a different relation type, showing examples for which the relation is satisfied.
The various context initiator policy options
An example showing the composition of segmentation-oriented context and temporal context. Each square is a separate context partition and designates the combination of an hour-long interval and a specific customer.
An example definition of temporal segmentation using Amit. Note: Amit is not available through the Event Processing in Action website.
Event Processing in Action ebook for free