Stream processing with Kafka Streams
Delivering events from tunnels to operators under 3 seconds
Content
Basic recap
Simple use-case
Simple use-case
Simple use-case
Simple use-case: Inside the application
Extending the use-case
Enter: Kafka Streams API
Application library for stream processing on top of Kafka clusters.
Features:
What is Stream Processing?
Event
Basic Kafka Streams Application Architecture
Foo | Axx | Add | Bar | |
Foo | Bar | | | |
Source processor
Sink processor
Stream
processors
Topology
Topology example
Foo | Axx | Add | Bar | |
Foo | Bar | | | |
Sink processor
Stream
processors
Chart made with: https://zz85.github.io/kafka-streams-viz/
DSL Stateful/Stateless transformations
Stateless
Stateful
Aggregation 101
| | | | |
| | | | |
Key | Value |
| |
| |
| |
Aggregation 101
F | | | | |
1 | 1 | | | | |
Key | Value |
1 | 1 |
| |
| |
Aggregation 101
F | Ba | | | |
1 | 1 | 2 | 1 | | | |
Key | Value |
1 | 1 |
2 | 1 |
| |
Aggregation 101
F | Ba | Foo | | |
1 | 1 | 2 | 1 | 3 | 1 | | |
Key | Value |
1 | 1 |
2 | 1 |
3 | 1 |
Aggregation 101
F | Ba | Foo | Bar | |
1 | 1 | 2 | 1 | 3 | 1 | 3 | 2 | |
Key | Value |
1 | 1 |
2 | 1 |
3 | 2 |
Aggregation 101
F | Ba | Foo | Bar | Ok |
1 | 1 | 2 | 1 | 3 | 1 | 3 | 2 | 2 | 2 |
Key | Value |
1 | 1 |
2 | 2 |
3 | 2 |
Aggregation 101
F | Ba | Foo | Bar | Ok |
1 | 1 | 2 | 1 | 3 | 1 | 3 | 2 | 2 | 2 |
Key | Value |
1 | 1 |
2 | 2 |
3 | 2 |
Stream as Table
Table as Stream
count in detailed view
State store
Exactly-once delivery semantics
Trafsys:�Graphics Engine
Case study
Old Architecture
OPC Client
Processing Engine
Web Server
Database is the main storage and communication hub
New Architecture
OPC Client
Processing Engine
Web Server
Database still essential and accessed by every component, but not used for messaging anymore
Graphics Engine
How to calculate update for an object?
ObjectType "Emergency phone area":
- TELEPHONE – at its place
- FIRE EXTINGUISHER – at its place
- DOOR – closed --> open
{� "objectId": 1,� "variable": "DOOR",� "state": "CLOSED",� "timestamp": 12341231321�}
{� "objectId": 1,� "variable": "DOOR",� "state": "OPEN",� "timestamp": 12341231322�}
Single state update:
Calculating object coloring
We need to remember state of all variables within the object
Remembering state
Storing calculated state
1
2
3
Already grouped!
Storing calculated state
Key | Value |
| |
| |
Storing calculated state
Key | Value |
1 | {DOOR: OPEN} |
| |
{� "objectId": 1,� "variable": "DOOR",� "state": "OPEN"�}
Storing calculated state
Key | Value |
1 | {DOOR: OPEN, PHONE:OK} |
| |
{� "objectId": 1,� "variable": "PHONE",� "state": "OK"�}
Storing calculated state
Key | Value |
1 | {DOOR: OPEN, PHONE:OK} |
2 | {DOOR: CLOSED} |
{� "objectId": 2,� "variable": "DOOR",� "state": "CLOSED"�}
Storing calculated state
Key | Value |
1 | {DOOR: CLOSED, PHONE:OK} |
2 | {DOOR: CLOSED} |
{� "objectId": 1,� "variable": "DOOR",� "state": "CLOSED"�}
Querying state
?
Querying state
Performance
Summary
Thanks!