SlideShare a Scribd company logo
1
Streaming SQL
to Unify Batch and Stream Processing:
Theory and Practice with Apache Flink at Uber
Strata Data Conference,
San Jose
March, 7th 2018
Fabian Hueske Shuyi Chen
What is Apache Flink?
2
Batch Processing
process static and
historic data
Data Stream
Processing
realtime results
from data streams
Event-driven
Applications
data-driven actions
and services
Stateful Computations Over Data Streams
What is Apache Flink?
3
Queries
Applications
Devices
etc.
Database
Stream
File / Object
Storage
Stateful computations over streams
real-time and historic
fast, scalable, fault tolerant, in-memory,
event time, large state, exactly-once
Historic
Data
Streams
Application
Hardened at scale
4
Streaming Platform Service
billions messages per day
A lot of Stream SQL
Streaming Platform as a Service
3700+ container running Flink,
1400+ nodes, 22k+ cores, 100s of jobs
Fraud detection
Streaming Analytics Platform
100s jobs, 1000s nodes, TBs state,
metrics, analytics, real time ML,
Streaming SQL as a platform
Powerful Abstractions
5
Process Function (events, state, time)
DataStream API (streams, windows)
SQL / Table API (dynamic tables)
Stream- & Batch
Data Processing
High-level
Analytics API
Stateful Event-
Driven Applications
val stats = stream
.keyBy("sensor")
.timeWindow(Time.seconds(5))
.sum((a, b) -> a.add(b))
def processElement(event: MyEvent, ctx: Context, out: Collector[Result]) = {
// work with event and state
(event, state.value) match { … }
out.collect(…) // emit events
state.update(…) // modify state
// schedule a timer callback
ctx.timerService.registerEventTimeTimer(event.timestamp + 500)
}
Layered abstractions to
navigate simple to complex use cases
Apache Flink’s Relational APIs
Unified APIs for batch & streaming data
A query specifies exactly the same result
regardless whether its input is
static batch data or streaming data.
6
tableEnvironment
.scan("clicks")
.groupBy('user)
.select('user, 'url.count as 'cnt)
SELECT user, COUNT(url) AS cnt
FROM clicks
GROUP BY user
LINQ-style Table APIANSI SQL
Query Translation
7
tableEnvironment
.scan("clicks")
.groupBy('user)
.select('user, 'url.count as 'cnt)
SELECT user, COUNT(url) AS cnt
FROM clicks
GROUP BY user
Input data is
bounded
(batch)
Input data is
unbounded
(streaming)
What if “clicks” is a file?
8
Clicks
user cTime url
Mary 12:00:00 https://…
Bob 12:00:00 https://…
Mary 12:00:02 https://…
Liz 12:00:03 https://…
user cnt
Mary 2
Bob 1
Liz 1
SELECT
user,
COUNT(url) as cnt
FROM clicks
GROUP BY user
Input data is
read at once
Result is produced
at once
What if “clicks” is a stream?
9
user cTime url
user cnt
SELECT
user,
COUNT(url) as cnt
FROM clicks
GROUP BY user
Clicks
Mary 12:00:00 https://…
Bob 12:00:00 https://…
Mary 12:00:02 https://…
Liz 12:00:03 https://…
Bob 1
Liz 1
Mary 1Mary 2
Input data is
continuously read
Result is continuously
produced
The result is identical!
Why is stream-batch unification important?
 Usability
• ANSI SQL syntax: No custom “StreamSQL” syntax.
• ANSI SQL semantics: No stream-specific results.
 Portability
• Run the same query on bounded and unbounded data
• Run the same query on recorded and real-time data
 Do we need to soften SQL semantics for streaming? 10
now
bounded query
unbounded query
past future
bounded query
start of the stream
unbounded query
DBMSs Run Queries on Streams
 Materialized views (MV) are similar to regular views,
but persisted to disk or memory
• Used to speed-up analytical queries
• MVs need to be updated when the base tables change
 MV maintenance is very similar to SQL on streams
• Base table updates are a stream of DML statements
• MV definition query is evaluated on that stream
• MV is query result and continuously updated
11
Continuous Queries in Flink
 Core concept is a “Dynamic Table”
• Dynamic tables are changing over time
 Queries on dynamic tables
• produce new dynamic tables (which are updated based on input)
• do not terminate
 Stream ↔ Dynamic table conversions
12
Stream ↔ Dynamic Table Conversions
 Append Conversions
• Records are only inserted/appended
 Upsert Conversions
• Records are inserted/updated/deleted and have a
(composite) unique key
 Changelog Conversions
• Records are inserted/updated/deleted
13
SQL Feature Set in Flink 1.5.0
 SELECT FROM WHERE
 GROUP BY / HAVING
• Non-windowed, TUMBLE, HOP, SESSION windows
 JOIN
• Windowed INNER, LEFT / RIGHT / FULL OUTER JOIN
• Non-windowed INNER JOIN
 Scalar, aggregation, table-valued UDFs
 SQL CLI Client (beta)
 [streaming only] OVER / WINDOW
• UNBOUNDED / BOUNDED PRECEDING
 [batch only] UNION / INTERSECT / EXCEPT / IN / ORDER BY
14
What can I build with this?
 Data Pipelines
• Transform, aggregate, and move events in real-time
 Low-latency ETL
• Convert and write streams to file systems, DBMS, K-V stores, indexes, …
• Convert appearing files into streams
 Stream & Batch Analytics
• Run analytical queries over bounded and unbounded data
• Query and compare historic and real-time data
 Data Preparation for Live Dashboards
• Compute and update data to visualize in real-time 15
The New York Taxi Rides Data Set
 The New York City Taxi & Limousine Commission provides a public data
set about taxi rides in New York City
 We can derive a streaming table from the data
 Table: TaxiRides
rideId: BIGINT // ID of the taxi ride
isStart: BOOLEAN // flag for pick-up (true) or drop-off (false) event
lon: DOUBLE // longitude of pick-up or drop-off location
lat: DOUBLE // latitude of pick-up or drop-off location
rowtime: TIMESTAMP // time of pick-up or drop-off event
16
Identify popular pick-up / drop-off locations
SELECT cell,
isStart,
HOP_END(rowtime, INTERVAL '5' MINUTE, INTERVAL '15' MINUTE) AS hopEnd,
COUNT(*) AS cnt
FROM (SELECT rowtime, isStart, toCellId(lon, lat) AS cell
FROM TaxiRides
WHERE isInNYC(lon, lat))
GROUP BY cell,
isStart,
HOP(rowtime, INTERVAL '5' MINUTE, INTERVAL '15' MINUTE) 17
 Compute every 5 minutes for each location the
number of departing and arriving taxis
of the last 15 minutes.
Average ride duration per pick-up location
SELECT pickUpCell,
AVG(TIMESTAMPDIFF(MINUTE, e.rowtime, s.rowtime) AS avgDuration
FROM (SELECT rideId, rowtime, toCellId(lon, lat) AS pickUpCell
FROM TaxiRides
WHERE isStart) s
JOIN
(SELECT rideId, rowtime
FROM TaxiRides
WHERE NOT isStart) e
ON s.rideId = e.rideId AND
e.rowtime BETWEEN s.rowtime AND s.rowtime + INTERVAL '1' HOUR
GROUP BY pickUpCell
18
 Join start ride and end ride events on rideId and
compute average ride duration per pick-up location.
Building a Dashboard
19
Elastic
Search
Kafka
SELECT cell,
isStart,
HOP_END(rowtime, INTERVAL '5' MINUTE, INTERVAL '15' MINUTE) AS hopEnd,
COUNT(*) AS cnt
FROM (SELECT rowtime, isStart, toCellId(lon, lat) AS cell
FROM TaxiRides
WHERE isInNYC(lon, lat))
GROUP BY cell,
isStart,
HOP(rowtime, INTERVAL '5' MINUTE, INTERVAL '15' MINUTE)
Flink SQL in Production @
UBER
20
Uber's business is Real-Time
21
Uber
Challenges
Infrastructure
 100s of Billions of
messages / day
 At-least-once
processing
 Exactly-once state
processing
 99.99% SLA on
availability
 99.99% SLA on
latency
Productivity
 Target audience
 Operation people
 Data scientists
 Engineers
 Integrations
 Logging
 Backend services
 Storage systems
 Data management
 Monitoring
22
Operation
 ~1000 streaming
jobs
 Multiple DCs
Stream processing @ Uber
 Apache Samza (Since Jul. 2015)
• Scalable
• At-least-once message processing
• Managed state
• Fault tolerance
 Apache Flink (Since May, 2017)
• All of above
• Exactly-once stateful computation
• Accurate
• Unified stream & batch processing with SQL
23
24
Lifecycle of building a streaming job
Writing the job
25
Business
Logics
Input
Output
Testing Debugging
• Java/Scala
• Streaming/batch
• Duplicate code
Running the job
26
Resource
estimation
Deployment
Monitoring
& Alerts
Logging Maintenance
• Manual process
• Hard to scale beyond > 10 jobs
27
Job from idea to production takes days
28
How can we improve efficiency as a platform?
Flink SQL to be savior
29
SELECT AVG(…) FROM eats_order
WHERE …
Connectors
30
HTTP
SELECT AVG(…) FROM eats_order
WHERE …
Pinot
UI & Backend services
 To make it self-service
• SQL composition & validation
• Connectors management
31
UI & Backend services
 To make it self-service
• Job compilation and generation
• Resource estimation
32
Analyze input Analyze query
Test
deployment
Kafka input rate
Hive metastore data SELECT * FROM ...
YARN containers
CPU
Heap memory
UI & Backend services
 To make it self-service
• Job deployment
33
Sandbox
• Functional correctness
• Play around with SQL
Staging
• System generated estimate
• Production like load
Production
• Managed
Promote
UI & Backend services
34
 To make it self-service
• Job management
UI & Backend services
 To support Uber scale
• Monitoring and alert automation
• Auto-scaling
• Job recovery
• DC failover
35
Watchdog
AthenaX
 Uber's Self-service stream and batch
processing platform
• SQL
• Connectors
• UI & backend services
36
37
Business use cases
Real-time Machine Learning - UberEats ETD
38
SELECT restaurant_id,
AVG(etd) AS avg_etd
FROM restaurant_stream
GROUP BY TUMBLE(proctime, INTERVAL '5' MINUTE),
restaurant_id
Powering Restaurant Manager
39
Better Data -> Better
Food -> Better
Business = A Winning
Recipe
Eats restaurant
manager blog
AthenaX wins
 SQL abstraction with Flink
• Non-engineers to use stream processing
 E2E Self service
 Job from idea to production take minutes/hours
 Centralized place to track streaming dataflows
 Minimal human intervention, and scale
operationally to ~ 1000 jobs in production
40
AthenaX Open Source
 Uber engineering blog
 Open source repository
41
15% discount code: StrataFlink
Flink Forward SF 2018 Presenters
43
Thank you!
@fhueske
@ApacheFlink
Available on O’Reilly Early Release!

More Related Content

PPTX
Why and how to leverage the power and simplicity of SQL on Apache Flink
PPTX
Stream Analytics with SQL on Apache Flink
PPTX
Flink's Journey from Academia to the ASF
PDF
Flink Forward San Francisco 2018: Stefan Richter - "How to build a modern str...
PPTX
Stream Analytics with SQL on Apache Flink
PPTX
Flink Forward Berlin 2017: Till Rohrmann - From Apache Flink 1.3 to 1.4
PPTX
Apache Flink Meetup Munich (November 2015): Flink Overview, Architecture, Int...
PPTX
Webinar: Flink SQL in Action - Fabian Hueske
Why and how to leverage the power and simplicity of SQL on Apache Flink
Stream Analytics with SQL on Apache Flink
Flink's Journey from Academia to the ASF
Flink Forward San Francisco 2018: Stefan Richter - "How to build a modern str...
Stream Analytics with SQL on Apache Flink
Flink Forward Berlin 2017: Till Rohrmann - From Apache Flink 1.3 to 1.4
Apache Flink Meetup Munich (November 2015): Flink Overview, Architecture, Int...
Webinar: Flink SQL in Action - Fabian Hueske

What's hot (20)

PDF
Flink Forward San Francisco 2018: Ken Krugler - "Building a scalable focused ...
PPTX
Flink Forward Berlin 2017: Hao Wu - Large Scale User Behavior Analytics by Flink
PPTX
data Artisans Product Announcement
PPTX
January 2016 Flink Community Update & Roadmap 2016
PPTX
Introduction to KSQL: Streaming SQL for Apache Kafka®
PPTX
Flink Community Update December 2015: Year in Review
PPTX
Flink Forward Berlin 2017: Fabian Hueske - Using Stream and Batch Processing ...
PPTX
From Apache Flink® 1.3 to 1.4
PDF
Unlocking the world of stream processing with KSQL, the streaming SQL engine ...
PDF
Dynamic Scaling: How Apache Flink Adapts to Changing Workloads (at FlinkForwa...
PDF
Apache Flink @ Tel Aviv / Herzliya Meetup
PPTX
Apache Flink Berlin Meetup May 2016
PPTX
GOTO Night Amsterdam - Stream processing with Apache Flink
PPTX
Fabian Hueske - Stream Analytics with SQL on Apache Flink
PDF
Big, Fast, Easy Data: Distributed Stream Processing for Everyone with KSQL, t...
PDF
Scaling stream data pipelines with Pravega and Apache Flink
PPTX
Taking a look under the hood of Apache Flink's relational APIs.
PPTX
Flink Streaming @BudapestData
PDF
Apache Flink's Table & SQL API - unified APIs for batch and stream processing
PPTX
Flink Forward Berlin 2017: Patrick Gunia - Migration of a realtime stats prod...
Flink Forward San Francisco 2018: Ken Krugler - "Building a scalable focused ...
Flink Forward Berlin 2017: Hao Wu - Large Scale User Behavior Analytics by Flink
data Artisans Product Announcement
January 2016 Flink Community Update & Roadmap 2016
Introduction to KSQL: Streaming SQL for Apache Kafka®
Flink Community Update December 2015: Year in Review
Flink Forward Berlin 2017: Fabian Hueske - Using Stream and Batch Processing ...
From Apache Flink® 1.3 to 1.4
Unlocking the world of stream processing with KSQL, the streaming SQL engine ...
Dynamic Scaling: How Apache Flink Adapts to Changing Workloads (at FlinkForwa...
Apache Flink @ Tel Aviv / Herzliya Meetup
Apache Flink Berlin Meetup May 2016
GOTO Night Amsterdam - Stream processing with Apache Flink
Fabian Hueske - Stream Analytics with SQL on Apache Flink
Big, Fast, Easy Data: Distributed Stream Processing for Everyone with KSQL, t...
Scaling stream data pipelines with Pravega and Apache Flink
Taking a look under the hood of Apache Flink's relational APIs.
Flink Streaming @BudapestData
Apache Flink's Table & SQL API - unified APIs for batch and stream processing
Flink Forward Berlin 2017: Patrick Gunia - Migration of a realtime stats prod...
Ad

Similar to Streaming SQL to unify batch and stream processing: Theory and practice with Apache Flink at Uber (20)

PPTX
Why and how to leverage the simplicity and power of SQL on Flink
PPTX
Flink Forward San Francisco 2018: Fabian Hueske & Timo Walther - "Why and how...
PDF
Apache Flink - a Gentle Start
PPTX
Flink Forward Berlin 2018: Timo Walther - "Flink SQL in Action"
PDF
Couchbase@live person meetup july 22nd
PPTX
Flink SQL in Action
PPTX
Data Stream Processing with Apache Flink
PPTX
Azure Stream Analytics : Analyse Data in Motion
PDF
Confluent Workshop Series: ksqlDB로 스트리밍 앱 빌드
PDF
XStream: stream processing platform at facebook
PPTX
Flexible and Real-Time Stream Processing with Apache Flink
PDF
Now You See Me, Now You Compute: Building Event-Driven Architectures with Apa...
PPTX
Flink Forward San Francisco 2018: - Jinkui Shi and Radu Tudoran "Flink real-t...
PPTX
Apache Flink at Strata San Jose 2016
PDF
The Art of The Event Streaming Application: Streams, Stream Processors and Sc...
PPTX
Kakfa summit london 2019 - the art of the event-streaming app
PDF
Big Data Analytics Platforms by KTH and RISE SICS
PDF
[WSO2Con EU 2018] The Rise of Streaming SQL
PPTX
Advanced Stream Processing with Flink and Pulsar - Pulsar Summit NA 2021 Keynote
PDF
The art of the event streaming application: streams, stream processors and sc...
Why and how to leverage the simplicity and power of SQL on Flink
Flink Forward San Francisco 2018: Fabian Hueske & Timo Walther - "Why and how...
Apache Flink - a Gentle Start
Flink Forward Berlin 2018: Timo Walther - "Flink SQL in Action"
Couchbase@live person meetup july 22nd
Flink SQL in Action
Data Stream Processing with Apache Flink
Azure Stream Analytics : Analyse Data in Motion
Confluent Workshop Series: ksqlDB로 스트리밍 앱 빌드
XStream: stream processing platform at facebook
Flexible and Real-Time Stream Processing with Apache Flink
Now You See Me, Now You Compute: Building Event-Driven Architectures with Apa...
Flink Forward San Francisco 2018: - Jinkui Shi and Radu Tudoran "Flink real-t...
Apache Flink at Strata San Jose 2016
The Art of The Event Streaming Application: Streams, Stream Processors and Sc...
Kakfa summit london 2019 - the art of the event-streaming app
Big Data Analytics Platforms by KTH and RISE SICS
[WSO2Con EU 2018] The Rise of Streaming SQL
Advanced Stream Processing with Flink and Pulsar - Pulsar Summit NA 2021 Keynote
The art of the event streaming application: streams, stream processors and sc...
Ad

More from Fabian Hueske (6)

PPTX
Juggling with Bits and Bytes - How Apache Flink operates on binary data
PPTX
ApacheCon: Apache Flink - Fast and Reliable Large-Scale Data Processing
PPTX
Apache Flink - Hadoop MapReduce Compatibility
PPTX
Apache Flink - A Sneek Preview on Language Integrated Queries
PPTX
Apache Flink - Akka for the Win!
PPTX
Apache Flink - Community Update January 2015
Juggling with Bits and Bytes - How Apache Flink operates on binary data
ApacheCon: Apache Flink - Fast and Reliable Large-Scale Data Processing
Apache Flink - Hadoop MapReduce Compatibility
Apache Flink - A Sneek Preview on Language Integrated Queries
Apache Flink - Akka for the Win!
Apache Flink - Community Update January 2015

Recently uploaded (20)

PDF
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
PPT
Quality review (1)_presentation of this 21
PPTX
IB Computer Science - Internal Assessment.pptx
PPTX
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
PDF
Data Science Trends & Career Guide---ppt
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PPTX
Introduction to Knowledge Engineering Part 1
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PPTX
Measurement of Afordability for Water Supply and Sanitation in Bangladesh .pptx
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPTX
climate analysis of Dhaka ,Banglades.pptx
PDF
Data Analyst Certificate Programs for Beginners | IABAC
PDF
Foundation of Data Science unit number two notes
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PPTX
Moving the Public Sector (Government) to a Digital Adoption
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PPTX
Understanding Prototyping in Design and Development
PPTX
Major-Components-ofNKJNNKNKNKNKronment.pptx
PDF
.pdf is not working space design for the following data for the following dat...
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
Quality review (1)_presentation of this 21
IB Computer Science - Internal Assessment.pptx
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
Data Science Trends & Career Guide---ppt
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
Introduction to Knowledge Engineering Part 1
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
Measurement of Afordability for Water Supply and Sanitation in Bangladesh .pptx
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
climate analysis of Dhaka ,Banglades.pptx
Data Analyst Certificate Programs for Beginners | IABAC
Foundation of Data Science unit number two notes
STUDY DESIGN details- Lt Col Maksud (21).pptx
Moving the Public Sector (Government) to a Digital Adoption
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
Understanding Prototyping in Design and Development
Major-Components-ofNKJNNKNKNKNKronment.pptx
.pdf is not working space design for the following data for the following dat...

Streaming SQL to unify batch and stream processing: Theory and practice with Apache Flink at Uber

  • 1. 1 Streaming SQL to Unify Batch and Stream Processing: Theory and Practice with Apache Flink at Uber Strata Data Conference, San Jose March, 7th 2018 Fabian Hueske Shuyi Chen
  • 2. What is Apache Flink? 2 Batch Processing process static and historic data Data Stream Processing realtime results from data streams Event-driven Applications data-driven actions and services Stateful Computations Over Data Streams
  • 3. What is Apache Flink? 3 Queries Applications Devices etc. Database Stream File / Object Storage Stateful computations over streams real-time and historic fast, scalable, fault tolerant, in-memory, event time, large state, exactly-once Historic Data Streams Application
  • 4. Hardened at scale 4 Streaming Platform Service billions messages per day A lot of Stream SQL Streaming Platform as a Service 3700+ container running Flink, 1400+ nodes, 22k+ cores, 100s of jobs Fraud detection Streaming Analytics Platform 100s jobs, 1000s nodes, TBs state, metrics, analytics, real time ML, Streaming SQL as a platform
  • 5. Powerful Abstractions 5 Process Function (events, state, time) DataStream API (streams, windows) SQL / Table API (dynamic tables) Stream- & Batch Data Processing High-level Analytics API Stateful Event- Driven Applications val stats = stream .keyBy("sensor") .timeWindow(Time.seconds(5)) .sum((a, b) -> a.add(b)) def processElement(event: MyEvent, ctx: Context, out: Collector[Result]) = { // work with event and state (event, state.value) match { … } out.collect(…) // emit events state.update(…) // modify state // schedule a timer callback ctx.timerService.registerEventTimeTimer(event.timestamp + 500) } Layered abstractions to navigate simple to complex use cases
  • 6. Apache Flink’s Relational APIs Unified APIs for batch & streaming data A query specifies exactly the same result regardless whether its input is static batch data or streaming data. 6 tableEnvironment .scan("clicks") .groupBy('user) .select('user, 'url.count as 'cnt) SELECT user, COUNT(url) AS cnt FROM clicks GROUP BY user LINQ-style Table APIANSI SQL
  • 7. Query Translation 7 tableEnvironment .scan("clicks") .groupBy('user) .select('user, 'url.count as 'cnt) SELECT user, COUNT(url) AS cnt FROM clicks GROUP BY user Input data is bounded (batch) Input data is unbounded (streaming)
  • 8. What if “clicks” is a file? 8 Clicks user cTime url Mary 12:00:00 https://… Bob 12:00:00 https://… Mary 12:00:02 https://… Liz 12:00:03 https://… user cnt Mary 2 Bob 1 Liz 1 SELECT user, COUNT(url) as cnt FROM clicks GROUP BY user Input data is read at once Result is produced at once
  • 9. What if “clicks” is a stream? 9 user cTime url user cnt SELECT user, COUNT(url) as cnt FROM clicks GROUP BY user Clicks Mary 12:00:00 https://… Bob 12:00:00 https://… Mary 12:00:02 https://… Liz 12:00:03 https://… Bob 1 Liz 1 Mary 1Mary 2 Input data is continuously read Result is continuously produced The result is identical!
  • 10. Why is stream-batch unification important?  Usability • ANSI SQL syntax: No custom “StreamSQL” syntax. • ANSI SQL semantics: No stream-specific results.  Portability • Run the same query on bounded and unbounded data • Run the same query on recorded and real-time data  Do we need to soften SQL semantics for streaming? 10 now bounded query unbounded query past future bounded query start of the stream unbounded query
  • 11. DBMSs Run Queries on Streams  Materialized views (MV) are similar to regular views, but persisted to disk or memory • Used to speed-up analytical queries • MVs need to be updated when the base tables change  MV maintenance is very similar to SQL on streams • Base table updates are a stream of DML statements • MV definition query is evaluated on that stream • MV is query result and continuously updated 11
  • 12. Continuous Queries in Flink  Core concept is a “Dynamic Table” • Dynamic tables are changing over time  Queries on dynamic tables • produce new dynamic tables (which are updated based on input) • do not terminate  Stream ↔ Dynamic table conversions 12
  • 13. Stream ↔ Dynamic Table Conversions  Append Conversions • Records are only inserted/appended  Upsert Conversions • Records are inserted/updated/deleted and have a (composite) unique key  Changelog Conversions • Records are inserted/updated/deleted 13
  • 14. SQL Feature Set in Flink 1.5.0  SELECT FROM WHERE  GROUP BY / HAVING • Non-windowed, TUMBLE, HOP, SESSION windows  JOIN • Windowed INNER, LEFT / RIGHT / FULL OUTER JOIN • Non-windowed INNER JOIN  Scalar, aggregation, table-valued UDFs  SQL CLI Client (beta)  [streaming only] OVER / WINDOW • UNBOUNDED / BOUNDED PRECEDING  [batch only] UNION / INTERSECT / EXCEPT / IN / ORDER BY 14
  • 15. What can I build with this?  Data Pipelines • Transform, aggregate, and move events in real-time  Low-latency ETL • Convert and write streams to file systems, DBMS, K-V stores, indexes, … • Convert appearing files into streams  Stream & Batch Analytics • Run analytical queries over bounded and unbounded data • Query and compare historic and real-time data  Data Preparation for Live Dashboards • Compute and update data to visualize in real-time 15
  • 16. The New York Taxi Rides Data Set  The New York City Taxi & Limousine Commission provides a public data set about taxi rides in New York City  We can derive a streaming table from the data  Table: TaxiRides rideId: BIGINT // ID of the taxi ride isStart: BOOLEAN // flag for pick-up (true) or drop-off (false) event lon: DOUBLE // longitude of pick-up or drop-off location lat: DOUBLE // latitude of pick-up or drop-off location rowtime: TIMESTAMP // time of pick-up or drop-off event 16
  • 17. Identify popular pick-up / drop-off locations SELECT cell, isStart, HOP_END(rowtime, INTERVAL '5' MINUTE, INTERVAL '15' MINUTE) AS hopEnd, COUNT(*) AS cnt FROM (SELECT rowtime, isStart, toCellId(lon, lat) AS cell FROM TaxiRides WHERE isInNYC(lon, lat)) GROUP BY cell, isStart, HOP(rowtime, INTERVAL '5' MINUTE, INTERVAL '15' MINUTE) 17  Compute every 5 minutes for each location the number of departing and arriving taxis of the last 15 minutes.
  • 18. Average ride duration per pick-up location SELECT pickUpCell, AVG(TIMESTAMPDIFF(MINUTE, e.rowtime, s.rowtime) AS avgDuration FROM (SELECT rideId, rowtime, toCellId(lon, lat) AS pickUpCell FROM TaxiRides WHERE isStart) s JOIN (SELECT rideId, rowtime FROM TaxiRides WHERE NOT isStart) e ON s.rideId = e.rideId AND e.rowtime BETWEEN s.rowtime AND s.rowtime + INTERVAL '1' HOUR GROUP BY pickUpCell 18  Join start ride and end ride events on rideId and compute average ride duration per pick-up location.
  • 19. Building a Dashboard 19 Elastic Search Kafka SELECT cell, isStart, HOP_END(rowtime, INTERVAL '5' MINUTE, INTERVAL '15' MINUTE) AS hopEnd, COUNT(*) AS cnt FROM (SELECT rowtime, isStart, toCellId(lon, lat) AS cell FROM TaxiRides WHERE isInNYC(lon, lat)) GROUP BY cell, isStart, HOP(rowtime, INTERVAL '5' MINUTE, INTERVAL '15' MINUTE)
  • 20. Flink SQL in Production @ UBER 20
  • 21. Uber's business is Real-Time 21 Uber
  • 22. Challenges Infrastructure  100s of Billions of messages / day  At-least-once processing  Exactly-once state processing  99.99% SLA on availability  99.99% SLA on latency Productivity  Target audience  Operation people  Data scientists  Engineers  Integrations  Logging  Backend services  Storage systems  Data management  Monitoring 22 Operation  ~1000 streaming jobs  Multiple DCs
  • 23. Stream processing @ Uber  Apache Samza (Since Jul. 2015) • Scalable • At-least-once message processing • Managed state • Fault tolerance  Apache Flink (Since May, 2017) • All of above • Exactly-once stateful computation • Accurate • Unified stream & batch processing with SQL 23
  • 24. 24 Lifecycle of building a streaming job
  • 25. Writing the job 25 Business Logics Input Output Testing Debugging • Java/Scala • Streaming/batch • Duplicate code
  • 26. Running the job 26 Resource estimation Deployment Monitoring & Alerts Logging Maintenance • Manual process • Hard to scale beyond > 10 jobs
  • 27. 27 Job from idea to production takes days
  • 28. 28 How can we improve efficiency as a platform?
  • 29. Flink SQL to be savior 29 SELECT AVG(…) FROM eats_order WHERE …
  • 30. Connectors 30 HTTP SELECT AVG(…) FROM eats_order WHERE … Pinot
  • 31. UI & Backend services  To make it self-service • SQL composition & validation • Connectors management 31
  • 32. UI & Backend services  To make it self-service • Job compilation and generation • Resource estimation 32 Analyze input Analyze query Test deployment Kafka input rate Hive metastore data SELECT * FROM ... YARN containers CPU Heap memory
  • 33. UI & Backend services  To make it self-service • Job deployment 33 Sandbox • Functional correctness • Play around with SQL Staging • System generated estimate • Production like load Production • Managed Promote
  • 34. UI & Backend services 34  To make it self-service • Job management
  • 35. UI & Backend services  To support Uber scale • Monitoring and alert automation • Auto-scaling • Job recovery • DC failover 35 Watchdog
  • 36. AthenaX  Uber's Self-service stream and batch processing platform • SQL • Connectors • UI & backend services 36
  • 38. Real-time Machine Learning - UberEats ETD 38 SELECT restaurant_id, AVG(etd) AS avg_etd FROM restaurant_stream GROUP BY TUMBLE(proctime, INTERVAL '5' MINUTE), restaurant_id
  • 39. Powering Restaurant Manager 39 Better Data -> Better Food -> Better Business = A Winning Recipe Eats restaurant manager blog
  • 40. AthenaX wins  SQL abstraction with Flink • Non-engineers to use stream processing  E2E Self service  Job from idea to production take minutes/hours  Centralized place to track streaming dataflows  Minimal human intervention, and scale operationally to ~ 1000 jobs in production 40
  • 41. AthenaX Open Source  Uber engineering blog  Open source repository 41
  • 42. 15% discount code: StrataFlink
  • 43. Flink Forward SF 2018 Presenters 43