SlideShare a Scribd company logo
1 of 29
Download to read offline
Complex Event Processing:
Use Cases & FlinkCEP Library
Gordon Tai - @tzulitai
July 19, 2016 @ Flink.tw Meetup
00 This Talk is About ...
● How FlinkCEP got me interested in Flink
● CEP use cases & applications
○ Use case study #1: tracking an order process
○ Use case study #2: advertisement targeting
● A look at the API
1
● 戴資力(Gordon)
● Data Engineer @ VMFive
● Java, Scala
● Using Flink as an user on VMFive’s Adtech platform
● Enjoy working on distributed computing systems
● Works on Flink during free time
● Contributor: Flink Kinesis Consumer connector
00 Me & Flink
2
Tale of a Data Engineer trying to figure
out how to build up a streaming analytics
pipeline ...
1. First lesson: non-trivial streaming
applications are never stateless
2. Second lesson: statefull streaming
topologies are a pain
3
1. Exactly-once state updates on failures for correctness
2. Idempotance wrt. external state stores
3. Out-of-order events
4. Aggregating on time windows
5. Rapid application development
Applications I was working on:
Streaming aggregation for reporting &
Conversion patterns for alerting
4
TL;DR. It isn’t fun. At all.
● Reference:
Building a Stream Processing
System for Playable Ads Data
at VMFive @ HadoopCon 2015
● Redis was used as an external
state store
● All state update had to be
idempotent
● Exactly-once & replay on
failover implemented with
Storm’s tuple acking
mechanism
5
● Generate derived events when a specified pattern on raw
events occur in a data stream
○ if A and then B → infer complex event C
● Goal: identify meaningful event patterns and respond to
them as quickly as possible
● Demanding on the stream processor to provide robust state
handling & out-of-order events support while keeping low
latency with high throughput
01 Complex Event Processing
6
02 Apache Flink CEP Library
● Built upon Flink’s
DataStream API
● Allows users to define
patterns, inject them on
event streams, and
generates new event
streams based on the
pattern
● Exploits Flink’s exactly-
once semantics for definite
correctness
7
eCommerce Order Process Tracking
Use case study #1
** Note: the illustrations & content in this section is from Data Artisans’ presentation:
Streaming Analytics & CEP - Two Sides of the Same Coin?
03 Order Tracking Data Model
● Order(orderId, tStamp, “received”) extends Event
● Shipment(orderId, tStamp, “shipped”) extends Event
● Delivery(orderId, tStamp, “delivered”) extends Event
8
04 Real-Time Warnings for SLAs
● ProcessSucc(orderId, tStamp, duration)
● ProcessWarn(orderId, tStamp)
● DeliverySucc(orderId, tStamp, duration)
● DeliveryWarn(orderId, tStamp)
New inferred events:
9
05 Glimpse at the FlinkCEP API
val processingPattern = Pattern
.begin[Event]("orderReceived").subtype(classOf[ Order])
.followedBy( "orderShipped").where(_.status == "shipped")
.within(Time.hours(1))
val processingPatternStream = CEP.pattern(
input.keyBy( "orderId"),
processingPattern)
val procResult: DataStream[Either[ProcessWarn, ProcessSucc]] =
processingPatternStream.select {
(pP, timestamp) => // Timeout handler
ProcessWarn(pP("orderReceived").orderId, timestamp)
} {
fP => // Select function
ProcessSucc(
fP( "orderReceived").orderId, fP( "orderShipped").tStamp,
fP( "orderShipped").tStamp – fP( "orderReceived").tStamp)
}
10
06 Glimpse at the FlinkCEP API
val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
val input: DataStream[Event] = env.addSource(new FlinkKafkaConsumer09(...))
val processingPattern = Pattern.begin(...)...
val processingPatternStream = CEP.pattern(input.keyBy( "orderId"), processingPattern)
val procResult: DataStream[Either[ProcessWarn, ProcessSucc]] = processingPatternStream.select(...)
procResult.addSink(new RedisSink(...))
// .addSink(new FlinkKafkaProducer09(...))
// .addSink(new ElasticsearchSink(...))
// .map(new MapFunction{...})
// … anything you’d like to continue to do with the inferred event stream
env.execute()
11
07 Glimpse at the FlinkCEP API
val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
env.setStreamTimeCharacteristic( TimeCharacteristic.EventTime)
val input: DataStream[Event] = env
.addSource(new FlinkKafkaConsumer09(...))
.assignTimestampsAndWatermarks(new CustomExtractor)
val processingPattern = Pattern.begin(...)...
val processingPatternStream = CEP.pattern(input.keyBy( "orderId"), processingPattern)
val procResult: DataStream[Either[ProcessWarn, ProcessSucc]] = processingPatternStream.select(...)
procResult.addSink(new RedisSink(...))
// .addSink(new FlinkKafkaProducer09(...))
// .addSink(new ElasticsearchSink(...))
// .map(new MapFunction{...})
env.execute()
12
08 Combining Stream SQL & CEP
● Further reading: Streaming Analytics & CEP - Two Sides of the Same Coin?
13
Ad Targeting based on User Attribution
Use case study #2
** Note: the content in this section is heavily based on my experience at VMFive
14
09 Ad Targeting 101
● What an ad server does, in a nutshell →
determine an appropriate advertisement, chosen from an
advertisement campaign pool, for each incoming ad
request
AdServer
Campaign
Pool
(1) request advertisement
(2) return appropriate
advertisement info
from campaign pool
● “appropriate”:
fulfill the targeting rules of
each campaign
15
10 Ad Targeting Rule Types
● Fundamental campaign targeting rule types:
○ Target users’ current location, ex. users in Taipei
○ Target specific user device type, ex. tablet or phone
○ ...
● Advanced campaign targeting rule types:
○ Target user’s past location trace, ex. in Taipei for the past 7 days
○ Target users entering / departuring countries
○ Target users with specific attribution, ex. viewed
○ ...
16
11 Ad Targeting Rule Types
● Fundamental campaign targeting rule types:
○ Target users’ current location, ex. users in Taipei
○ Target specific user device type, ex. tablet or phone
○ ...
● Advanced campaign targeting rule types:
○ Target user’s past location trace, ex. in Taipei for the past 7 days
○ Target users entering / departuring countries
○ Target users with specific attribution, ex. viewed
○ ...
● Does not require event aggregation
● The rules can be matched simply
based on info at request time
● Requires aggregation of historical events
● Aggregating at request time will be far too slow
● Requires inferring complex events from patterns in
raw event stream → CEP to the rescue!
16
12 Basic Ad Targeting Architecture
Campaign Pool
Targeting Cache
Ad Targeter
register ad
campaigns
Event Logger
WebService
AdServerData Warehouse
17
(1) initial
connection
12 Basic Ad Targeting Architecture
Campaign Pool
Targeting Cache
Ad Targeter
Event Logger
WebService
AdServerData Warehouse
17
(2) fetch ad
12 Basic Ad Targeting Architecture
Ad Targeter
Event Logger
WebService
AdServerData Warehouse
Raw Logs
Event Bus Service
Reporting & analytics
services
Batch
Streaming
...
Campaign Pool
Targeting Cache
18
(3) event
tracking
13 Advanced Ad Targeting Architecture
Ad Targeter
Event Logger
WebService
AdServerData Warehouse
Raw Logs
Event Bus Service
Reporting & analytics
services
Batch
Streaming
...
RulesServuce
Campaign Pool
Targeting Cache
C
E
P
19
13 Advanced Ad Targeting Architecture
Data Warehouse
Raw Logs
Event Bus Service
Batch
Streaming
...
RulesService
C
E
P
CEP-Rule Templates
Rule
Fulfillment
Cache
(Redis)
Entry /
Depart
User
Attribution
...
(1) Inject a rule
to start matching
on event stream
(3)
submit
CEP
topology
(2) Return Rule ID
20
13 Advanced Ad Targeting Architecture
Data Warehouse
Raw Logs
Event Bus Service
Batch
Streaming
...
RulesService
C
E
P
CEP-Rule Templates
Rule
Fulfillment
Cache
(Redis)
Entry /
Depart
User
Attribution
...
(4) When CEP
pattern is fulfilled,
write to cache:
UID → RuleID
(5) Lookup
whether a UID
has fulfilled a
RuleID
21
13 Advanced Ad Targeting Architecture
Ad Targeter
register ad
campaigns
Event Logger
WebService
AdServerData Warehouse
Raw Logs
Event Bus Service
Reporting & analytics
services
Batch
Streaming
...
RulesService
Campaign Pool
Targeting Cache
C
E
P
22
(1) register rule
for campaign
(2) lookup whether
user fulfils a rule
14 Some Discussion
● Why a fixed pool of CEP-Rule Templates?
○ Prevent rogue rules to match, ex. rules that will consume too much resource
○ It’s a lot less work and complication ;)
● Would be very nice to have a freestyle rule service
○ Pattern matching across different event streams of an organization
○ For BI, there will be arbitrary complex events / patterns analysts want to monitor
● Further study for similar use case: King’s RBEA
○ RBEA: Rule-Based Event Aggregator
○ https://techblog.king.com/rbea-scalable-real-time-analytics-king/
○ http://data-artisans.com/rbea-scalable-real-time-analytics-at-king/
23
Closing
XX Closing
● Complex Event Processing is an emerging way to draw
insights from data streams, and is demanding of the
underlying stream processor for exactly-once semantics for
correctness
● FlinkCEP builds on the DataStreamAPI to make this possible
and easy
24

More Related Content

Recently uploaded

Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
amitlee9823
 
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
amitlee9823
 
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night StandCall Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
gajnagarg
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
only4webmaster01
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
amitlee9823
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
amitlee9823
 

Recently uploaded (20)

Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Aspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraAspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - Almora
 
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men  🔝Ongole🔝   Escorts S...
➥🔝 7737669865 🔝▻ Ongole Call-girls in Women Seeking Men 🔝Ongole🔝 Escorts S...
 
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
 
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night StandCall Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Shivaji Nagar ☎ 7737669865 🥵 Book Your One night Stand
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Complex Event Processing: Use Cases & FlinkCEP Library (Flink.tw Meetup 2016/07/19)

  • 1. Complex Event Processing: Use Cases & FlinkCEP Library Gordon Tai - @tzulitai July 19, 2016 @ Flink.tw Meetup
  • 2. 00 This Talk is About ... ● How FlinkCEP got me interested in Flink ● CEP use cases & applications ○ Use case study #1: tracking an order process ○ Use case study #2: advertisement targeting ● A look at the API 1
  • 3. ● 戴資力(Gordon) ● Data Engineer @ VMFive ● Java, Scala ● Using Flink as an user on VMFive’s Adtech platform ● Enjoy working on distributed computing systems ● Works on Flink during free time ● Contributor: Flink Kinesis Consumer connector 00 Me & Flink 2
  • 4. Tale of a Data Engineer trying to figure out how to build up a streaming analytics pipeline ... 1. First lesson: non-trivial streaming applications are never stateless 2. Second lesson: statefull streaming topologies are a pain 3
  • 5. 1. Exactly-once state updates on failures for correctness 2. Idempotance wrt. external state stores 3. Out-of-order events 4. Aggregating on time windows 5. Rapid application development Applications I was working on: Streaming aggregation for reporting & Conversion patterns for alerting 4
  • 6. TL;DR. It isn’t fun. At all. ● Reference: Building a Stream Processing System for Playable Ads Data at VMFive @ HadoopCon 2015 ● Redis was used as an external state store ● All state update had to be idempotent ● Exactly-once & replay on failover implemented with Storm’s tuple acking mechanism 5
  • 7. ● Generate derived events when a specified pattern on raw events occur in a data stream ○ if A and then B → infer complex event C ● Goal: identify meaningful event patterns and respond to them as quickly as possible ● Demanding on the stream processor to provide robust state handling & out-of-order events support while keeping low latency with high throughput 01 Complex Event Processing 6
  • 8. 02 Apache Flink CEP Library ● Built upon Flink’s DataStream API ● Allows users to define patterns, inject them on event streams, and generates new event streams based on the pattern ● Exploits Flink’s exactly- once semantics for definite correctness 7
  • 9. eCommerce Order Process Tracking Use case study #1 ** Note: the illustrations & content in this section is from Data Artisans’ presentation: Streaming Analytics & CEP - Two Sides of the Same Coin?
  • 10. 03 Order Tracking Data Model ● Order(orderId, tStamp, “received”) extends Event ● Shipment(orderId, tStamp, “shipped”) extends Event ● Delivery(orderId, tStamp, “delivered”) extends Event 8
  • 11. 04 Real-Time Warnings for SLAs ● ProcessSucc(orderId, tStamp, duration) ● ProcessWarn(orderId, tStamp) ● DeliverySucc(orderId, tStamp, duration) ● DeliveryWarn(orderId, tStamp) New inferred events: 9
  • 12. 05 Glimpse at the FlinkCEP API val processingPattern = Pattern .begin[Event]("orderReceived").subtype(classOf[ Order]) .followedBy( "orderShipped").where(_.status == "shipped") .within(Time.hours(1)) val processingPatternStream = CEP.pattern( input.keyBy( "orderId"), processingPattern) val procResult: DataStream[Either[ProcessWarn, ProcessSucc]] = processingPatternStream.select { (pP, timestamp) => // Timeout handler ProcessWarn(pP("orderReceived").orderId, timestamp) } { fP => // Select function ProcessSucc( fP( "orderReceived").orderId, fP( "orderShipped").tStamp, fP( "orderShipped").tStamp – fP( "orderReceived").tStamp) } 10
  • 13. 06 Glimpse at the FlinkCEP API val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment val input: DataStream[Event] = env.addSource(new FlinkKafkaConsumer09(...)) val processingPattern = Pattern.begin(...)... val processingPatternStream = CEP.pattern(input.keyBy( "orderId"), processingPattern) val procResult: DataStream[Either[ProcessWarn, ProcessSucc]] = processingPatternStream.select(...) procResult.addSink(new RedisSink(...)) // .addSink(new FlinkKafkaProducer09(...)) // .addSink(new ElasticsearchSink(...)) // .map(new MapFunction{...}) // … anything you’d like to continue to do with the inferred event stream env.execute() 11
  • 14. 07 Glimpse at the FlinkCEP API val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment env.setStreamTimeCharacteristic( TimeCharacteristic.EventTime) val input: DataStream[Event] = env .addSource(new FlinkKafkaConsumer09(...)) .assignTimestampsAndWatermarks(new CustomExtractor) val processingPattern = Pattern.begin(...)... val processingPatternStream = CEP.pattern(input.keyBy( "orderId"), processingPattern) val procResult: DataStream[Either[ProcessWarn, ProcessSucc]] = processingPatternStream.select(...) procResult.addSink(new RedisSink(...)) // .addSink(new FlinkKafkaProducer09(...)) // .addSink(new ElasticsearchSink(...)) // .map(new MapFunction{...}) env.execute() 12
  • 15. 08 Combining Stream SQL & CEP ● Further reading: Streaming Analytics & CEP - Two Sides of the Same Coin? 13
  • 16. Ad Targeting based on User Attribution Use case study #2 ** Note: the content in this section is heavily based on my experience at VMFive 14
  • 17. 09 Ad Targeting 101 ● What an ad server does, in a nutshell → determine an appropriate advertisement, chosen from an advertisement campaign pool, for each incoming ad request AdServer Campaign Pool (1) request advertisement (2) return appropriate advertisement info from campaign pool ● “appropriate”: fulfill the targeting rules of each campaign 15
  • 18. 10 Ad Targeting Rule Types ● Fundamental campaign targeting rule types: ○ Target users’ current location, ex. users in Taipei ○ Target specific user device type, ex. tablet or phone ○ ... ● Advanced campaign targeting rule types: ○ Target user’s past location trace, ex. in Taipei for the past 7 days ○ Target users entering / departuring countries ○ Target users with specific attribution, ex. viewed ○ ... 16
  • 19. 11 Ad Targeting Rule Types ● Fundamental campaign targeting rule types: ○ Target users’ current location, ex. users in Taipei ○ Target specific user device type, ex. tablet or phone ○ ... ● Advanced campaign targeting rule types: ○ Target user’s past location trace, ex. in Taipei for the past 7 days ○ Target users entering / departuring countries ○ Target users with specific attribution, ex. viewed ○ ... ● Does not require event aggregation ● The rules can be matched simply based on info at request time ● Requires aggregation of historical events ● Aggregating at request time will be far too slow ● Requires inferring complex events from patterns in raw event stream → CEP to the rescue! 16
  • 20. 12 Basic Ad Targeting Architecture Campaign Pool Targeting Cache Ad Targeter register ad campaigns Event Logger WebService AdServerData Warehouse 17 (1) initial connection
  • 21. 12 Basic Ad Targeting Architecture Campaign Pool Targeting Cache Ad Targeter Event Logger WebService AdServerData Warehouse 17 (2) fetch ad
  • 22. 12 Basic Ad Targeting Architecture Ad Targeter Event Logger WebService AdServerData Warehouse Raw Logs Event Bus Service Reporting & analytics services Batch Streaming ... Campaign Pool Targeting Cache 18 (3) event tracking
  • 23. 13 Advanced Ad Targeting Architecture Ad Targeter Event Logger WebService AdServerData Warehouse Raw Logs Event Bus Service Reporting & analytics services Batch Streaming ... RulesServuce Campaign Pool Targeting Cache C E P 19
  • 24. 13 Advanced Ad Targeting Architecture Data Warehouse Raw Logs Event Bus Service Batch Streaming ... RulesService C E P CEP-Rule Templates Rule Fulfillment Cache (Redis) Entry / Depart User Attribution ... (1) Inject a rule to start matching on event stream (3) submit CEP topology (2) Return Rule ID 20
  • 25. 13 Advanced Ad Targeting Architecture Data Warehouse Raw Logs Event Bus Service Batch Streaming ... RulesService C E P CEP-Rule Templates Rule Fulfillment Cache (Redis) Entry / Depart User Attribution ... (4) When CEP pattern is fulfilled, write to cache: UID → RuleID (5) Lookup whether a UID has fulfilled a RuleID 21
  • 26. 13 Advanced Ad Targeting Architecture Ad Targeter register ad campaigns Event Logger WebService AdServerData Warehouse Raw Logs Event Bus Service Reporting & analytics services Batch Streaming ... RulesService Campaign Pool Targeting Cache C E P 22 (1) register rule for campaign (2) lookup whether user fulfils a rule
  • 27. 14 Some Discussion ● Why a fixed pool of CEP-Rule Templates? ○ Prevent rogue rules to match, ex. rules that will consume too much resource ○ It’s a lot less work and complication ;) ● Would be very nice to have a freestyle rule service ○ Pattern matching across different event streams of an organization ○ For BI, there will be arbitrary complex events / patterns analysts want to monitor ● Further study for similar use case: King’s RBEA ○ RBEA: Rule-Based Event Aggregator ○ https://techblog.king.com/rbea-scalable-real-time-analytics-king/ ○ http://data-artisans.com/rbea-scalable-real-time-analytics-at-king/ 23
  • 29. XX Closing ● Complex Event Processing is an emerging way to draw insights from data streams, and is demanding of the underlying stream processor for exactly-once semantics for correctness ● FlinkCEP builds on the DataStreamAPI to make this possible and easy 24