Overview

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.

FAQ

```html
What is a context in event processing?A context is a named specification of conditions that groups event instances so they can be processed in a related way. It assigns events to one or more context partitions.
Why is context important in event processing systems?Context allows the same event to be processed differently depending on conditions such as time, location, external state, or event attributes. It also helps isolate related events and can improve processing efficiency.
What are the four main context dimensions discussed in Chapter 7?The four main context dimensions are temporal context, spatial context, state-oriented context, and segmentation-oriented context.
What is a temporal context?A temporal context consists of one or more time intervals, possibly overlapping. Each interval corresponds to a partition containing events that occur during that time.
What are the four types of temporal context?The four temporal context types are fixed interval, event interval, sliding fixed interval, and sliding event interval.
What is the difference between fixed interval and sliding fixed interval contexts?A fixed interval context uses one fixed time period or a regularly repeating set of non-overlapping periods. A sliding fixed interval context opens new windows at regular time intervals relative to one another, and the windows may overlap.
What is a spatial context?A spatial context groups events according to geospatial characteristics, such as whether an event occurred within a location, near an entity, or within a distance of an event or entity.
What is the difference between state-oriented and segmentation-oriented context?State-oriented context depends on the state of an external entity, such as a threat level or traffic condition. Segmentation-oriented context groups events based on values of one or more attributes in the events themselves, such as driver or customer ID.
What is a composite context?A composite context is built from two or more member contexts. Its partitions are formed from the combination of the member context partitions, often using a priority order to determine how classification is applied.
What is a context initiator policy?A context initiator policy defines what happens when a new initiator event occurs while a window or partition is already active. The possible policies are Add, Ignore, Refresh, and Extend.
```

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Event Processing in Action Event Processing in Action ebook for free