KEMBAR78
BigData conference - Introduction to stream processing | PPTX
@nicolas_frankel
A gentle introduction to Stream
Processing
Nicolas Fränkel
@nicolas_frankel
Me, myself and I
 18 years in technical roles:
• Developer, team lead, architect, …
 Developer Advocate
@nicolas_frankel
Hazelcast
HAZELCAST IMDG is an operational,
in-memory, distributed computing
platform that manages data using
in-memory storage and performs
execution for breakthrough
and scale.
HAZELCAST JET is the ultra
fast, application embeddable,
3rd generation stream
processing engine for low
latency batch and stream
processing.
@nicolas_frankel
Schedule
 Why streaming?
 Streaming approaches
 Hazelcast Jet
 Open Data
 General Transit Feed Specification
 The demo
@nicolas_frankel
In a time before our time…
Data was neatly stored in SQL databases
@nicolas_frankel
The need for Extract Transform Load
 Analytics
• Supermarket sales in the last hour?
 Reporting
• Banking account annual closing
@nicolas_frankel
Writes vs. reads
 Normalized vs. denormalized
 Correct vs. fast
@nicolas_frankel
What SQL implies
 Normal forms
 Joins
 Constraints
@nicolas_frankel
The need for ETL
 Different actors
 With different needs
 Using the same database?
@nicolas_frankel
The batch model
1. Extract
2. Transform
3. Load
@nicolas_frankel
Batches are everywhere!
@nicolas_frankel
Properties of batches
 Scheduled at regular intervals
• Daily
• Weekly
• Monthly
• Yearly
• etc.
 Run in a specific amount of time
@nicolas_frankel
Oops
 When the execution time overlaps the
next execution schedule
 When the space taken by the data
exceeds the storage capacity
 When the batch fails mid-execution
 etc.
@nicolas_frankel
Chunking!
 Keep a cursor
• And only manage “chunks” of data
 What about new data coming in?
@nicolas_frankel
Big data!
 Parallelize everything
• Map - Reduce
• Hadoop
 NoSQL
• Schema on Read vs. Schema on Write
@nicolas_frankel
Event
“In programming and software design, an event is an action or
occurrence recognized by software, often originating
asynchronously from the external environment, that may be
handled by the software. Computer events can be generated or
triggered by the system, by the user, or in other ways.”
-- Wikipedia
@nicolas_frankel
Make everything event-based!
@nicolas_frankel
Benefits
 Memory-friendly
 Easily processed
 Pull vs. push
• Very close to real-time
• Keeps derived data in-sync
@nicolas_frankel
From finite datasets to infinite
@nicolas_frankel
Stateful streams
 Aggregation
 Windowing
@nicolas_frankel
Streaming is “smart” ETL
Processing
Ingest
In-Memory
Operational
Storage
Combine
Join, Enrich,
Group, Aggregate
Stream
Windowing,
Event-Time
Processing
Compute
Distributed and
Parallel
Computation
Transform
Filter, Clean,
Convert
Publish
In-Memory,
Subscriber
Notifications
@nicolas_frankel
Analytics and Decision Making
 Real-time dashboards
 Stats
 Predictions
• Push stream through ML model
 Complex-Event-Processing
@nicolas_frankel
Persistent event-storage systems
 Apache Kafka
 Apache Pulsar
@nicolas_frankel
Apache Kafka
 Distributed
 On-disk storage
 Messages sent and read from a topic
 Consumer can keep track of the offset
@nicolas_frankel
Some in-memory stream processing engines
 On-premise
• Apache Flink
• Hazelcast Jet
 Cloud-based
• Amazon Kinesis
• Google Dataflow
 Apache Beam
• Abstraction over some of the above
@nicolas_frankel
Hazelcast Jet
 Apache 2 Open Source
 Leverages Hazelcast IMDG
 Unified batch/streaming API
 (Hazelcast Jet Enterprise)
@nicolas_frankel
Pipeline Job
 Declarative code that
defines and links sources,
transforms, and sinks
 Platform-specific SDK
 Client submits pipeline to
the SPE
 Running instance of pipeline
in SPE
 SPE executes the pipeline
• Code execution
• Data routing
• Flow control
@nicolas_frankel
Deployment modes
// Create new cluster member
JetInstance jet = Jet.newJetInstance();
// Connect to running cluster
JetInstance jet = Jet.newJetClient();
Client/ServerEmbedded
Java API
Application
Java API
Application
Java API
Application
Client API
Application
Client API
Application
Client API
Application
Client API
Application
@nicolas_frankel
Hazelcast Jet
@nicolas_frankel
Open Data
« Open data is the idea that some data
should be freely available to everyone to
use and republish as they wish, without
restrictions from copyright, patents or
other mechanisms of control. »
--https://en.wikipedia.org/wiki/Open_data
@nicolas_frankel
Some Open Data initiatives
 France:
• https://www.data.gouv.fr/fr/
 Switzerland:
• https://opendata.swiss/en/
 European Union:
• https://data.europa.eu/euodp/en/data/
@nicolas_frankel
Challenges
1. Access
2. Format
3. Standard
4. Data correctness
@nicolas_frankel
Access
 Access data interactively through a web-
service
 Download a file
@nicolas_frankel
Format
In general, Open Data means Open
Format
 PDF
 CSV
 XML
 JSON
 etc.
@nicolas_frankel
Standard
 Let’s pretend the format is XML
• Which grammar is used?
 A shared standard is required
• Congruent to a domain
@nicolas_frankel
Data correctness
"32.TA.66-43","16:20:00","16:20:00","8504304"
"32.TA.66-44","24:53:00","24:53:00","8500100"
"32.TA.66-44","25:00:00","25:00:00","8500162"
"32.TA.66-44","25:02:00","25:02:00","8500170"
"32.TA.66-45","23:32:00","23:32:00","8500170"
@nicolas_frankel
A standard for Public Transport
 General Transit Feed Specification (GTFS)
 ” […] defines a common format for public transportation
schedules and associated geographic information. GTFS
feeds let public transit agencies publish their transit data and
developers write applications that consume that data in an
interoperable way.”
 Based on two kinds of data:
• “Static” e.g. stops
• Dynamic e.g. position
@nicolas_frankel
GTFS static model
Filename Required Defines
agency.txt Required Transit agencies with service represented in this dataset.
stops.txt Required
Stops where vehicles pick up or drop off riders. Also defines stations and station
entrances.
routes.txt Required Transit routes. A route is a group of trips that are displayed to riders as a single service.
trips.txt Required
Trips for each route. A trip is a sequence of two or more stops that occur during a
specific time period.
stop_times.txt Required Times that a vehicle arrives at and departs from stops for each trip.
calendar.txt Conditionally required
Service dates specified using a weekly schedule with start and end dates. This file is
required unless all dates of service are defined in calendar_dates.txt.
calendar_dates.txt Conditionally required
Exceptions for the services defined in the calendar.txt. If calendar.txt is omitted, then
calendar_dates.txt is required and must contain all dates of service.
fare_attributes.txt Optional Fare information for a transit agency's routes.
@nicolas_frankel
GTFS static model
Filename Required Defines
fare_rules.txt Optional Rules to apply fares for itineraries.
shapes.txt Optional Rules for mapping vehicle travel paths, sometimes referred to as route alignments.
frequencies.txt Optional
Headway (time between trips) for headway-based service or a compressed representation of fixed-schedule
service.
transfers.txt Optional Rules for making connections at transfer points between routes.
pathways.txt Optional Pathways linking together locations within stations.
levels.txt Optional Levels within stations.
feed_info.txt Optional Dataset metadata, including publisher, version, and expiration information.
translations.txt Optional Translated information of a transit agency.
attributions.txt Optional Specifies the attributions that are applied to the dataset.
@nicolas_frankel
GTFS dynamic model
@nicolas_frankel
A GTFS provider: Swiss Public Transport
 Open Data
 GTFS static available as downloadable
.txt files
 GTFS dynamic available as a REST
endpoint
@nicolas_frankel
The available… … data model
Where’s the position?!
@nicolas_frankel
The dynamic data pipeline
1. Source: web service
2. Split into trip updates
3. Enrich with trip data
4. Enrich with stop times data
5. Transform hours into timestamp
6. Enrich with location data
7. Sink: Hazelcast IMDG
@nicolas_frankel
Architecture overview
@nicolas_frankel
Talk is cheap, show me the code!
@nicolas_frankel
Recap
 Streaming has a lot of benefits
 Leverage available Data
• Open Data has a lot of untapped
potential
 But you can get cool stuff done!
@nicolas_frankel
Thanks a lot!
 https://blog.frankel.ch/
 @nicolas_frankel
 https://jet-start.sh/
 https://bit.ly/jet-train
 https://slack.hazelcast.com/

BigData conference - Introduction to stream processing

Editor's Notes

  • #23 Real-time (latency-sensitive) operations combined with analytics Count usages per CC in last 10 secs, fraud if > 10 Real-time querying Based on analytics, prediction Fraud detection ran overnight has low value Complex event processing Pattern detection (if A and B -> C) SPE runs this at scale Valuable: IOT support. Machine analytics/predictions - fits into AI Without streaming?
  • #41 @startuml class FeedMessage class FeedHeader { gtfs_realtime_version: string timestamp: uint64 } enum Incrementality { FULL_DATASET DIFFERENTIAL } class FeedEntity { id: String is_deleted: boolean } class TripUpdate { timestamp: uint64 delay: int32 } class VehiclePosition { current_stop_sequence: uint32 stop_id: string timestamp: uint64 } enum VehicleStopStatus { INCOMING_AT STOPPED_AT IN_TRANSIT_TO } enum CongestionLevel { UNKNOWN_CONGESTION_LEVEL RUNNING_SMOOTHLY STOP_AND_GO CONGESTION SEVERE_CONGESTION } class Alert enum Cause { UNKNOWN_CAUSE OTHER_CAUSE TECHNICAL_PROBLEM STRIKE DEMONSTRATION ACCIDENT HOLIDAY WEATHER MAINTENANCE CONSTRUCTION POLICE_ACTIVITY MEDICAL_EMERGENCY } enum Effect { NO_SERVICE REDUCED_SERVICE SIGNIFICANT_DELAYS DETOUR ADDITIONAL_SERVICE MODIFIED_SERVICE OTHER_EFFECT UNKNOWN_EFFECT STOP_MOVED } class TimeRange { start: uint64 end: uint64 } class Position { latitude: float longitude: float bearing: float odometer: double speed: float } class TripDescriptor { trip_id: String route_id: String direction_id: uint32 start_time: string start_date: string } class VehicleDescriptor { id: string label: string license_plate: string } class StopTimeUpdate { stop_sequence: uint32 stop_id: string } class StopTimeEvent { delay: uint32 time: int64 uncertainty: int32 } enum ScheduleRelationship { SCHEDULED SKIPPED NO_DATA } class TripDescriptor { trip_id: string route_id: string direction_id: uint32 start_time: string start_date: string } enum ScheduleRelationship2 as "ScheduleRelationship" { SCHEDULED ADDED UNSCHEDULED CANCELED } class EntitySelector { agency_id: string route_id: string route_type: int32 stop_id: string } class Translation { text: string language: string } FeedMessage -up-> "1" FeedHeader: header FeedMessage -down-> "*" FeedEntity: entity FeedHeader -right-> "1" Incrementality FeedEntity --> "0..1" TripUpdate FeedEntity -left-> "0..1" VehiclePosition FeedEntity -right-> "0..1" Alert TripUpdate --> "1" TripDescriptor: trip TripUpdate -left-> "0..1" VehicleDescriptor: vehicle TripUpdate --> "*" StopTimeUpdate StopTimeUpdate -left-> "0..1" StopTimeEvent: arrival StopTimeUpdate -left-> "0..1" StopTimeEvent: departure StopTimeUpdate --> "0..1" ScheduleRelationship TripDescriptor -right-> "0..1" ScheduleRelationship2 VehiclePosition --> "0..1" TripDescriptor: trip VehiclePosition --> "0..1" VehicleDescriptor: vehicle VehiclePosition -left-> "0..1" Position: vehicle VehiclePosition -up-> "0..1" VehicleStopStatus: current_status VehiclePosition -up-> "0..1" CongestionLevel Alert --> "*" TimeRange: active_period Alert --> "1..*" EntitySelector: informed_entity Alert -up-> "0..1" Cause Alert -up-> "0..1" Effect Alert -right-> "0..1" TranslatedString: url Alert -right-> "1" TranslatedString: header_text Alert -right-> "1" TranslatedString: description_text EntitySelector --> "0..1" TripDescriptor: trip TranslatedString --> "1..*" Translation note left of FeedMessage: Root message hide empty members @enduml
  • #45 node "Hazelcast Jet" as jet { database "Hazelcast IMDG" as imdg artifact "Load reference data Job" as staticjob artifact "Load dynamic data Job" as dynamicjob folder "Reference data files" as refdata { file trips.txt file routes.txt } } component "Reference data loader" <<Loader>> as staticloader component "Dynamic data loader" <<Loader>> as dynamicloader component "Web application" <<Spring Boot>> as webapp cloud { interface "Open Data endpoint" as ws } staticloader --> staticjob: Send job staticjob --> refdata: Read files staticjob --> imdg: Store JSON dynamicloader --> dynamicjob: Send job dynamicjob -right-> ws: Call REST endpoint dynamicjob --> imdg: Store JSON webapp -left-> imdg: Register to changes