SlideShare a Scribd company logo
1 of 32
Download to read offline
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 1/32
BUILDING MICROSERVICES WITH KAFKA STREAMSBUILDING MICROSERVICES WITH KAFKA STREAMS
Beyond Kafka-for-Messaging
Andreas Schroeder
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 2/32
WHYWHY
Kafka
is a thing
can be used in interesting ways beyond messaging
Kafka Streams - not just for data analytics
both have surprises and pitfalls
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 3/32
ABOUT MEABOUT ME
Dr. Andreas Schroeder
@AndSchroeder
andreas-schroeder
Kafka user & experimenter since 2016
Pet topics: distributed systems, architecutre, ops
Currently @ BMW
Akka Alpakka contributor
All views presented here are my own
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 4/32
KAFKA CLUSTER-SIDEKAFKA CLUSTER-SIDE
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 5/32
PARTITIONS & OFFSETSPARTITIONS & OFFSETS
0
0 1
1
2
2 3
3 4
4 5
5 6
6
0 1 2 3 4 5 6 7
7
7
8
8
8
9
9
9 10
10
11 12
Records
offset
value
key
timestamp
p0
p1
p2
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 6/32
PRODUCERS & CONSUMERSPRODUCERS & CONSUMERS
Producer
Consumer
read read
append
Consumer
consumergroup
Consumer
read
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 7/32
DATA RETENTIONDATA RETENTION
time / size-based
7 days
key-based log compaction
superseded by update
Records
current
state of
keyed
entities
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 8/32
PITFALLS: KAFKA DEFAULT CONFIGSPITFALLS: KAFKA DEFAULT CONFIGS
availability + throughput > consistency + durability
not so great for event sourcing or CDC
producer acks: 1 vs. all
producer retries (Before 2.1): 0 vs. 2147483647
producer delivery timeout (Since 2.1): 2 mins vs. 1 day
topic min.insync.replicas: 1 vs. 2
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 9/32
EVENT SOURCINGEVENT SOURCING
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 10/32
CQRS EVENT SOURCING BIG PICTURECQRS EVENT SOURCING BIG PICTURE
events reducers state
service
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 11/32
GETTING KAFKA STREAMS EVENT SOURCINGGETTING KAFKA STREAMS EVENT SOURCING
1. Key abstractions: KStream and KTable
KStream: unbounded stream of data
KTable: continuously updated key-value store
Stream-Table duality
2. KStream with groupBy & aggregate produces KTable
aggregating events = event sourcing
3. KTable - backed by distributed & fault-tolerant store
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 12/32
STATE MANAGEMENTSTATE MANAGEMENT
in
State
outapp
in-memory or
RocksDB
changelog
stateful
transformation
for backup &
standby replicas
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 13/32
DEMODEMO
events segmenter
sess.
device 1
device 2
device 3
device 4
device 5
driver
segmenter-sessions-
changelog
session-
events
reader
DeviceWokeUp
DataReceived
AllDataReceived
device-id → event dev-id + sess-id → event
Data emitted in sessions with start / end markers
Task: generate and maintain session ids
https://github.com/andreas-schroeder/demo-segmenter
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 14/32
EVENT SOURCING COMPAREDEVENT SOURCING COMPARED
events
snapshots
app
app'
ephemeral derivation
persistent source of truth
events app
state
changelog
persistent
ephemeral
limited retention
system input
events - source of truth vs. audit log
state - derivation vs. persistent
fixes - reprocess vs. compensation events
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 15/32
RETAINING EVENTSRETAINING EVENTS
Events can also be kept indefinitely
Store events in log-compacted topic with unique ids
as keys
Use groupBy(entity key) & aggregate
Needs explicit deletion of events
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 16/32
NEW LANGUAGENEW LANGUAGE
http request → record
key-value put → groupByKey, aggregate
key-value lookup → stream + table join
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 17/32
SIDE-EFFECTING OUT OF KAFKASIDE-EFFECTING OUT OF KAFKA
Kafka Streams is only for
CPU-bound data transformation on Kafka
No HTTP calls
No I/O other than Kafka
Consequence: side-effects must go through topics
Use Kafka connect or Akka/Alpakka
for acting on the world
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 18/32
PITFALLSPITFALLS
Joins and aggregate are difficult to fully grasp
Read the docs on - really
Losing my religion consumer offsets
Protect yourself with timeouts
i.e. stream.filter(recent)
stateful transformations
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 19/32
EVENT SOURCING TAKE AWAYEVENT SOURCING TAKE AWAY
Kafka Streams
can be used to build event reducers
works only on Kafka topics - no external I/O
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 20/32
CHANGE DATA CAPTURECHANGE DATA CAPTURE
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 21/32
HIGH FANOUT SERVICESHIGH FANOUT SERVICES
query / read
endpoint
High query volume
Tight availability requirements
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 22/32
SYNC COUPLING AND CONSISTENCYSYNC COUPLING AND CONSISTENCY
A B C
API
sync
async
avAPI
tAPI
= a ⋅ a ⋅ avA vB vC
= + +tA tB tC
avAPI
tAPI
= avA
= tA
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 23/32
TRADING CONSISTENCY FOR AVAILABILITYTRADING CONSISTENCY FOR AVAILABILITY
Source
Source
Connector
Sink
Connector
Client
full stock
Write
API
push all
updates
store full
records
follow & apply
updates
retention policy:
log compaction
Failures of individual services are partial system failures only
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 24/32
BLUE/GREEN DATA MIGRATIONBLUE/GREEN DATA MIGRATION
Ablue
full stock
Agreen
Read stock topic from the start
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 25/32
DATA TRANSFORMATION PIPELINESDATA TRANSFORMATION PIPELINES
Transform
stock A
Sink
Connector
aggregatedstock B
stock C
Combining multiple stocks is a stateful transformation
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 26/32
CDC TECHNOLOGIESCDC TECHNOLOGIES
Source
Connector
Sink
Connector
Transform
Relational DBs
   Kafka Connect
   Debezium
Other sources
   Kafka Connect
   Alpakka / Akka Stream
Kafka Connect
Alpakka / Akka Stream
Kafka Streams
Flink
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 27/32
CDC PITFALLSCDC PITFALLS
Handrolling DB source connectors
Source connectors are complex
initial load and deltas
at-least-once delivery
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 28/32
CDC TAKE AWAYCDC TAKE AWAY
Asynchronous decoupling allows trading
consistency for resilience
CDC is not trivial to get started with
Rich ecosystem of technoligies exists
Combine multiple sources with Kafka Streams
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 29/32
WRAP-UPWRAP-UP
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 30/32
SUMMARYSUMMARY
Kafka Streams
CQRS event reducers
Change Data Capture
New Language
Connectors needed get back out of Kafka
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 31/32
O'Reilly Ideas
RECOMMENDED READSRECOMMENDED READS
Martin Kleppmann | Kafka Summit SFMartin Kleppmann | Kafka Summit SFMartin Kleppmann | Kafka Summit SF ……… Jay Kreps | Kafka Summit SF 2018 KeyJay Kreps | Kafka Summit SF 2018 KeyJay Kreps | Kafka Summit SF 2018 Key………
Streaming 101
Streaming 102
10.1.2019 Building Microservices with Kafka Streams
http://localhost:8000/?print-pdf#/ 32/32
THANK YOUTHANK YOU

More Related Content

Recently uploaded

Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 

Recently uploaded (20)

GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionThe Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion Production
 
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purityAPVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java Developers
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
AI Hackathon.pptx
AI                        Hackathon.pptxAI                        Hackathon.pptx
AI Hackathon.pptx
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
 

Featured

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)
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn
 

Featured (20)

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...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Building microservices with kafka streams

  • 1. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 1/32 BUILDING MICROSERVICES WITH KAFKA STREAMSBUILDING MICROSERVICES WITH KAFKA STREAMS Beyond Kafka-for-Messaging Andreas Schroeder
  • 2. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 2/32 WHYWHY Kafka is a thing can be used in interesting ways beyond messaging Kafka Streams - not just for data analytics both have surprises and pitfalls
  • 3. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 3/32 ABOUT MEABOUT ME Dr. Andreas Schroeder @AndSchroeder andreas-schroeder Kafka user & experimenter since 2016 Pet topics: distributed systems, architecutre, ops Currently @ BMW Akka Alpakka contributor All views presented here are my own
  • 4. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 4/32 KAFKA CLUSTER-SIDEKAFKA CLUSTER-SIDE
  • 5. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 5/32 PARTITIONS & OFFSETSPARTITIONS & OFFSETS 0 0 1 1 2 2 3 3 4 4 5 5 6 6 0 1 2 3 4 5 6 7 7 7 8 8 8 9 9 9 10 10 11 12 Records offset value key timestamp p0 p1 p2
  • 6. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 6/32 PRODUCERS & CONSUMERSPRODUCERS & CONSUMERS Producer Consumer read read append Consumer consumergroup Consumer read
  • 7. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 7/32 DATA RETENTIONDATA RETENTION time / size-based 7 days key-based log compaction superseded by update Records current state of keyed entities
  • 8. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 8/32 PITFALLS: KAFKA DEFAULT CONFIGSPITFALLS: KAFKA DEFAULT CONFIGS availability + throughput > consistency + durability not so great for event sourcing or CDC producer acks: 1 vs. all producer retries (Before 2.1): 0 vs. 2147483647 producer delivery timeout (Since 2.1): 2 mins vs. 1 day topic min.insync.replicas: 1 vs. 2
  • 9. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 9/32 EVENT SOURCINGEVENT SOURCING
  • 10. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 10/32 CQRS EVENT SOURCING BIG PICTURECQRS EVENT SOURCING BIG PICTURE events reducers state service
  • 11. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 11/32 GETTING KAFKA STREAMS EVENT SOURCINGGETTING KAFKA STREAMS EVENT SOURCING 1. Key abstractions: KStream and KTable KStream: unbounded stream of data KTable: continuously updated key-value store Stream-Table duality 2. KStream with groupBy & aggregate produces KTable aggregating events = event sourcing 3. KTable - backed by distributed & fault-tolerant store
  • 12. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 12/32 STATE MANAGEMENTSTATE MANAGEMENT in State outapp in-memory or RocksDB changelog stateful transformation for backup & standby replicas
  • 13. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 13/32 DEMODEMO events segmenter sess. device 1 device 2 device 3 device 4 device 5 driver segmenter-sessions- changelog session- events reader DeviceWokeUp DataReceived AllDataReceived device-id → event dev-id + sess-id → event Data emitted in sessions with start / end markers Task: generate and maintain session ids https://github.com/andreas-schroeder/demo-segmenter
  • 14. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 14/32 EVENT SOURCING COMPAREDEVENT SOURCING COMPARED events snapshots app app' ephemeral derivation persistent source of truth events app state changelog persistent ephemeral limited retention system input events - source of truth vs. audit log state - derivation vs. persistent fixes - reprocess vs. compensation events
  • 15. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 15/32 RETAINING EVENTSRETAINING EVENTS Events can also be kept indefinitely Store events in log-compacted topic with unique ids as keys Use groupBy(entity key) & aggregate Needs explicit deletion of events
  • 16. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 16/32 NEW LANGUAGENEW LANGUAGE http request → record key-value put → groupByKey, aggregate key-value lookup → stream + table join
  • 17. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 17/32 SIDE-EFFECTING OUT OF KAFKASIDE-EFFECTING OUT OF KAFKA Kafka Streams is only for CPU-bound data transformation on Kafka No HTTP calls No I/O other than Kafka Consequence: side-effects must go through topics Use Kafka connect or Akka/Alpakka for acting on the world
  • 18. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 18/32 PITFALLSPITFALLS Joins and aggregate are difficult to fully grasp Read the docs on - really Losing my religion consumer offsets Protect yourself with timeouts i.e. stream.filter(recent) stateful transformations
  • 19. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 19/32 EVENT SOURCING TAKE AWAYEVENT SOURCING TAKE AWAY Kafka Streams can be used to build event reducers works only on Kafka topics - no external I/O
  • 20. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 20/32 CHANGE DATA CAPTURECHANGE DATA CAPTURE
  • 21. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 21/32 HIGH FANOUT SERVICESHIGH FANOUT SERVICES query / read endpoint High query volume Tight availability requirements
  • 22. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 22/32 SYNC COUPLING AND CONSISTENCYSYNC COUPLING AND CONSISTENCY A B C API sync async avAPI tAPI = a ⋅ a ⋅ avA vB vC = + +tA tB tC avAPI tAPI = avA = tA
  • 23. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 23/32 TRADING CONSISTENCY FOR AVAILABILITYTRADING CONSISTENCY FOR AVAILABILITY Source Source Connector Sink Connector Client full stock Write API push all updates store full records follow & apply updates retention policy: log compaction Failures of individual services are partial system failures only
  • 24. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 24/32 BLUE/GREEN DATA MIGRATIONBLUE/GREEN DATA MIGRATION Ablue full stock Agreen Read stock topic from the start
  • 25. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 25/32 DATA TRANSFORMATION PIPELINESDATA TRANSFORMATION PIPELINES Transform stock A Sink Connector aggregatedstock B stock C Combining multiple stocks is a stateful transformation
  • 26. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 26/32 CDC TECHNOLOGIESCDC TECHNOLOGIES Source Connector Sink Connector Transform Relational DBs    Kafka Connect    Debezium Other sources    Kafka Connect    Alpakka / Akka Stream Kafka Connect Alpakka / Akka Stream Kafka Streams Flink
  • 27. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 27/32 CDC PITFALLSCDC PITFALLS Handrolling DB source connectors Source connectors are complex initial load and deltas at-least-once delivery
  • 28. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 28/32 CDC TAKE AWAYCDC TAKE AWAY Asynchronous decoupling allows trading consistency for resilience CDC is not trivial to get started with Rich ecosystem of technoligies exists Combine multiple sources with Kafka Streams
  • 29. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 29/32 WRAP-UPWRAP-UP
  • 30. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 30/32 SUMMARYSUMMARY Kafka Streams CQRS event reducers Change Data Capture New Language Connectors needed get back out of Kafka
  • 31. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 31/32 O'Reilly Ideas RECOMMENDED READSRECOMMENDED READS Martin Kleppmann | Kafka Summit SFMartin Kleppmann | Kafka Summit SFMartin Kleppmann | Kafka Summit SF ……… Jay Kreps | Kafka Summit SF 2018 KeyJay Kreps | Kafka Summit SF 2018 KeyJay Kreps | Kafka Summit SF 2018 Key……… Streaming 101 Streaming 102
  • 32. 10.1.2019 Building Microservices with Kafka Streams http://localhost:8000/?print-pdf#/ 32/32 THANK YOUTHANK YOU