SlideShare a Scribd company logo
1 of 82
Download to read offline
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Looking for Patterns -
FlinkCEP Library
_D. Wysakowicz
WHUG
03.07.2017
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
About me
■ Data Engineer at GetInData
■ Apache Flink Committer
■ Involved in Flink CEP library development
Dawid Wysakowicz
@OneMoreCoder
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
That moment
when party
goes wrong.
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Were there
any signs?
Any Patterns?
That moment
when party
goes wrong.
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Image source: “Continuous Analytics: Stream Query Processing in Practice”, Michael J Franklin, Professor, UC Berkley, Dec 2009 and
http://www.slideshare.net/JoshBaer/shortening-the-feedback-loop-big-data-spain-external
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Buying Home Insurance Online
Property
Info
Offer
Accept
General Terms
of Contract
PaymentScope
Change
Info
Change
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Buying Home Insurance Online
Property
Info
Offer
Accept
Exit
Scope
Change
Info
Change
General Terms
of Contract
Payment
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Simple Example - Matching Payments
Notify whenever a payment for accepted offer arrives
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Create Pattern
/* create pattern sequence*/
Pattern<Event, ?> pattern = Pattern<Event>
.begin("offer accepted")
.subtype(OfferAccepted.class)
.followedBy("payment received")
.subtype(PaymentReceived.class)
.within(Time.hours(48));
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Apply Pattern
/* create pattern sequence*/
Pattern<Event, ?> pattern = Pattern<Event>
.begin("offer accepted")
.subtype(OfferAccepted.class)
.followedBy("payment received")
.subtype(PaymentReceived.class)
.within(Time.hours(48));
/* convert match sequence into alerts */
DataStream<Alert> alerts = CEP.pattern(stream, pattern)
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Select Matches
/* create pattern sequence*/
Pattern<Event, ?> pattern = Pattern<Event>
.begin("offer accepted")
.subtype(OfferAccepted.class)
.followedBy("payment received")
.subtype(PaymentReceived.class)
.within(Time.hours(48));
/* convert match sequence into alerts */
DataStream<Alert> alerts = CEP.pattern(stream, pattern)
.select(new PatternSelectFunction<Event, Alert>() {
@Override
public Alert select(Map<String, List<Event>> match) throws Exception {
return createAlert(match);
}
});
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Handle Results
/* create pattern sequence*/
Pattern<Event, ?> pattern = Pattern<Event>
.begin("offer accepted")
.subtype(OfferAccepted.class)
.followedBy("payment received")
.subtype(PaymentReceived.class)
.within(Time.hours(48));
/* convert match sequence into alerts */
DataStream<Alert> alerts = CEP.pattern(stream, pattern)
.select(new PatternSelectFunction<Event, Alert>() {
@Override
public Alert select(Map<String, List<Event>> match) throws Exception {
return createAlert(match);
}
});
/* write out results */
alerts.addSink(...);
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Seamless Integration - Standard Pipeline
DataStream
Source e.g.
DataStream
Sink e.g.
DataStream
Transformations
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Seamless Integration - CEP Library
DataStream
Source e.g.
DataStream
Sink e.g.
DataStream
Transformations
CEP
DataStream Pattern
DataStream
Stream of matches
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
CEP Resulting Matches
CEP
DataStream
Pattern
A -> B -> C
C2C1B2B1A
DataStream
Stream of matches
A, B1, C1 A, B2, C1 A, B1, C2 A, B2, C2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
CEP Timeouted Matches
CEP
DataStream
Pattern
A -> B -> C within 5 seconds
C2(t=7)B2(t=4)B1(t=2)A(t = 1)
DataStream
Stream of timeouted matches
W=6
?
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
CEP Timeouted Matches
CEP
DataStream
Pattern
A -> B -> C within 5 seconds
C2(t=7)B2(t=4)B1(t=2)A(t = 1)
DataStream
Stream of timeouted matches
A A, B1 A, B2
W=6
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Pattern Sequence
Pattern
.begin("start")
.subtype(Event.class)
.where(...)
.or(...)
.followedBy("next")
.subtype(Event.class)
.where(...)
.where(...)
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Patterns
Pattern
.begin("start")
.subtype(Event.class)
.where(...)
.or(...)
.followedBy("next")
.subtype(Event.class)
.where(...)
.where(...)
Basic building blocks
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Conditions
Pattern
.begin("start")
.subtype(Event.class)
.where(...)
.or(...)
.followedBy("next")
.subtype(Event.class)
.where(...)
.where(...)
Basic building blocks
Condition specification
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Time Restrictions
Pattern
.begin("start")
.subtype(Event.class)
.where(...)
.or(...)
.followedBy("next")
.subtype(Event.class)
.where(...)
.where(...)
.within(Time.seconds(3))
Basic building blocks
Condition specification
Time restrictions
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Time Restrictions
Pattern
.begin("start")
.subtype(Event.class)
.where(...)
.or(...)
.followedBy("next")
.subtype(Event.class)
.where(...)
.where(...)
.within(Time.seconds(3))
Basic building blocks
Condition specification
Time restrictions
NOTE: The time restriction is a
global property. This is a period in
which either whole match is
generated or partial matches are
timeouted.
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
■ Skip till next
Consuming Strategy
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
■ Skip till next
■ Strict continuity
Consuming Strategy
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
■ Skip till next
■ Strict continuity
■ Skip till any
Consuming Strategy
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
■ Skip till next
■ Strict continuity
■ Skip till any
■ Not follow
Consuming Strategy
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
■ Skip till next
■ Strict continuity
■ Skip till any
Consuming Strategy
■ Not follow
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
■ Skip till next
■ Strict continuity
■ Skip till any
■ Not follow
■ Not next
Consuming Strategy
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
■ Skip till next
■ Strict continuity
■ Skip till any
Consuming Strategy
■ Not follow
■ Not next
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Consuming Strategy
■ Skip till next
■ Strict continuity
■ Skip till any
■ Not follow
■ Not next
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Looping Example
How many offer changes before accepting?
...
?
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Pattern Specification
Pattern
.begin("start")
.subtype(Event.class)
.where(...)
.or(...)
.times(3)
.followedBy("next")
.subtype(Event.class)
.where(...)
.where(...)
.oneOrMore().optional()
.within(Time.seconds(3))
Quantifier application
Basic building blocks
Condition specification
Time restrictions
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Quantifiers
■ Singleton pattern
■ Complex pattern
● Times (count)
● Looping pattern
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Quantifiers
■ Singleton pattern
■ Complex pattern
● Times (count)
● Looping pattern
■ Optional pattern
● singleton -> optional
● times -> no or exactly n times
● oneOrMore -> zeroOrMore
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Complex Patterns - Consuming Strategies
?
Pattern
.begin("offer").subtype(Offer.class)
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
?
Pattern
.begin("offer").subtype(Offer.class)
.followedByAny("changes").subtype(OfferChanged.class)
Complex Patterns - Consuming Strategies
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
?
Pattern
.begin("offer").subtype(Offer.class)
.followedByAny("changes").subtype(OfferChanged.class)
.oneOrMore()
.consecutive()
Complex Patterns - Consuming Strategies
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
?
Pattern
.begin("offer").subtype(Offer.class)
.followedByAny("changes").subtype(OfferChanged.class)
.oneOrMore()
.consecutive()
.followedBy(“accepted”).subtype(OfferAccepted.class)
Complex Patterns - Consuming Strategies
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
■ Consuming strategy - before first element
■ Inner consuming strategy - between events matched in the
Pattern
Complex Patterns - Consuming Strategies
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Iterative Condition
Trigger alert when the same property changed.
PL Flood PL
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Iterative Condition
public abstract class IterativeCondition<T> implements Function, Serializable {
public abstract boolean filter(T value, Context<T> ctx) throws Exception;
/**
* @return An {@link Iterable} over the already accepted elements
* for a given pattern. Elements are iterated in the order they were
* inserted in the pattern.
*
* @param name The name of the pattern.
*/
public interface Context<T> extends Serializable {
Iterable<T> getEventsForPattern(String name);
}
}
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Iterative Condition
Trigger alert when the same property changed.
Pattern
.begin("first change").subtype(OfferChanged.class)
.followedBy("second change").subtype(OfferChanged.class)
.where(new IterativeCondition<OfferChanged>() {
@Override
public boolean filter(OfferChanged value, Context<OfferChanged> ctx) {
return ctx.getEventsForPattern("first change").iterator().next()
.property().equals(value.property());
}
});
PL Flood PL
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Complex Example
Alert when a user constantly decreases value of the
property
-12.000€
-14.000€
-24.000€
-100.000€
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Complex Example - Implementation
Alert when a user changed value by more than 200% of
previous average change
Pattern
.begin("change").subtype(ValueChanged.class)
.oneOrMore()
.followedBy("alerting change").subtype(ValueChanged.class)
.where(new IterativeCondition<OfferChanged>() {
@Override
public boolean filter(OfferChanged value, Context<OfferChanged> ctx) {
double averageChange = countAverage(ctx.getEventsForPattern("change"));
return value.change > 2 * averageChange;
}
});
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
FlinkCEP & Asian Telco
■ +15 subscriber-oriented triggers to implement
● e.g. when a subscriber registers in a roaming and then
spends X USD in a roaming
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Summary
■ Shortest possible feedback loop
■ Seamless integration with Flink ecosystem
■ Complex patterns
● Dynamic length
● Conditions based on calculations
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
How does it works underneath?
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventStream
Order handling
1 5 4 2
PatternOperator
ElementsQueue
1 2 4 5
NFA
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventStream
Order handling
1 5 4 82
W=5
PatternOperator
ElementsQueue
1 2 4 5
W=5
NFA
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventStream
Order handling
1 5 4 82
W=5
PatternOperator
ElementsQueue
1 2 4 5
W=5
NFA
MatchesStream
A B
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventStream
Order handling - late elements
1 5 4 8 32
W=5
PatternOperator
ElementsQueue
1 2 4 5
W=5
NFA
MatchesStream
A B
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventStream
Order handling - late elements
1 5 4 8 32
W=5
PatternOperator
ElementsQueue
1 2 4 5
W=5
NFA
MatchesStream
A B
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Nondeterministic Finite Automaton
■ Graph where:
● Vertices = States
● Edges = Transitions
■ IGNORE - event not consumed
■ TAKE - event consumed
■ PROCEED - event analyzed in the target state
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Example of NFA
Pattern
.begin(“A”)
.followedByAny(“B”).optional()
.next(“C”)
.followedBy(“D”)
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Example of NFA
A B? C D
TAKE TAKE
TAKE
PROCEED
IGNORE IGNORE IGNORE
TAKE
Pattern
.begin(“A”)
.followedByAny(“B”).optional()
.next(“C”)
.followedBy(“D”)
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventsStream
Example of NFA
A B? C D
TAKE TAKE
TAKE
PROCEED
IGNORE IGNORE IGNORE
TAKE
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventsStream
Example of NFA
A B? C D
TAKE TAKE
TAKE
PROCEED
IGNORE IGNORE IGNORE
TAKE
A
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventsStream
Example of NFA
A
A
B?
A
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventsStream
A B
Example of NFA
A B? C D
TAKE TAKE
TAKE
PROCEED
IGNORE IGNORE IGNORE
TAKE
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventsStream
A B
Example of NFA
A B? C D
TAKE TAKE
TAKE
PROCEED
IGNORE IGNORE IGNORE
TAKE
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventsStream
Example of NFA
A B? C D
TAKE TAKE
TAKE
PROCEED
IGNORE IGNORE IGNORE
TAKE
A B
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventsStream
Example of NFA
A
A
B?
A
B
A
C
B?
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventsStream
Example of NFA
A B? C D
TAKE TAKE
TAKE
PROCEED
IGNORE IGNORE IGNORE
TAKE
A B C
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventsStream
Example of NFA
A B? C D
TAKE TAKE
TAKE
PROCEED
IGNORE IGNORE IGNORE
TAKE
A B C
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventsStream
Example of NFA
A
A
B?
A
B
A
C
B?
D
B?
D
A
C
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
EventsStream
Example of NFA
A
A
B?
A
B
A
C
B?
D
B?
D
A
C D
Match: A, C, D
B?
Match: A, B, C, D
A
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2
© Copyright. All rights reserved. Not to be reproduced without prior written consent.
Shared Buffer - how it works
MiddleStart End
S1
S2
M1
M2
M3
E1
E2
1
2
1.0
1.0.0
1.0.0.0
2.0
1.0.0.0.0
1.0.0.0.1
2.0.0
Events order
S1 M1 M2 S2 M3 E1 E2

More Related Content

What's hot

Dynamic Allocation in Spark
Dynamic Allocation in SparkDynamic Allocation in Spark
Dynamic Allocation in Spark
Databricks
 
Apache Spark At Scale in the Cloud
Apache Spark At Scale in the CloudApache Spark At Scale in the Cloud
Apache Spark At Scale in the Cloud
Databricks
 
Can Apache Kafka Replace a Database?
Can Apache Kafka Replace a Database?Can Apache Kafka Replace a Database?
Can Apache Kafka Replace a Database?
Kai Wähner
 

What's hot (20)

Dynamic Allocation in Spark
Dynamic Allocation in SparkDynamic Allocation in Spark
Dynamic Allocation in Spark
 
Introduction to Apache Flink
Introduction to Apache FlinkIntroduction to Apache Flink
Introduction to Apache Flink
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internals
 
A Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and HudiA Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and Hudi
 
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
 
Improving Apache Spark for Dynamic Allocation and Spot Instances
Improving Apache Spark for Dynamic Allocation and Spot InstancesImproving Apache Spark for Dynamic Allocation and Spot Instances
Improving Apache Spark for Dynamic Allocation and Spot Instances
 
Change Data Capture to Data Lakes Using Apache Pulsar and Apache Hudi - Pulsa...
Change Data Capture to Data Lakes Using Apache Pulsar and Apache Hudi - Pulsa...Change Data Capture to Data Lakes Using Apache Pulsar and Apache Hudi - Pulsa...
Change Data Capture to Data Lakes Using Apache Pulsar and Apache Hudi - Pulsa...
 
Apache Spark At Scale in the Cloud
Apache Spark At Scale in the CloudApache Spark At Scale in the Cloud
Apache Spark At Scale in the Cloud
 
Using Apache Calcite for Enabling SQL and JDBC Access to Apache Geode and Oth...
Using Apache Calcite for Enabling SQL and JDBC Access to Apache Geode and Oth...Using Apache Calcite for Enabling SQL and JDBC Access to Apache Geode and Oth...
Using Apache Calcite for Enabling SQL and JDBC Access to Apache Geode and Oth...
 
A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...
A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...
A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...
 
Introduction to Apache Flink
Introduction to Apache FlinkIntroduction to Apache Flink
Introduction to Apache Flink
 
Where is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in FlinkWhere is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in Flink
 
Can Apache Kafka Replace a Database?
Can Apache Kafka Replace a Database?Can Apache Kafka Replace a Database?
Can Apache Kafka Replace a Database?
 
Deep dive into stateful stream processing in structured streaming by Tathaga...
Deep dive into stateful stream processing in structured streaming  by Tathaga...Deep dive into stateful stream processing in structured streaming  by Tathaga...
Deep dive into stateful stream processing in structured streaming by Tathaga...
 
Streaming SQL with Apache Calcite
Streaming SQL with Apache CalciteStreaming SQL with Apache Calcite
Streaming SQL with Apache Calcite
 
The evolution of Apache Calcite and its Community
The evolution of Apache Calcite and its CommunityThe evolution of Apache Calcite and its Community
The evolution of Apache Calcite and its Community
 
Running Apache Spark on Kubernetes: Best Practices and Pitfalls
Running Apache Spark on Kubernetes: Best Practices and PitfallsRunning Apache Spark on Kubernetes: Best Practices and Pitfalls
Running Apache Spark on Kubernetes: Best Practices and Pitfalls
 
ksqlDB로 시작하는 스트림 프로세싱
ksqlDB로 시작하는 스트림 프로세싱ksqlDB로 시작하는 스트림 프로세싱
ksqlDB로 시작하는 스트림 프로세싱
 
The Top Five Mistakes Made When Writing Streaming Applications with Mark Grov...
The Top Five Mistakes Made When Writing Streaming Applications with Mark Grov...The Top Five Mistakes Made When Writing Streaming Applications with Mark Grov...
The Top Five Mistakes Made When Writing Streaming Applications with Mark Grov...
 
Step-by-Step Introduction to Apache Flink
Step-by-Step Introduction to Apache Flink Step-by-Step Introduction to Apache Flink
Step-by-Step Introduction to Apache Flink
 

Similar to Flink Complex Event Processing

[rwdsummit2012] Adaptive Images in Responsive Web Design
[rwdsummit2012] Adaptive Images in Responsive Web Design[rwdsummit2012] Adaptive Images in Responsive Web Design
[rwdsummit2012] Adaptive Images in Responsive Web Design
Christopher Schmitt
 

Similar to Flink Complex Event Processing (20)

FlinkCEP Library - Dawid Wysakowicz, GetInData (WHUG)
FlinkCEP Library - Dawid Wysakowicz, GetInData (WHUG)FlinkCEP Library - Dawid Wysakowicz, GetInData (WHUG)
FlinkCEP Library - Dawid Wysakowicz, GetInData (WHUG)
 
Flink Forward Berlin 2017: Dawid Wysakowicz - Looking for patterns with Flink...
Flink Forward Berlin 2017: Dawid Wysakowicz - Looking for patterns with Flink...Flink Forward Berlin 2017: Dawid Wysakowicz - Looking for patterns with Flink...
Flink Forward Berlin 2017: Dawid Wysakowicz - Looking for patterns with Flink...
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
 
Adtech scala-performance-tuning-150323223738-conversion-gate01
Adtech scala-performance-tuning-150323223738-conversion-gate01Adtech scala-performance-tuning-150323223738-conversion-gate01
Adtech scala-performance-tuning-150323223738-conversion-gate01
 
Adtech x Scala x Performance tuning
Adtech x Scala x Performance tuningAdtech x Scala x Performance tuning
Adtech x Scala x Performance tuning
 
Streaming analytics better than batch – when and why by Dawid Wysakowicz and ...
Streaming analytics better than batch – when and why by Dawid Wysakowicz and ...Streaming analytics better than batch – when and why by Dawid Wysakowicz and ...
Streaming analytics better than batch – when and why by Dawid Wysakowicz and ...
 
Introduction to Client Side Dev in SharePoint Workshop
Introduction to Client Side Dev in SharePoint WorkshopIntroduction to Client Side Dev in SharePoint Workshop
Introduction to Client Side Dev in SharePoint Workshop
 
Assessing the Reliability of a Human Estimator
Assessing the Reliability of a Human EstimatorAssessing the Reliability of a Human Estimator
Assessing the Reliability of a Human Estimator
 
Naked Performance With Clojure
Naked Performance With ClojureNaked Performance With Clojure
Naked Performance With Clojure
 
Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...
Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...
Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
 
Backbone the Good Parts
Backbone the Good PartsBackbone the Good Parts
Backbone the Good Parts
 
Adopting F# at SBTech
Adopting F# at SBTechAdopting F# at SBTech
Adopting F# at SBTech
 
Advance sql - window functions patterns and tricks
Advance sql - window functions patterns and tricksAdvance sql - window functions patterns and tricks
Advance sql - window functions patterns and tricks
 
Agile Machine Learning for Real-time Recommender Systems
Agile Machine Learning for Real-time Recommender SystemsAgile Machine Learning for Real-time Recommender Systems
Agile Machine Learning for Real-time Recommender Systems
 
Preparing for distributed system failures using akka #ScalaMatsuri
Preparing for distributed system failures using akka #ScalaMatsuriPreparing for distributed system failures using akka #ScalaMatsuri
Preparing for distributed system failures using akka #ScalaMatsuri
 
[html5tx] Adaptive Images in Responsive Web Design
[html5tx] Adaptive Images in Responsive Web Design[html5tx] Adaptive Images in Responsive Web Design
[html5tx] Adaptive Images in Responsive Web Design
 
JavaScript Refactoring
JavaScript RefactoringJavaScript Refactoring
JavaScript Refactoring
 
From Zero to Hero – Web Performance
From Zero to Hero – Web PerformanceFrom Zero to Hero – Web Performance
From Zero to Hero – Web Performance
 
[rwdsummit2012] Adaptive Images in Responsive Web Design
[rwdsummit2012] Adaptive Images in Responsive Web Design[rwdsummit2012] Adaptive Images in Responsive Web Design
[rwdsummit2012] Adaptive Images in Responsive Web Design
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreel
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Buy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxBuy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptx
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 

Flink Complex Event Processing

  • 1. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Looking for Patterns - FlinkCEP Library _D. Wysakowicz WHUG 03.07.2017
  • 2. © Copyright. All rights reserved. Not to be reproduced without prior written consent. About me ■ Data Engineer at GetInData ■ Apache Flink Committer ■ Involved in Flink CEP library development Dawid Wysakowicz @OneMoreCoder
  • 3. © Copyright. All rights reserved. Not to be reproduced without prior written consent. That moment when party goes wrong.
  • 4. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Were there any signs? Any Patterns? That moment when party goes wrong.
  • 5. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Image source: “Continuous Analytics: Stream Query Processing in Practice”, Michael J Franklin, Professor, UC Berkley, Dec 2009 and http://www.slideshare.net/JoshBaer/shortening-the-feedback-loop-big-data-spain-external
  • 6. © Copyright. All rights reserved. Not to be reproduced without prior written consent.
  • 7. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Buying Home Insurance Online Property Info Offer Accept General Terms of Contract PaymentScope Change Info Change
  • 8. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Buying Home Insurance Online Property Info Offer Accept Exit Scope Change Info Change General Terms of Contract Payment
  • 9. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Simple Example - Matching Payments Notify whenever a payment for accepted offer arrives
  • 10. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Create Pattern /* create pattern sequence*/ Pattern<Event, ?> pattern = Pattern<Event> .begin("offer accepted") .subtype(OfferAccepted.class) .followedBy("payment received") .subtype(PaymentReceived.class) .within(Time.hours(48));
  • 11. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Apply Pattern /* create pattern sequence*/ Pattern<Event, ?> pattern = Pattern<Event> .begin("offer accepted") .subtype(OfferAccepted.class) .followedBy("payment received") .subtype(PaymentReceived.class) .within(Time.hours(48)); /* convert match sequence into alerts */ DataStream<Alert> alerts = CEP.pattern(stream, pattern)
  • 12. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Select Matches /* create pattern sequence*/ Pattern<Event, ?> pattern = Pattern<Event> .begin("offer accepted") .subtype(OfferAccepted.class) .followedBy("payment received") .subtype(PaymentReceived.class) .within(Time.hours(48)); /* convert match sequence into alerts */ DataStream<Alert> alerts = CEP.pattern(stream, pattern) .select(new PatternSelectFunction<Event, Alert>() { @Override public Alert select(Map<String, List<Event>> match) throws Exception { return createAlert(match); } });
  • 13. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Handle Results /* create pattern sequence*/ Pattern<Event, ?> pattern = Pattern<Event> .begin("offer accepted") .subtype(OfferAccepted.class) .followedBy("payment received") .subtype(PaymentReceived.class) .within(Time.hours(48)); /* convert match sequence into alerts */ DataStream<Alert> alerts = CEP.pattern(stream, pattern) .select(new PatternSelectFunction<Event, Alert>() { @Override public Alert select(Map<String, List<Event>> match) throws Exception { return createAlert(match); } }); /* write out results */ alerts.addSink(...);
  • 14. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Seamless Integration - Standard Pipeline DataStream Source e.g. DataStream Sink e.g. DataStream Transformations
  • 15. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Seamless Integration - CEP Library DataStream Source e.g. DataStream Sink e.g. DataStream Transformations CEP DataStream Pattern DataStream Stream of matches
  • 16. © Copyright. All rights reserved. Not to be reproduced without prior written consent. CEP Resulting Matches CEP DataStream Pattern A -> B -> C C2C1B2B1A DataStream Stream of matches A, B1, C1 A, B2, C1 A, B1, C2 A, B2, C2
  • 17. © Copyright. All rights reserved. Not to be reproduced without prior written consent. CEP Timeouted Matches CEP DataStream Pattern A -> B -> C within 5 seconds C2(t=7)B2(t=4)B1(t=2)A(t = 1) DataStream Stream of timeouted matches W=6 ?
  • 18. © Copyright. All rights reserved. Not to be reproduced without prior written consent. CEP Timeouted Matches CEP DataStream Pattern A -> B -> C within 5 seconds C2(t=7)B2(t=4)B1(t=2)A(t = 1) DataStream Stream of timeouted matches A A, B1 A, B2 W=6
  • 19. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Pattern Sequence Pattern .begin("start") .subtype(Event.class) .where(...) .or(...) .followedBy("next") .subtype(Event.class) .where(...) .where(...)
  • 20. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Patterns Pattern .begin("start") .subtype(Event.class) .where(...) .or(...) .followedBy("next") .subtype(Event.class) .where(...) .where(...) Basic building blocks
  • 21. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Conditions Pattern .begin("start") .subtype(Event.class) .where(...) .or(...) .followedBy("next") .subtype(Event.class) .where(...) .where(...) Basic building blocks Condition specification
  • 22. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Time Restrictions Pattern .begin("start") .subtype(Event.class) .where(...) .or(...) .followedBy("next") .subtype(Event.class) .where(...) .where(...) .within(Time.seconds(3)) Basic building blocks Condition specification Time restrictions
  • 23. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Time Restrictions Pattern .begin("start") .subtype(Event.class) .where(...) .or(...) .followedBy("next") .subtype(Event.class) .where(...) .where(...) .within(Time.seconds(3)) Basic building blocks Condition specification Time restrictions NOTE: The time restriction is a global property. This is a period in which either whole match is generated or partial matches are timeouted.
  • 24. © Copyright. All rights reserved. Not to be reproduced without prior written consent. ■ Skip till next Consuming Strategy
  • 25. © Copyright. All rights reserved. Not to be reproduced without prior written consent. ■ Skip till next ■ Strict continuity Consuming Strategy
  • 26. © Copyright. All rights reserved. Not to be reproduced without prior written consent. ■ Skip till next ■ Strict continuity ■ Skip till any Consuming Strategy
  • 27. © Copyright. All rights reserved. Not to be reproduced without prior written consent. ■ Skip till next ■ Strict continuity ■ Skip till any ■ Not follow Consuming Strategy
  • 28. © Copyright. All rights reserved. Not to be reproduced without prior written consent. ■ Skip till next ■ Strict continuity ■ Skip till any Consuming Strategy ■ Not follow
  • 29. © Copyright. All rights reserved. Not to be reproduced without prior written consent. ■ Skip till next ■ Strict continuity ■ Skip till any ■ Not follow ■ Not next Consuming Strategy
  • 30. © Copyright. All rights reserved. Not to be reproduced without prior written consent. ■ Skip till next ■ Strict continuity ■ Skip till any Consuming Strategy ■ Not follow ■ Not next
  • 31. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Consuming Strategy ■ Skip till next ■ Strict continuity ■ Skip till any ■ Not follow ■ Not next
  • 32. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Looping Example How many offer changes before accepting? ... ?
  • 33. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Pattern Specification Pattern .begin("start") .subtype(Event.class) .where(...) .or(...) .times(3) .followedBy("next") .subtype(Event.class) .where(...) .where(...) .oneOrMore().optional() .within(Time.seconds(3)) Quantifier application Basic building blocks Condition specification Time restrictions
  • 34. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Quantifiers ■ Singleton pattern ■ Complex pattern ● Times (count) ● Looping pattern
  • 35. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Quantifiers ■ Singleton pattern ■ Complex pattern ● Times (count) ● Looping pattern ■ Optional pattern ● singleton -> optional ● times -> no or exactly n times ● oneOrMore -> zeroOrMore
  • 36. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Complex Patterns - Consuming Strategies ? Pattern .begin("offer").subtype(Offer.class)
  • 37. © Copyright. All rights reserved. Not to be reproduced without prior written consent. ? Pattern .begin("offer").subtype(Offer.class) .followedByAny("changes").subtype(OfferChanged.class) Complex Patterns - Consuming Strategies
  • 38. © Copyright. All rights reserved. Not to be reproduced without prior written consent. ? Pattern .begin("offer").subtype(Offer.class) .followedByAny("changes").subtype(OfferChanged.class) .oneOrMore() .consecutive() Complex Patterns - Consuming Strategies
  • 39. © Copyright. All rights reserved. Not to be reproduced without prior written consent. ? Pattern .begin("offer").subtype(Offer.class) .followedByAny("changes").subtype(OfferChanged.class) .oneOrMore() .consecutive() .followedBy(“accepted”).subtype(OfferAccepted.class) Complex Patterns - Consuming Strategies
  • 40. © Copyright. All rights reserved. Not to be reproduced without prior written consent. ■ Consuming strategy - before first element ■ Inner consuming strategy - between events matched in the Pattern Complex Patterns - Consuming Strategies
  • 41. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Iterative Condition Trigger alert when the same property changed. PL Flood PL
  • 42. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Iterative Condition public abstract class IterativeCondition<T> implements Function, Serializable { public abstract boolean filter(T value, Context<T> ctx) throws Exception; /** * @return An {@link Iterable} over the already accepted elements * for a given pattern. Elements are iterated in the order they were * inserted in the pattern. * * @param name The name of the pattern. */ public interface Context<T> extends Serializable { Iterable<T> getEventsForPattern(String name); } }
  • 43. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Iterative Condition Trigger alert when the same property changed. Pattern .begin("first change").subtype(OfferChanged.class) .followedBy("second change").subtype(OfferChanged.class) .where(new IterativeCondition<OfferChanged>() { @Override public boolean filter(OfferChanged value, Context<OfferChanged> ctx) { return ctx.getEventsForPattern("first change").iterator().next() .property().equals(value.property()); } }); PL Flood PL
  • 44. © Copyright. All rights reserved. Not to be reproduced without prior written consent.
  • 45. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Complex Example Alert when a user constantly decreases value of the property -12.000€ -14.000€ -24.000€ -100.000€
  • 46. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Complex Example - Implementation Alert when a user changed value by more than 200% of previous average change Pattern .begin("change").subtype(ValueChanged.class) .oneOrMore() .followedBy("alerting change").subtype(ValueChanged.class) .where(new IterativeCondition<OfferChanged>() { @Override public boolean filter(OfferChanged value, Context<OfferChanged> ctx) { double averageChange = countAverage(ctx.getEventsForPattern("change")); return value.change > 2 * averageChange; } });
  • 47. © Copyright. All rights reserved. Not to be reproduced without prior written consent. FlinkCEP & Asian Telco ■ +15 subscriber-oriented triggers to implement ● e.g. when a subscriber registers in a roaming and then spends X USD in a roaming
  • 48. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Summary ■ Shortest possible feedback loop ■ Seamless integration with Flink ecosystem ■ Complex patterns ● Dynamic length ● Conditions based on calculations
  • 49. © Copyright. All rights reserved. Not to be reproduced without prior written consent. How does it works underneath?
  • 50. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventStream Order handling 1 5 4 2 PatternOperator ElementsQueue 1 2 4 5 NFA
  • 51. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventStream Order handling 1 5 4 82 W=5 PatternOperator ElementsQueue 1 2 4 5 W=5 NFA
  • 52. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventStream Order handling 1 5 4 82 W=5 PatternOperator ElementsQueue 1 2 4 5 W=5 NFA MatchesStream A B
  • 53. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventStream Order handling - late elements 1 5 4 8 32 W=5 PatternOperator ElementsQueue 1 2 4 5 W=5 NFA MatchesStream A B
  • 54. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventStream Order handling - late elements 1 5 4 8 32 W=5 PatternOperator ElementsQueue 1 2 4 5 W=5 NFA MatchesStream A B
  • 55. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Nondeterministic Finite Automaton ■ Graph where: ● Vertices = States ● Edges = Transitions ■ IGNORE - event not consumed ■ TAKE - event consumed ■ PROCEED - event analyzed in the target state
  • 56. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Example of NFA Pattern .begin(“A”) .followedByAny(“B”).optional() .next(“C”) .followedBy(“D”)
  • 57. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Example of NFA A B? C D TAKE TAKE TAKE PROCEED IGNORE IGNORE IGNORE TAKE Pattern .begin(“A”) .followedByAny(“B”).optional() .next(“C”) .followedBy(“D”)
  • 58. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventsStream Example of NFA A B? C D TAKE TAKE TAKE PROCEED IGNORE IGNORE IGNORE TAKE
  • 59. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventsStream Example of NFA A B? C D TAKE TAKE TAKE PROCEED IGNORE IGNORE IGNORE TAKE A
  • 60. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventsStream Example of NFA A A B? A
  • 61. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventsStream A B Example of NFA A B? C D TAKE TAKE TAKE PROCEED IGNORE IGNORE IGNORE TAKE
  • 62. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventsStream A B Example of NFA A B? C D TAKE TAKE TAKE PROCEED IGNORE IGNORE IGNORE TAKE
  • 63. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventsStream Example of NFA A B? C D TAKE TAKE TAKE PROCEED IGNORE IGNORE IGNORE TAKE A B
  • 64. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventsStream Example of NFA A A B? A B A C B?
  • 65. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventsStream Example of NFA A B? C D TAKE TAKE TAKE PROCEED IGNORE IGNORE IGNORE TAKE A B C
  • 66. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventsStream Example of NFA A B? C D TAKE TAKE TAKE PROCEED IGNORE IGNORE IGNORE TAKE A B C
  • 67. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventsStream Example of NFA A A B? A B A C B? D B? D A C
  • 68. © Copyright. All rights reserved. Not to be reproduced without prior written consent. EventsStream Example of NFA A A B? A B A C B? D B? D A C D Match: A, C, D B? Match: A, B, C, D A
  • 69. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 70. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 71. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 72. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 73. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 74. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 75. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 76. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 77. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 78. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 79. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 80. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 81. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 82. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Shared Buffer - how it works MiddleStart End S1 S2 M1 M2 M3 E1 E2 1 2 1.0 1.0.0 1.0.0.0 2.0 1.0.0.0.0 1.0.0.0.1 2.0.0 Events order S1 M1 M2 S2 M3 E1 E2
  • 83. © Copyright. All rights reserved. Not to be reproduced without prior written consent. Summary ■ Shortest possible feedback loop ■ Seamless integration with Flink ecosystem ■ Complex patterns ● Dynamic length ● Conditions based on calculations