In Event Processing (EP) and it’s sub-disciplines CEP and ESP there’s a very important concept called context. For some reason the IT world chooses as generic names as possible to all kinds of important concepts which would benefit from a more specific and inspiring name.
The context in is one of the defining features of EP. It’s something you need to understand and be friends with in order to really appreciate the power of EP.
Unfortunately it seems that there are some confusion about what a context is. Which I understand, being such a generic term and a concept used in various places outside CEP.
The event processing context is, in short, the set of events that you see when executing your CEP rules, procedural code or your streaming version of SQL.
The most trivial context is the event that you just received, for simplicity just assume that you receive one event at the time. The concept of "events that happen at the same time" is too confusing anyway.
A more complex context can be constructed by keeping any number of the events that you received. For example the last 10, or the events received during the last 10 minutes. Commonly this kind of context is referred to as a window in many products.
An even more advanced context can be constructed by applying different kinds of conditions to events in order to determine if they should be included in the context. For example, that they should be emitted by a car which is currently in Stockholm. You could also use various types of event relationships to determine if events should be included in the context.
The context can include events which you receive as time goes by, you select some of these to be included in your context. The context can also contain historical events which have occurred before you started your processing. As time goes by, events are inserted and removed from the context.
If you are in a hurry, read only this: an event window is not the same thing as a context. An event window is a type of context!
To decide what events should be included in the context, a large number of factors can be considered. Depending on your type of CEP system you might find context management which takes into account:
- Event causality
- Temporal relationships
- Historical events
- Reference data
and so on…
A rich context could for example be, all events that:
- Are notifications about new GPS locations of entities of type heavy vehicle, and
- The events occurs during working hours, and
- The vehicle is located in Construction Zone X. and
- The cargo of the vehicle weights over 40 tons, and
- It travels on a road classified as temporary, and
- The driver is listening to Iron Maiden
Well, ok. I might made the last one up. But I hope you get the general idea; All of the above must be true at any point of time for the event to be included in the context.
Also note that in this case we would probably have one context per vehicle.
In the context you have a bunch of events which are all related somehow, possible in very complex ways. By using these events as an input to whatever processing your system is doing, your processing logic will be much simpler than if you were operating on the raw stream of events.
So, rich context management avoids processing the raw stream of events and gives you a easy way to select only those events in which you are interested.