Algorithm Search⌘K

Problemadvanced

Complex event processing

Also called CEP, event pattern matching.

Detect patterns of events, such as sequences with predicates and time limits, over a stream and report each match.

Time
Ω(n + T) worst
Where
T = the number of matches reported; k = the number of components of the pattern; n = the number of events in the stream

Complex event processing is the problem of finding, in a stream of timestamped events, every occurrence of a pattern made of simpler events: for example an item that is read on a shelf and then at the exit with no checkout in between, within 12 hours. A pattern combines event types with sequence, negation, repetition, conditions on attributes and a time window, and each match must be reported as soon as it is complete. Most engines evaluate patterns with automata that read the stream, which makes the problem a form of matching a regular language against an unbounded sequence, with data in the letters. The page NFA-based event pattern matching (SASE) gives one such algorithm in full.

In plain words

A stream of small events comes in: badge reads, card payments, price ticks, sensor alarms. One event alone says little, but a certain sequence of them means something, such as a card that pays in two cities within an hour. You write a pattern that describes the sequence, with the order of the events, the conditions on their values, events that must not occur in between, and a time limit. The system watches the stream and calls out each time the pattern happens, at the moment of the event that completes it. The hard parts are that many partial sequences can be open at once, that one event can belong to many matches, and that events can arrive out of order.

Definition

An event has a type, a timestamp and attributes. The input is a stream x1,x2,…x_1, x_2, \dots of events, ordered by timestamp, with ties broken by a fixed rule. A sequence pattern is

P=SEQ(C1,…,Ck) WHERE θ WITHIN W,P = \mathrm{SEQ}(C_1, \dots, C_k) \ \mathrm{WHERE}\ \theta \ \mathrm{WITHIN}\ W,

where each component CiC_i is an event type EiE_i, a negated type !Ei!E_i or, in languages with Kleene closure, a repetition Ei+E_i+; θ\theta is a condition on the attributes of the chosen events; and WW is a time span. Under the most permissive selection, a match is a tuple of events (e1,…,em)(e_1, \dots, e_m), one for each positive component, at increasing positions in the stream, such that eie_i has the type of its component, θ\theta holds, the span from the first to the last event is at most WW, and for each negated component, no event of that type that satisfies its part of θ\theta lies between the events of its neighbours.

The task is online: after each event xjx_j, report every match whose last event is xjx_j, each match once. A match cannot be reported earlier, because it is not complete before xjx_j arrives. With a negated last component, a match can be reported only when the window has passed without the negated event.

Variants

  • Event selection strategies. SASE+ names four rules for which events may form a match. Strict contiguity: the events of a match are adjacent in the stream. Partition contiguity: they are adjacent within the partition given by an equality condition, such as one stock symbol. Skip till next match: events that cannot extend a partial match are skipped, but a partial match takes the next event that fits and does not branch. Skip till any match: every combination is a match, so a partial match branches on each event that fits.
  • Consumption. Some languages consume the events of a match, so that an event takes part in at most one match. Others let an event be reused.
  • Kleene closure and aggregates. A component E+E+ takes one or more events, with conditions such as "each price is higher than the one before", and the output may aggregate them.
  • Windows. Time windows, count windows, or a window that starts at a given event.
  • Order and time. Events may carry event time and arrive out of order, or the system may use arrival time only. See below.
  • Output. Report every match, the first match only, or a summary such as the number of matches.

Examples

Take SEQ(a,b)\mathrm{SEQ}(a, b) WITHIN 10 on the stream a@1,a@2,b@3,c@4,b@5a@1, a@2, b@3, c@4, b@5.

strategy matches
strict contiguity (a@2, b@3)
skip till next match (a@1, b@3), (a@2, b@3)
skip till any match (a@1, b@3), (a@1, b@5), (a@2, b@3), (a@2, b@5)

Under strict contiguity, a@1 is followed by a@2, which is not a bb, so only a@2 and b@3 are adjacent. Under skip till next match, a partial match starts at each aa and takes the next bb, which is b@3 for both. Under skip till any match, every aa pairs with every later bb in the window.

With a negation, SEQ(a,!c,b)\mathrm{SEQ}(a, !c, b) WITHIN 10 under skip till any match gives (a@1, b@3) and (a@2, b@3), because c@4 lies between each aa and b@5.

With an equality condition, a card fraud rule is SEQ(Pay p,Pay q)\mathrm{SEQ}(\mathrm{Pay}\ p, \mathrm{Pay}\ q) WHERE p.card=q.cardp.\mathrm{card} = q.\mathrm{card} and p.city≠q.cityp.\mathrm{city} \ne q.\mathrm{city} WITHIN 1 hour. The equality on the card splits the stream into one sub-stream per card.

Known algorithms

  • Automata with shared stacks or buffers. SASE (Wu, Diao and Rizvi, 2006) runs a nondeterministic automaton over the stream and keeps the partial matches in stacks with pointers to their predecessors; it builds each match when its last event arrives and pushes the window and the equality tests into the stacks. SASE+ (2008) extends this to Kleene closure with an NFA and a shared match buffer. The SASE page proves that the stack scheme reports each match once, with a search cost of O(k2)O(k^2) per match.
  • Other automaton models. Cugola and Margara (2012) survey engines that compile patterns into automata, such as Cayuga, and the CEP libraries of stream processors such as Apache Flink also use automata.
  • Trees of operators. Some engines evaluate a sequence as a tree of join-like operators over buffers of events, which allows a cost-based choice of the order in which the components are joined; ZStream (Mei and Madden, 2009) is an example.
  • Relational evaluation. A sequence pattern with a window is a self-join of the stream with conditions on the order of the timestamps, so a continuous query engine can evaluate it with window joins. This is general but usually slower than a dedicated matcher.
  • Plain automata for strict contiguity. With strict contiguity and conditions on single events only, the pattern is a regular expression over the event types, and a deterministic automaton or an NFA simulation finds the matches in time proportional to the stream.
AlgorithmTimeSpacePropertiesCode
NFA-based event pattern matching (SASE)O(k^2 M + k n) worstO(k n) extradeterministicexactnot externalnot in placeonlinerecursive1 language

Bounds

  • Theorem (output size). Any algorithm must read every event and report every match, so it needs Ω(n+T)\Omega(n + T) time. Under skip till any match, TT can be very large: if a window holds n/kn/k events of each of the types E1,…,EkE_1, \dots, E_k, in this order, then every choice of one event per type is a match, so T≥(n/k)kT \ge (n/k)^k.
  • Theorem (strict contiguity). For a fixed pattern of types under strict contiguity, without conditions across events, the set of streams that end with a match is a regular language, so a deterministic automaton reports matches in O(1)O(1) time per event, with a number of states that depends only on the pattern. A time window adds a test on the timestamps of the open match, which the automaton cannot do with its states alone; for a pattern of kk single events, keeping the last kk timestamps is enough.
  • Skip till next match. Each partial match takes one path, so it gives at most one match per start event. The work per event is proportional to the number of open partial matches, which the window bounds.
  • Measurements. The papers on SASE, SASE+ and their successors measure throughput on synthetic and real streams. These are measurements on their systems, and this page does not repeat them.

Reductions

  • Regular expression matching. Strict contiguity on event types is the same as regular expression search in a string whose letters are the event types, so CEP under strict contiguity is at least as hard as this classic problem and, without data conditions, no harder.
  • Window joins. A sequence of kk components under skip till any match is a kk-way self-join of the stream with the conditions e1.ts≤⋯≤ek.tse_1.ts \le \cdots \le e_k.ts, ek.ts−e1.ts≤We_k.ts - e_1.ts \le W and θ\theta. A negation becomes an anti-join. So every sequence pattern can be written as a continuous query over windows, as in the CQL stream model.
  • From matches to streams. The output of a pattern is a stream of complex events, which can be the input of other patterns. This is how hierarchies of events are built.

Applications

The SASE papers motivate the problem with RFID tracking in retail and supply chains, such as the shoplifting pattern. Other common uses are financial trading, where a pattern detects a price movement across stocks; fraud detection on payments; intrusion detection on network logs; and the monitoring of sensors and business processes.

Late data. Most matchers need the events in timestamp order. A stream with bounded disorder can be reordered with a buffer that holds each event for a fixed delay, as on the event-time watermark page, at the cost of that delay in every report. A late event that falls outside the delay can complete a match that was already missed, or, under negation, show that a reported match was false. A system must then drop the event, report the missed match late, or retract the earlier report. The choice is part of the semantics of the query, not of the algorithm.

References

  1. Gianpaolo Cugola and Alessandro Margara, Processing flows of information: from data stream to complex event processing, ACM Computing Surveys 44(3), 2012, article 15, pages 15:1 to 15:62, the information flow processing model, the comparison of data stream and complex event processing systems, the operators of event languages (sequences, negation, iteration, windows, parameters) and the survey of systems with automata, trees and rules (general locator)
  2. Eugene Wu, Yanlei Diao and Shariq Rizvi, High-performance complex event processing over streams, Proceedings of ACM SIGMOD 2006, pages 407 to 418, the SASE language with SEQ, negation, equivalence tests and WITHIN, and its evaluation with active instance stacks (general locator)
  3. Jagrati Agrawal, Yanlei Diao, Daniel Gyllstrom and Neil Immerman, Efficient pattern matching over event streams, Proceedings of ACM SIGMOD 2008, pages 147 to 160, Kleene closure and the four event selection strategies: strict contiguity, partition contiguity, skip till next match and skip till any match (general locator)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a contract.yaml