SlideShare a Scribd company logo
7
Most read
8
Most read
9
Most read
Stateful Microservices with
Apache Kafka and Spring Cloud
Stream
Jan Svoboda, Solution Engineer
jsvoboda@confluent.io
Agenda
2
Basics Recap
Motivation for Event Driven Microservices
Event Types
EDM Components
Demo Application
Use Cases
Application Architecture
Stateful Microservices Concepts
Event Sourcing using State Store
Microservices decoupling (CQRS)
State Store Scaling
Smart Load Balancing
Jan Svoboda
https://www.linkedin.com/in/svobodajan/
• Confluent, Solutions Engineer 2020 - now
• Event Streaming, Event-Driven Microservices
• Apache Kafka, Kafka Streams
• Pivotal, Platform Architect, 2016 - 2020
• PaaS, Microservices
• Cloud Foundry, Spring, Rabbit MQ
• IBM, Solutions Architect, 2011 - 2016
• DevOps, Agile
• Bluemix, Rational
Basics Recap
Motivation for Kafka and Microservices
What is your Microservices Journey?
5
James Watters (Pivotal SVP), Kafka Summit 2019 Keynote, https://youtu.be/9I3CDfHKfNY?t=582
● Stage 1 -> Strangling the Monolith
○ DB based integration
● Stage 2-> Provide Independent Data
Sources
○ REST based integration
● Stage 3 -> Build Event Driven
Microservices
○ Kafka based integration
What is in the Event Message?
6
Martin Fowler (Thoughtworks), 7th Feb 2017, https://martinfowler.com/articles/201701-event-driven.html
● Event Notification
○ simple notification of change in its domain
○ no response required
● Event Carried State Transfer
○ contains details of the changed data
○ repeated data
● Event Sourcing
○ contains change to the state of a system
○ rebuild state by reprocessing changes
● Command Query Responsibility Segregation
○ separate structures for reading and writing
○ combined with previous message patterns
Neil Avery,, 31st Jan 2019,
https://www.confluent.io/blog/journey-to-event-driven-part-1-why-e
vent-first-thinking-changes-everything/
Event Driven Microservices Components
7
Apache Kafka
Broker for EDM events
Kafka Streams
Stream Processing API
RocksDB
Persistence layer for Kafka
Streams
Spring Cloud Stream
Stream abstraction layer
Kafka Streams Binder
SCS binding for Kafka
topics
Demo Application
Use Cases and Architecture
Demo Application - Use Cases
9
Simple Bookmarks Manager to demonstrate
Event Driven Microservices principles.
As a user I can:
● save a bookmark
● read list of my saved bookmarks
● change bookmark URL
● delete bookmark
Code available at
https://github.com/griga23/bookmarksDemo
Demo Application - Architecture and Dataflow
• Spring Boot (2 jars)
• Apache Kafka (2 topics)
• Spring Cloud Streams + Kafka
Streams Binder (RocksDB as a
state store)
Jan:Google,http://google.com
Jan:Google,http://google.com
JanGoogle: Google, http://google.com
JanGoogle,http://google.com
Stateful Microservices Concepts
Getting hands dirty...
1. Event Sourcing using State Store
My Data Liberation
● From Data sourcing to Event sourcing
● From synchronous Request/Reply to asynchronous Publish/Subscribe
● Store key/values in Kafka Streams State Store
● Kafka Streams Interactive Queries for data lookup
https://docs.confluent.io/platform/current/streams/developer-guide/interactive-queries.html
Spring Cloud Stream components
➔ StreamBridge class
➔ Java Lambda Functions for aggregating data to the
Materialized State Store
➔ InteractiveQueryService class
2. Microservices Decoupling (CQRS)
Command Query Responsibility
Segregation
● Pattern separates read and
update operations for a data
store.
● Implementing CQRS can
maximize performance,
scalability, and security.
● Allows a system to better
evolve over time and prevents
update commands from
causing merge conflicts at the
domain level.
https://docs.microsoft.com/en-us/azure/
architecture/patterns/cqrs
Kafka Streams State Store
➔ Change-log compacted topic
➔ RocksDB state.dir, applicationId, checkpoint
➔ Standby Replica
3. Scaling – Stateful Microservices
• Multiple State Stores
with different
partitions
• HTTP REST calls to
provide State Stores
inter communication
Jan:Google,http://google.com
Jan:Yahoo,http://yahoo.com
JanGoogle:Google,http://google.com
JanYahoo:Yahoo,http://yahoo.com
JanGoogle:Google,http://google.com
JanYahoo:Yahoo,http://yahooo.com
https://docs.confluent.io/platform/current/streams/developer-guide/interactive-queries.html#querying-remote-state-stores-for-the-entire-app
Kafka Streams State Store
➔ configuration application.server
➔ methods getAllHostsInfo, KeyQueryMetadata, getHostInfo
4. Smart Load Balancing – Routing to the Right
State Store
https://medium.com/bakdata/queryable-kafka-topics-with-kafka-streams-8d2cca9de33f
• Spring Cloud Gateway for
incoming HTTP traffic to redirect
to proper State Store
• State Store Host Awareness
Jan:Google,http://google.com
Jan:Google
JanYahoo:Yahoo,http://yahoo.com
Kafka Streams State Store
➔ getHostInfo
Questions/Comments
Nice ones only ;)
#CONFLUENTSKO2021
Thank you!
jsvoboda@confliuent.io

More Related Content

PPTX
Building Event Streaming Microservices with Spring Boot and Apache Kafka | Ja...
PPTX
Data Streaming with Apache Kafka & MongoDB
PDF
Building event-driven (Micro)Services with Apache Kafka Ecosystem
PDF
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
PDF
batbern43 Events - Lessons learnt building an Enterprise Data Bus
PDF
Building event-driven (Micro)Services with Apache Kafka
PDF
Life of a startup - Sjoerd Mulder - Codemotion Amsterdam 2017
PDF
Full lifecycle of a microservice
Building Event Streaming Microservices with Spring Boot and Apache Kafka | Ja...
Data Streaming with Apache Kafka & MongoDB
Building event-driven (Micro)Services with Apache Kafka Ecosystem
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
batbern43 Events - Lessons learnt building an Enterprise Data Bus
Building event-driven (Micro)Services with Apache Kafka
Life of a startup - Sjoerd Mulder - Codemotion Amsterdam 2017
Full lifecycle of a microservice

Similar to Stateful Microservices with Apache Kafka and Spring Cloud Stream with Jan Svoboda | Kafka Summit London 2022 (20)

PPTX
Data Streaming with Apache Kafka & MongoDB - EMEA
PPTX
Webinar: Data Streaming with Apache Kafka & MongoDB
PDF
James Watters Kafka Summit NYC 2019 Keynote
PDF
Event Streaming CTO Roundtable for Cloud-native Kafka Architectures
PDF
Set Your Data In Motion - CTO Roundtable
PPT
IBM Bluemix OpenWhisk: Serverless Conference 2016, London, UK: The Future of ...
PDF
IoT Architectures for Apache Kafka and Event Streaming - Industry 4.0, Digita...
PDF
Spring and Pivotal Application Service - SpringOne Tour Dallas
PPTX
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...
PPTX
IoT and Event Streaming at Scale with Apache Kafka
PDF
Scylla Summit 2022: An Odyssey to ScyllaDB and Apache Kafka
PDF
Spring and Pivotal Application Service - SpringOne Tour - Boston
PDF
How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...
PDF
Message Driven and Event Sourcing
PPTX
Developing Serverless Applications on Kubernetes with Knative - OSCON 2019
PPTX
Apache Beam (incubating)
PDF
Devoxx 2018 - Pivotal and AxonIQ - Quickstart your event driven architecture
PDF
Introducing Kafka's Streams API
PDF
Building Event-Driven (Micro)Services with Apache Kafka
PDF
Cloud APIs Overview Tucker
Data Streaming with Apache Kafka & MongoDB - EMEA
Webinar: Data Streaming with Apache Kafka & MongoDB
James Watters Kafka Summit NYC 2019 Keynote
Event Streaming CTO Roundtable for Cloud-native Kafka Architectures
Set Your Data In Motion - CTO Roundtable
IBM Bluemix OpenWhisk: Serverless Conference 2016, London, UK: The Future of ...
IoT Architectures for Apache Kafka and Event Streaming - Industry 4.0, Digita...
Spring and Pivotal Application Service - SpringOne Tour Dallas
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...
IoT and Event Streaming at Scale with Apache Kafka
Scylla Summit 2022: An Odyssey to ScyllaDB and Apache Kafka
Spring and Pivotal Application Service - SpringOne Tour - Boston
How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...
Message Driven and Event Sourcing
Developing Serverless Applications on Kubernetes with Knative - OSCON 2019
Apache Beam (incubating)
Devoxx 2018 - Pivotal and AxonIQ - Quickstart your event driven architecture
Introducing Kafka's Streams API
Building Event-Driven (Micro)Services with Apache Kafka
Cloud APIs Overview Tucker
Ad

More from HostedbyConfluent (20)

PDF
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
PDF
Renaming a Kafka Topic | Kafka Summit London
PDF
Evolution of NRT Data Ingestion Pipeline at Trendyol
PDF
Ensuring Kafka Service Resilience: A Dive into Health-Checking Techniques
PDF
Exactly-once Stream Processing with Arroyo and Kafka
PDF
Fish Plays Pokemon | Kafka Summit London
PDF
Tiered Storage 101 | Kafla Summit London
PDF
Building a Self-Service Stream Processing Portal: How And Why
PDF
From the Trenches: Improving Kafka Connect Source Connector Ingestion from 7 ...
PDF
Future with Zero Down-Time: End-to-end Resiliency with Chaos Engineering and ...
PDF
Navigating Private Network Connectivity Options for Kafka Clusters
PDF
Apache Flink: Building a Company-wide Self-service Streaming Data Platform
PDF
Explaining How Real-Time GenAI Works in a Noisy Pub
PDF
TL;DR Kafka Metrics | Kafka Summit London
PDF
A Window Into Your Kafka Streams Tasks | KSL
PDF
Mastering Kafka Producer Configs: A Guide to Optimizing Performance
PDF
Data Contracts Management: Schema Registry and Beyond
PDF
Code-First Approach: Crafting Efficient Flink Apps
PDF
Debezium vs. the World: An Overview of the CDC Ecosystem
PDF
Beyond Tiered Storage: Serverless Kafka with No Local Disks
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Renaming a Kafka Topic | Kafka Summit London
Evolution of NRT Data Ingestion Pipeline at Trendyol
Ensuring Kafka Service Resilience: A Dive into Health-Checking Techniques
Exactly-once Stream Processing with Arroyo and Kafka
Fish Plays Pokemon | Kafka Summit London
Tiered Storage 101 | Kafla Summit London
Building a Self-Service Stream Processing Portal: How And Why
From the Trenches: Improving Kafka Connect Source Connector Ingestion from 7 ...
Future with Zero Down-Time: End-to-end Resiliency with Chaos Engineering and ...
Navigating Private Network Connectivity Options for Kafka Clusters
Apache Flink: Building a Company-wide Self-service Streaming Data Platform
Explaining How Real-Time GenAI Works in a Noisy Pub
TL;DR Kafka Metrics | Kafka Summit London
A Window Into Your Kafka Streams Tasks | KSL
Mastering Kafka Producer Configs: A Guide to Optimizing Performance
Data Contracts Management: Schema Registry and Beyond
Code-First Approach: Crafting Efficient Flink Apps
Debezium vs. the World: An Overview of the CDC Ecosystem
Beyond Tiered Storage: Serverless Kafka with No Local Disks
Ad

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Empathic Computing: Creating Shared Understanding
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
KodekX | Application Modernization Development
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Advanced methodologies resolving dimensionality complications for autism neur...
NewMind AI Monthly Chronicles - July 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
Empathic Computing: Creating Shared Understanding
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Weekly Chronicles - August'25 Week I
“AI and Expert System Decision Support & Business Intelligence Systems”
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
20250228 LYD VKU AI Blended-Learning.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Digital-Transformation-Roadmap-for-Companies.pptx
Electronic commerce courselecture one. Pdf
KodekX | Application Modernization Development
The Rise and Fall of 3GPP – Time for a Sabbatical?
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Stateful Microservices with Apache Kafka and Spring Cloud Stream with Jan Svoboda | Kafka Summit London 2022

  • 1. Stateful Microservices with Apache Kafka and Spring Cloud Stream Jan Svoboda, Solution Engineer jsvoboda@confluent.io
  • 2. Agenda 2 Basics Recap Motivation for Event Driven Microservices Event Types EDM Components Demo Application Use Cases Application Architecture Stateful Microservices Concepts Event Sourcing using State Store Microservices decoupling (CQRS) State Store Scaling Smart Load Balancing
  • 3. Jan Svoboda https://www.linkedin.com/in/svobodajan/ • Confluent, Solutions Engineer 2020 - now • Event Streaming, Event-Driven Microservices • Apache Kafka, Kafka Streams • Pivotal, Platform Architect, 2016 - 2020 • PaaS, Microservices • Cloud Foundry, Spring, Rabbit MQ • IBM, Solutions Architect, 2011 - 2016 • DevOps, Agile • Bluemix, Rational
  • 4. Basics Recap Motivation for Kafka and Microservices
  • 5. What is your Microservices Journey? 5 James Watters (Pivotal SVP), Kafka Summit 2019 Keynote, https://youtu.be/9I3CDfHKfNY?t=582 ● Stage 1 -> Strangling the Monolith ○ DB based integration ● Stage 2-> Provide Independent Data Sources ○ REST based integration ● Stage 3 -> Build Event Driven Microservices ○ Kafka based integration
  • 6. What is in the Event Message? 6 Martin Fowler (Thoughtworks), 7th Feb 2017, https://martinfowler.com/articles/201701-event-driven.html ● Event Notification ○ simple notification of change in its domain ○ no response required ● Event Carried State Transfer ○ contains details of the changed data ○ repeated data ● Event Sourcing ○ contains change to the state of a system ○ rebuild state by reprocessing changes ● Command Query Responsibility Segregation ○ separate structures for reading and writing ○ combined with previous message patterns Neil Avery,, 31st Jan 2019, https://www.confluent.io/blog/journey-to-event-driven-part-1-why-e vent-first-thinking-changes-everything/
  • 7. Event Driven Microservices Components 7 Apache Kafka Broker for EDM events Kafka Streams Stream Processing API RocksDB Persistence layer for Kafka Streams Spring Cloud Stream Stream abstraction layer Kafka Streams Binder SCS binding for Kafka topics
  • 8. Demo Application Use Cases and Architecture
  • 9. Demo Application - Use Cases 9 Simple Bookmarks Manager to demonstrate Event Driven Microservices principles. As a user I can: ● save a bookmark ● read list of my saved bookmarks ● change bookmark URL ● delete bookmark Code available at https://github.com/griga23/bookmarksDemo
  • 10. Demo Application - Architecture and Dataflow • Spring Boot (2 jars) • Apache Kafka (2 topics) • Spring Cloud Streams + Kafka Streams Binder (RocksDB as a state store) Jan:Google,http://google.com Jan:Google,http://google.com JanGoogle: Google, http://google.com JanGoogle,http://google.com
  • 12. 1. Event Sourcing using State Store My Data Liberation ● From Data sourcing to Event sourcing ● From synchronous Request/Reply to asynchronous Publish/Subscribe ● Store key/values in Kafka Streams State Store ● Kafka Streams Interactive Queries for data lookup https://docs.confluent.io/platform/current/streams/developer-guide/interactive-queries.html Spring Cloud Stream components ➔ StreamBridge class ➔ Java Lambda Functions for aggregating data to the Materialized State Store ➔ InteractiveQueryService class
  • 13. 2. Microservices Decoupling (CQRS) Command Query Responsibility Segregation ● Pattern separates read and update operations for a data store. ● Implementing CQRS can maximize performance, scalability, and security. ● Allows a system to better evolve over time and prevents update commands from causing merge conflicts at the domain level. https://docs.microsoft.com/en-us/azure/ architecture/patterns/cqrs Kafka Streams State Store ➔ Change-log compacted topic ➔ RocksDB state.dir, applicationId, checkpoint ➔ Standby Replica
  • 14. 3. Scaling – Stateful Microservices • Multiple State Stores with different partitions • HTTP REST calls to provide State Stores inter communication Jan:Google,http://google.com Jan:Yahoo,http://yahoo.com JanGoogle:Google,http://google.com JanYahoo:Yahoo,http://yahoo.com JanGoogle:Google,http://google.com JanYahoo:Yahoo,http://yahooo.com https://docs.confluent.io/platform/current/streams/developer-guide/interactive-queries.html#querying-remote-state-stores-for-the-entire-app Kafka Streams State Store ➔ configuration application.server ➔ methods getAllHostsInfo, KeyQueryMetadata, getHostInfo
  • 15. 4. Smart Load Balancing – Routing to the Right State Store https://medium.com/bakdata/queryable-kafka-topics-with-kafka-streams-8d2cca9de33f • Spring Cloud Gateway for incoming HTTP traffic to redirect to proper State Store • State Store Host Awareness Jan:Google,http://google.com Jan:Google JanYahoo:Yahoo,http://yahoo.com Kafka Streams State Store ➔ getHostInfo