Advanced Big Data: Real-Time Data Processing
Dan Zaratsian
AI/ML Solutions Architect, Gaming @ Google
d.zaratsian@gmail.com
https://github.com/zaratsian
TOPICS
Next up...
Session 2
SQL & NoSQL
Session 3
Distributed ML
Session 4
Cloud ML
Session 5
Real-time Systems
Session 6
Cloud
SQL
ML
GCP PubSub
Serverless
Vertex AI
Events
(Data In)
Events
(Data Out)
In-Stream
Data Processing
Re-route to
Dashboard / 3rd Party Systems
Alerts
4
Page 4
© Hortonworks Inc. 2015
Events
(Data In)
Events
(Data Out)
Filtering
Aggregation
Pattern Detection
Computation
Merging / Joins
Retention Window
Text Analytics
Clustering
Machine Learning
…more…
Detect Events & Patterns of Interest
5
Page 5
© Hortonworks Inc. 2015
Streaming Analytics Ecosystem
Edge
Analytics
In-Motion
Analytics
At-Rest
Analytics
Connected Systems, Devices
Monitor equipment on
for failures and safety
issues, and take action.
Identify fraudulent
transactions and be
alerted in real-time.
Intelligently integrate customer
information with real-time
streaming data
Strategic Data Integration
Transactions, Logs, Clickstreams
6
Page 6
© Hortonworks Inc. 2015
Streaming Analytics: Types
7
Page 7
© Hortonworks Inc. 2015
Where are the Opportunities?
* In many applications, the value of data has a shelf life
8
Page 8
© Hortonworks Inc. 2015
Batch Analytics
Get Data
Database
Historical Analysis
Adapters
FTP
APIs
Apache NiFi
Reports & Dashboards
Hive
BigQuery
Hbase
Cassandra
MongoDB
9
Page 9
© Hortonworks Inc. 2015
Streaming Analytics – Process Flow
Get Data
Database
Historical Analysis
Adapters
FTP
APIs
Apache NiFi
Reports & Dashboards
Real-time Analytics
Alerts
Storm
Spark
Beam
Flink
SAS ESP
Hive
BigQuery
Hbase
Cassandra
MongoDB
10
Page 10
© Hortonworks Inc. 2015
Streaming Analytics – Process Flow
Get Data
Database
Historical Analysis
Adapters
FTP
APIs
Apache NiFi
Reports & Dashboards
Real-time Analytics
Alerts
Bus
Kafka
RabbitMQ
PubSub
Kinesis
Storm
Spark
Beam
Flink
SAS ESP
Hive
BigQuery
Hbase
Cassandra
MongoDB
11
Page 11
© Hortonworks Inc. 2015
Streaming Analytics – Process Flow
Get Data
Database
Historical Analysis
Adapters
FTP
APIs
Apache NiFi
Reports & Dashboards
Real-time Analytics
Alerts
Bus
Bus
Kafka
RabbitMQ
PubSub
Kinesis
Storm
Spark
Beam
Flink
SAS ESP
Hive
BigQuery
Hbase
Cassandra
MongoDB
12
Page 12
© Hortonworks Inc. 2015
Streaming Analytics – Process Flow
Get Data
Bus
Real-time Analytics
Bus
Database
Historical Analysis
Adapters
FTP
APIs
Apache NiFi
Reports & Dashboards
3rd Party Service
Alerts
Internal Service (trigger offer)
Storm
Spark
Beam
Flink
SAS ESP
Kafka
RabbitMQ
PubSub
Kinesis
Hive
BigQuery
Hbase
Cassandra
MongoDB
13
Page 13
© Hortonworks Inc. 2015
Developed in the NSA (code name NiagaraFiles)
Open-sourced in 2014 (NSA team left and started Onyara, which was acquired by Hortonworks).
Control, automate, and audit the bi-directional flow of data between software systems.
Confidential & Proprietary
Confidential & Proprietary
Kafka
Developed by Linkedin
“Apache Kafka is used for building real-time data pipelines and streaming apps. It is horizontally scalable, fault-tolerant, wicked fast...” -- https://kafka.apache.org/
Up to 2 million writes/sec on 3 cheap machines (in 2014)
https://engineering.linkedin.com/kafka/benchmarking-apache-kafka-2-million-writes-second-three-cheap-machines
Confidential & Proprietary
Confidential & Proprietary
Kafka decouples Data Pipelines
Apache Kafka - Distributed Streaming Platform
Source System
Source System
Source System
Source System
Hadoop
Security Systems
Real-time monitoring
Data Warehouse
Kafka
Producers
Brokers
Consumers
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Proprietary + Confidential
Kafka Topic - Category or feed name to which records are published.
Topics in Kafka are always multi-subscriber; that is, a topic can have zero, one, or many consumers that subscribe to the data written to it.
Producer (Publisher) - Publishes data to a topic
Consumer (Subscriber) - Receives data from a Topic either through pull or push methods.
Confidential & Proprietary
Options for Stream Analytics on GCP
Edge
Activate
Analyze
Process
Collect
Web
IoT
Mobile
Data Store
Trigger
Pub/Sub
Dataflow
BigQuery
OR
Managed Services
Options for Integration or Hosting
Data Studio
(Managed)
(Managed)
3rd
Party BI
Other Cloud Pipelines
Other Cloud Warehouse
(Managed)
(Managed)
Bigtable
Kafka helps companies achieve their real-time goals
67%
of the Fortune 500 uses Kafka
Kafka is in Production at 200,000+ Companies
PubSub
Without Pub/Sub, computer systems must be online at the same time to get anything done. If one is unavailable, there is no business. It’s the world of telephones.
Pub/Sub is like email for machines
With Pub/Sub, similar to email, no one has to be online at the same time. Pub/Sub delivers messages instantly if everyone is online and safely holds them until they can be delivered otherwise.
Without Pub/Sub
With Pub/Sub
Confidential & Proprietary
How does Pub/Sub simplify systems?
Pub/Sub
Confidential & Proprietary
High-Level Architecture - PubSub as the Central Service
Confidential & Proprietary
PubSub Architecture - Flow of Events
Confidential & Proprietary
Spark Streaming
Spark Streaming
Spark Streaming is an extension of the core Spark API that enables scalable, high-throughput, fault-tolerant stream processing of live data streams.
Structured Streaming
Structured Streaming is a scalable and fault-tolerant stream processing engine built on the Spark SQL engine.
Confidential & Proprietary
Spark Streaming Architecture
Confidential & Proprietary
Structured Streaming Architecture
Confidential & Proprietary
Confidential & Proprietary
Structured Streaming Concepts
Confidential & Proprietary
Apache Beam
Same code deploys to Batch and Real-time
Apache Beam
(Google Dataflow)
Example architecture for data analytics
Tableau
QlikView
Apache Beam: Data Processing SDK
Multiple Modes
Multiple SDKs
Multiple Runners
Batch
Streaming
Java
Python
Direct: local for testing
Apache Apex: local, on-premise, cloud
Apache Flink: local, on-premise, cloud
Apache Spark: local, on-premise, cloud
Cloud Dataflow: fully managed service on Google Cloud
One Model
Apache Beam Terminology
Pipeline Contains all of the data and steps in your data processing task
PCollection Data, it is a distributed, multi-element data set
Transforms The operations in your pipeline to process data
Windowing Divides a PCollection based on the timestamps of event(s)
Triggers Determines when to emit the aggregated results of each window
Runner The software that accepts a pipeline and executes it
Watermarks The system's notion for when all data has arrived in a window
Apache Beam Terminology
Pipeline Contains all of the data and steps in your data processing task
PCollection Data, it is a distributed, multi-element data set
Transforms The operations in your pipeline to process data
Windowing Divides a PCollection based on the timestamps of event(s)
Triggers Determines when to emit the aggregated results of each window
Runner The software that accepts a pipeline and executes it
Watermarks The system's notion for when all data has arrived in a window
Types of Transforms:
Apache Beam Pipelines
{a->[apple, art, argentina], ar->[art, argentina, armenia],...}
Count
ExpandPrefixes
Top(3)
Write
Read
ExtractTags
{a->(argentina, 5M), a->(armenia, 2M), …, ar->(argentina, 5M), ar->(armenia, 2M), ...}
{#argentina scores!, watching #armenia vs #argentina, my #art project, …}
{argentina, armenia, argentina, art, ...}
{argentina->5M, armenia->2M, art->90M, ...}
Tweets
Predictions
Auto-Complete Example
Count
ExpandPrefixes
Top(3)
Write
Read
ExtractTags
Tweets
Predictions
Pipeline p = Pipeline.create();
p.begin()
p.run();
.apply(ParDo.of(new ExtractTags()))
.apply(Top.largestPerKey(3))
.apply(Count.create())
.apply(ParDo.of(new ExpandPrefixes())
.apply(TextIO.Write.to(“gs://…”));
.apply(TextIO.Read.from(“gs://…”))
Apache Beam Windowing
Fixed
Sliding
1
2
3
5
4
Sessions
2
4
3
1
Key 2
Key 1
Key 3
1
2
3
4
Windowing divides data into time-based finite chunks
Often required when doing aggregations over unbounded data
Apache Beam Windowing
Fixed-time windows
from apache_beam import window
fixed_windowed_items = (
items | 'window' >> beam.WindowInto(window.FixedWindows(60)))
Python
Sliding time windows
from apache_beam import window
sliding_windowed_items = (
items | 'window' >> beam.WindowInto(window.SlidingWindows(30, 5)))
Python
Session windows
from apache_beam import window
session_windowed_items = (
items | 'window' >> beam.WindowInto(window.Sessions(10 * 60)))
Python
Google Cloud Dataflow 101
Google Cloud Dataflow
Dataflow is a fully managed streaming analytics service that minimizes latency, processing time, and cost through autoscaling and batch processing.
Serverless
Unified Batch & Stream Processing
Open Source - Apache Beam
Windowing, Exactly-once processing, SDKs
Google Cloud Dataflow - Service Architecture
Bounded
Compute and Storage
Unbounded
Resource Management
Resource Auto-scaler
Dynamic Work Rebalancer
Work Scheduler
Monitoring
Log Collection
Graph Optimization
Auto-Healing
Intelligent Watermarking
SOURCE
SINK
Google Cloud Dataflow - Reference Architecture
Cloud Pub/Sub
Cloud Storage
Raw logs, files, assets, Google Analytics data, and so on
Events, metrics, and so on
Stream
Batch
Cloud Dataflow
Cloud Dataproc
Batch
BigQuery
Bigtable
B
C
A
Cloud Machine Learning
Applications
and Reports
Cloud Datalab
Visualization
and BI
Co-workers
Spanner
Count
ExpandPrefixes
Top(3)
Write
Read
ExtractTags
Tweets
Predictions
Pipeline p = Pipeline.create();
p.begin()
p.run();
.apply(ParDo.of(new ExtractTags()))
.apply(Top.largestPerKey(3))
.apply(Count.create())
.apply(ParDo.of(new ExpandPrefixes())
.apply(TextIO.Write.to(“gs://…”));
.apply(TextIO.Read.from(“gs://…”))
Pipeline p = Pipeline.create();
p.begin()
.apply(TextIO.Read.from(“gs://…”))
.apply(ParDo.of(new ExtractTags())
.apply(Count.create())
.apply(ParDo.of(new ExpandPrefixes())
.apply(Top.largestPerKey(3))
.apply(TextIO.Write.to(“gs://…”));
p.run();
Google Cloud Dataflow
Creating a Dataflow Pipeline
Use pre-built Dataflow Templates
Write custom Apache Beam code (Java, Python, Scala, Go)
Use Google Dataflow SQL (in Alpha)
Hybrid of any of the above methods
Advanced Big Data: Real-time Data Processing
Dan Zaratsian
AI/ML Solutions Architect, Gaming @ Google
Thanks!