SlideShare a Scribd company logo
1
Building Event Driven
Microservices with Apache
Kafka and Kafka Streams
Ben Stopford
@benstopford
2
Build
Features
Build for
the Future
3
Evolution!
4
KAFKA
Serving
Layer
(Cassandra etc.)
Kafka Streams /
KSQL
Streaming Platforms
Data is embedded in
each engine
High Throughput
Messaging
Clustered
Java App
5
authorization_attempts possible_fraud
Streaming Example
6
CREATE STREAM possible_fraud AS
SELECT card_number, count(*)
FROM authorization_attempts
WINDOW TUMBLING (SIZE 5 MINUTE)
GROUP BY card_number
HAVING count(*) > 3;
authorization_attempts possible_fraud
7
CREATE STREAM possible_fraud AS
SELECT card_number, count(*)
FROM authorization_attempts
WINDOW TUMBLING (SIZE 5 MINUTE)
GROUP BY card_number
HAVING count(*) > 3;
authorization_attempts possible_fraud
8
CREATE STREAM possible_fraud AS
SELECT card_number, count(*)
FROM authorization_attempts
WINDOW TUMBLING (SIZE 5 MINUTE)
GROUP BY card_number
HAVING count(*) > 3;
authorization_attempts possible_fraud
9
CREATE STREAM possible_fraud AS
SELECT card_number, count(*)
FROM authorization_attempts
WINDOW TUMBLING (SIZE 5 MINUTE)
GROUP BY card_number
HAVING count(*) > 3;
authorization_attempts possible_fraud
10
CREATE STREAM possible_fraud AS
SELECT card_number, count(*)
FROM authorization_attempts
WINDOW TUMBLING (SIZE 5 MINUTE)
GROUP BY card_number
HAVING count(*) > 3;
authorization_attempts possible_fraud
11
CREATE STREAM possible_fraud AS
SELECT card_number, count(*)
FROM authorization_attempts
WINDOW TUMBLING (SIZE 5 MINUTE)
GROUP BY card_number
HAVING count(*) > 3;
authorization_attempts possible_fraud
12
Streaming == Manipulating Data in Flight
13
Business
Applications
14
EcosystemsApp
Increasingly we build ecosystems
15
SOA / Microservices / EDA
Customer
Service
Shipping
Service
16
The Problem is DATA
17
Most services share the same core facts.
Catalog
Most services live
in here
18
So how do we share data between
services?
Orders
Service
Shipping
Service
Customer
Service
Webserver
19
Buying an iPad (with REST)
Submit
Order
shipOrder() getCustomer()
Orders
Service
Shipping
Service
Customer
Service
Webserver
20
Buying an iPad with Events
Message Broker (Kafka)
Notification Data is
replicated
(incrementally)
Submit
Order
Order
Created
Customer
Updated
Orders
Service
Shipping
Service
Customer
Service
Webserver
KAFKA
21
Events for Notification Only
Message Broker (Kafka)
Submit
Order
Order
Created
getCustomer()
REST
Notification
Orders
Service
Shipping
Service
Customer
Service
Webserver
KAFKA
22
Events for Data Locality
Customer
Updated
Submit
Order
Order
Created
Data is
replicated
Orders
Service
Shipping
Service
Customer
Service
Webserver
KAFKA
23
Events have two hats
Notification Data
replication
24
Events are the key to scalable service
ecosystems
25
Streaming is the toolset for dealing with
events as they move!
26
Kafka: a Streaming Platform
The Log ConnectorsConnectors
Producer Consumer
Streaming Engine
27
Kafka: a Streaming Platform
The Log ConnectorsConnectors
Producer Consumer
Streaming Engine
28
What is a Distributed Log?
29
Shard on the way in
Producing
Services
Kafka
Consuming
Services
30
Each shard is a queue
Producing
Services
Kafka
Consuming
Services
31
Consumers share load
Producing
Services
Kafka
Consuming
Services
32
Reduces to a globally ordered queue
33
Load Balanced Services
34
Fault Tolerant Services
35
Build ‘Always On’ Services
Rely on Fault
Tolerant Broker
36
Services can “Rewind & Replay” the log
Rewind & Replay
37
Compacted Log
(retains only latest version)
Version 3
Version 2
Version 1
Version 2
Version 1
Version 5
Version 4
Version 3
Version 2
Version 1
38
Kafka: a Streaming Platform
The Log ConnectorsConnectors
Producer Consumer
Streaming Engine
39
Kafka Connect
Kafka
Connect
Kafka
Connect
Kafka
40
Kafka: a Streaming Platform
The Log ConnectorsConnectors
Producer Consumer
Streaming Engine
41
A database engine for
data-in-flight
42
SELECT card_number, count(*)
FROM authorization_attempts
WINDOW (SIZE 5 MINUTE)
GROUP BY card_number
HAVING count(*) > 3;
Continuously Running Queries
43
Features: similar to database
query engine
JoinFilter
Aggr-
egate
View
Window
44
KAFKA
Buffer 5 mins
Windows
45
Lookup tables
KAFKA
46
Stateful Stream Processing
stream
Compacted
stream
Join
Stream
Table
KafkaKafka Streams
47
Scales Out
48
Embeddable
Orders Service
Kafka
Orders Service
Orders Service
49
Streaming is about
1. Processing data
incrementally
2. Moving data to where
it needs to be
processed (quickly
and efficiently)
On Notification
Data Replication
50
Kafka: a Streaming Platform
The Log ConnectorsConnectors
Producer Consumer
Streaming Engine
51
Steps to Streaming Services
52
1. Take Responsibility for the past and
evolve
53
Stay Simple. Take Responsibility for the past
Browser
Webserver
54
Evolve Forwards
Browser
Webserver
Orders
Service
55
2. Raise events. Don’t talk to services.
56
Events have two hats
Notification Data
replication
57
Raise events. Don’t talk to services
Browser
Webserver
Orders
Service
58
KAFKA
Order
Requested
Order
Received
Browser
Webserver
Orders
Service
Raise events. Don’t talk to services
59
KAFKA
Order
Requested
Order
Validated
Order
Received
Browser
Webserver
Orders
Service
Raise events. Don’t talk to services
60
KAFKA
Order
Requested
Order
Validated
Order
Received
Browser
Webserver
Orders
Service
Use Kafka as a Backbone for Events
61
3. Use Connect (& CDC) to evolve away
from legacy
62
KAFKA
Order
Requested
Order
Validated
Order
Received
Browser
Webserver
Orders
Service
Evolve away from Legacy
63KAFKA
Order
Requested
Order
Validated
Order
Received
Browser
Webserver
Orders
Service
Use the Database as a ‘Seam’
Connect
Products
64
4. Make use of Schemas
65KAFKA
Order
Requested
Order
Validated
Order
Received
Browser
Webserver
Orders
Service
Use Schemas to validate Backwards Compatibility
Connect
Products
Schema Registry
66
5. Use the Single Writer Principal
67KAFKA
Order
Requested
Order
Validated
Order
Received
Browser
Webserver
Orders
Service
Apply the single writer principal
Connect
Products
Schema Registry
Order
Completed
68
Orders
Service
Email
Service
T1 T2
T3
T4
REST
Service
T5
Single Writer Principal
69
Single Writer Principal
- Creates local consistency points in
the absence of Global Consistency
- Makes schema upgrades easier to
manage.
70
6. Store Datasets in the Log
71
Messaging that Remembers
Orders Customers
Payments
Stock
72
KAFKA
Order
Requested
Order
Validated
Order
Received
Browser
Webserver
Orders
Service
New Service, No Problem!
Connect
Products
Schema Registry
Order
Completed Repricing
73
Orders Customers
Payments
Stock
Single, Shared Source of Truth
74
But how do you query a log?
75
7. Move Data to Code
76
77
Connect
Order
Requested
Order
Validated
Order
Completed
Order
Received
Products
Browser
Webserver
Schema Registry
Orders
Service Stock
Stock
Materialize Stock ‘View’ Inside Service
KAFKA
78
Connect
Order
Requested
Order
Validated
Order
Completed
Order
Received
Products
Browser
Webserver
Schema Registry
Orders
Service Stock
Stock
Take only the data we need
KAFKA
79
Data Movement
Be realistic:
• Network is no longer the bottleneck
• Indexing is:
• In memory indexes help
• Keep datasets focused
80
8. Use the log instead as a ‘database’
81
Connect
Order
Requested
Order
Validated
Order
Completed
Order
Received
Products
Browser
Webserver
Schema Registry
Orders
Service
Reserved Stocks
Stock
Stock
Reserved Stocks
Apply Event Sourcing
KAFKA
Table
82
Connect
Order
Requested
Order
Validated
Order
Completed
Order
Received
Products
Browser
Webserver
Schema Registry
Orders
Service
Reserved Stocks
Stock
Stock
Reserved Stocks
Order Service Loads Reserved Stocks on Startup
KAFKA
83
Kafka has several features for reducing
the need to move data on startup
- Standby Replicas
- Disk Checkpoints
- Compacted topics
84
9. Use Transactions to tie All
Interactions Together
85
OrderRequested
(IPad)
2a. Order Validated
2c. Offset Commit
2b. IPad Reserved
Internal State:
Stock = 17
Reservations = 2
Tie Events & State with Transactions
86
Connect
TRANSACTION
Order
Requested
Order
Validated
Order
Completed
Order
Received
Products
Browser
Webserver
Schema Registry
Orders
Service
Reserved Stocks
Stock
Stock
Reserved Stocks
Transactions
KAFKA
87
10. Bridge the Sync/Async Divide with a
Streaming Ecosystem
88
POST
GET
Load
Balancer
ORDERSORDERS
OVTOPIC
Order
Validations
KAFKA
INVENTORY
Orders
Inventory
Fraud
Service
Order
Details
Service
Inventory
Service
(see previous figure)
Order
Created
Order
Validated
Orders View
Q in CQRS
Orders
Service
C is CQRS
Services in the Micro: Orders Service
Find the code online!
89
Orders Customers
Payments
Stock
Query Engine (Kstreams/KSQL)
Larger Ecosystems
HISTORICAL
EVENT STREAMS
90
Kafka
KAFKA
New York
Tokyo
London
Global / Disconnected Ecosystems
91
So…
92
Good architectures have little to do
with this:
93
It’s about how systems evolves over time
94
Request driven isn’t enough
• High coupling
• Hard to handle
async flows
• Hard to move and
join datasets.
95
Leverage the Duality of Events
Notification Data
replication
96
With a toolset built for data in flight
97
• Broadcast events
• Retain them in the log
• Evolve the event-stream with
streaming functions
• Recasting the event stream into
views when you need to query.
Event Driven Services
98
Confluent
Streaming
Platform
99
Thank You
@benstopford
Blog Series: https://www.confluent.io/blog/tag/microservices/

More Related Content

PDF
KSQL in Practice (Almog Gavra, Confluent) Kafka Summit London 2019
PDF
Exactly-once Data Processing with Kafka Streams - July 27, 2017
PDF
Apache kafka meet_up_zurich_at_swissre_from_zero_to_hero_with_kafka_connect_2...
PDF
Actors or Not: Async Event Architectures
PDF
Kafka Summit NYC 2017 - The Best Thing Since Partitioned Bread
PDF
Overcoming the Perils of Kafka Secret Sprawl (Tejal Adsul, Confluent) Kafka S...
PPTX
Top Ten Kafka® Configs
PDF
How to build 1000 microservices with Kafka and thrive
KSQL in Practice (Almog Gavra, Confluent) Kafka Summit London 2019
Exactly-once Data Processing with Kafka Streams - July 27, 2017
Apache kafka meet_up_zurich_at_swissre_from_zero_to_hero_with_kafka_connect_2...
Actors or Not: Async Event Architectures
Kafka Summit NYC 2017 - The Best Thing Since Partitioned Bread
Overcoming the Perils of Kafka Secret Sprawl (Tejal Adsul, Confluent) Kafka S...
Top Ten Kafka® Configs
How to build 1000 microservices with Kafka and thrive

What's hot (20)

PDF
KSQL - Stream Processing simplified!
PDF
Production Ready Kafka on Kubernetes (Devandra Tagare, Lyft) Kafka Summit SF ...
PDF
Streams, Tables, and Time in KSQL
PDF
Apache Kafka and KSQL in Action: Let's Build a Streaming Data Pipeline!
PPTX
Kafka Summit NYC 2017 - Easy, Scalable, Fault-tolerant Stream Processing with...
PDF
Building Scalable and Extendable Data Pipeline for Call of Duty Games: Lesson...
PDF
Introducing Kafka's Streams API
PDF
From Zero to Hero with Kafka Connect
PDF
SFBigAnalytics_20190724: Monitor kafka like a Pro
PDF
Flexible Authentication Strategies with SASL/OAUTHBEARER (Michael Kaminski, T...
PDF
Steps to Building a Streaming ETL Pipeline with Apache Kafka® and KSQL
PDF
Crossing the Streams: Rethinking Stream Processing with Kafka Streams and KSQL
PDF
KSQL Deep Dive - The Open Source Streaming Engine for Apache Kafka
PDF
ksqlDB: A Stream-Relational Database System
PDF
Building Stream Processing Applications with Apache Kafka's Exactly-Once Proc...
PDF
Apache Kafka in Adobe Ad Cloud's Analytics Platform
PDF
From Zero to Hero with Kafka Connect
PDF
Extending The Yahoo Streaming Benchmark to Apache Apex
PDF
Unlocking the world of stream processing with KSQL, the streaming SQL engine ...
PDF
Event Sourcing, Stream Processing and Serverless (Benjamin Stopford, Confluen...
KSQL - Stream Processing simplified!
Production Ready Kafka on Kubernetes (Devandra Tagare, Lyft) Kafka Summit SF ...
Streams, Tables, and Time in KSQL
Apache Kafka and KSQL in Action: Let's Build a Streaming Data Pipeline!
Kafka Summit NYC 2017 - Easy, Scalable, Fault-tolerant Stream Processing with...
Building Scalable and Extendable Data Pipeline for Call of Duty Games: Lesson...
Introducing Kafka's Streams API
From Zero to Hero with Kafka Connect
SFBigAnalytics_20190724: Monitor kafka like a Pro
Flexible Authentication Strategies with SASL/OAUTHBEARER (Michael Kaminski, T...
Steps to Building a Streaming ETL Pipeline with Apache Kafka® and KSQL
Crossing the Streams: Rethinking Stream Processing with Kafka Streams and KSQL
KSQL Deep Dive - The Open Source Streaming Engine for Apache Kafka
ksqlDB: A Stream-Relational Database System
Building Stream Processing Applications with Apache Kafka's Exactly-Once Proc...
Apache Kafka in Adobe Ad Cloud's Analytics Platform
From Zero to Hero with Kafka Connect
Extending The Yahoo Streaming Benchmark to Apache Apex
Unlocking the world of stream processing with KSQL, the streaming SQL engine ...
Event Sourcing, Stream Processing and Serverless (Benjamin Stopford, Confluen...
Ad

Similar to 10 essentials steps for kafka streaming services (20)

PDF
NDC London 2017 - The Data Dichotomy- Rethinking Data and Services with Streams
PDF
Building a Streaming Platform with Kafka
PDF
First Steps with Apache Kafka on Google Cloud Platform
PPTX
New Approaches for Fraud Detection on Apache Kafka and KSQL
PDF
Big Data LDN 2017: The Streaming Transformation
PDF
Streaming ETL to Elastic with Apache Kafka and KSQL
PDF
A Practical Deep Dive into Observability of Streaming Applications with Kosta...
PDF
KSQL – An Open Source Streaming Engine for Apache Kafka
PDF
Un'introduzione a Kafka Streams e KSQL... and why they matter!
PDF
Confluent Platform 5.5 + Apache Kafka 2.5 => New Features (JSON Schema, Proto...
PDF
Set your Data in Motion with Confluent & Apache Kafka Tech Talk Series LME
PDF
Beyond the brokers - A tour of the Kafka ecosystem
PDF
Beyond the Brokers: A Tour of the Kafka Ecosystem
PDF
JHipster conf 2019 - Kafka Ecosystem
PDF
Concepts and Patterns for Streaming Services with Kafka
PDF
Etl, esb, mq? no! es Apache Kafka®
PDF
What is Apache Kafka and What is an Event Streaming Platform?
PDF
EDA Meets Data Engineering – What's the Big Deal?
PDF
Build a Bridge to Cloud with Apache Kafka® for Data Analytics Cloud Services
PPTX
Bridge Your Kafka Streams to Azure Webinar
NDC London 2017 - The Data Dichotomy- Rethinking Data and Services with Streams
Building a Streaming Platform with Kafka
First Steps with Apache Kafka on Google Cloud Platform
New Approaches for Fraud Detection on Apache Kafka and KSQL
Big Data LDN 2017: The Streaming Transformation
Streaming ETL to Elastic with Apache Kafka and KSQL
A Practical Deep Dive into Observability of Streaming Applications with Kosta...
KSQL – An Open Source Streaming Engine for Apache Kafka
Un'introduzione a Kafka Streams e KSQL... and why they matter!
Confluent Platform 5.5 + Apache Kafka 2.5 => New Features (JSON Schema, Proto...
Set your Data in Motion with Confluent & Apache Kafka Tech Talk Series LME
Beyond the brokers - A tour of the Kafka ecosystem
Beyond the Brokers: A Tour of the Kafka Ecosystem
JHipster conf 2019 - Kafka Ecosystem
Concepts and Patterns for Streaming Services with Kafka
Etl, esb, mq? no! es Apache Kafka®
What is Apache Kafka and What is an Event Streaming Platform?
EDA Meets Data Engineering – What's the Big Deal?
Build a Bridge to Cloud with Apache Kafka® for Data Analytics Cloud Services
Bridge Your Kafka Streams to Azure Webinar
Ad

More from inovia (20)

PDF
10 tips for Redux at scale
PDF
Redux at scale
PDF
DocuSign's Road to react
PPTX
API Gateway: Nginx way
PPTX
Kafka: meetup microservice
PPTX
Microservice: starting point
PPTX
Correlation id (tid)
PPTX
Meetic back end redesign - Meetup microservices
PPTX
Security in microservices architectures
PPTX
Building a Secure, Performant Network Fabric for Microservice Applications
PPTX
Microservices vs SOA
PPTX
CQRS, an introduction by JC Bohin
PPTX
Domain Driven Design
PPTX
Oauth2, open-id connect with microservices
PPTX
You probably don't need microservices
PPTX
Api Gateway - What's the use of an api gateway?
PDF
Steam Learn: An introduction to Redis
PDF
Steam Learn: Speedrun et TAS
PDF
Steam Learn: Asynchronous Javascript
PDF
Steam Learn: Cheat sheet for Vim
10 tips for Redux at scale
Redux at scale
DocuSign's Road to react
API Gateway: Nginx way
Kafka: meetup microservice
Microservice: starting point
Correlation id (tid)
Meetic back end redesign - Meetup microservices
Security in microservices architectures
Building a Secure, Performant Network Fabric for Microservice Applications
Microservices vs SOA
CQRS, an introduction by JC Bohin
Domain Driven Design
Oauth2, open-id connect with microservices
You probably don't need microservices
Api Gateway - What's the use of an api gateway?
Steam Learn: An introduction to Redis
Steam Learn: Speedrun et TAS
Steam Learn: Asynchronous Javascript
Steam Learn: Cheat sheet for Vim

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Big Data Technologies - Introduction.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
KodekX | Application Modernization Development
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Modernizing your data center with Dell and AMD
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
Chapter 3 Spatial Domain Image Processing.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The AUB Centre for AI in Media Proposal.docx
Building Integrated photovoltaic BIPV_UPV.pdf
NewMind AI Monthly Chronicles - July 2025
Big Data Technologies - Introduction.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Understanding_Digital_Forensics_Presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
MYSQL Presentation for SQL database connectivity
KodekX | Application Modernization Development
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Modernizing your data center with Dell and AMD
Unlocking AI with Model Context Protocol (MCP)
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Electronic commerce courselecture one. Pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation

10 essentials steps for kafka streaming services