SlideShare a Scribd company logo
Event-driven microservices
using Apache Kafka
Andrew Schofield
Chief Architect, Event Streams
IBM Hursley Park
© 2019 IBM Corporation
What and why microservices?
Microservices is a technique for structuring an
application as a collection of services:
• Self-contained with clear interfaces and a
distinct purpose
• Loosely coupled – communicate over a
network
• Independently deployable, scalable,
maintainable and testable
© 2019 IBM Corporation
Microservices ApplicationMonolithic Application
Being event-driven is different
© 2019 IBM Corporation
Source: Gartner - From data-centric to event-centric IT priority
Why event-driven?
• Proper loose coupling means asynchronous communication
• Enables responsive applications
• In the real world, things often take time to complete
© 2019 IBM Corporation
Event-driven microservices
• Microservices communicate primarily
using events, with APIs where required
• Microservices can produce and consume
events using the publish/subscribe
pattern
• Events are handled by an event
backbone
• Data is eventually consistent
© 2019 IBM Corporation
Microservice
Microservice
Microservice
Microservice
Microservice
Event
backbone
Publish
Service
discoveryMicroservice
Microservice
Microservice
Subscribe
Subscribe
API
API
Publish
JSON /
HTTP
JSON / HTTP
Microservices
application
Apache Kafka is an Open-Source Streaming Platform
© 2019 IBM Corporation
PUBLISH & SUBSCRIBE
Read and write streams of events, like a
traditional messaging system.
PROCESS
Support scalable stream processing applications
that react to events in real-time.
STORE
Store streams of data safely in a distributed,
replicated, fault-tolerant cluster.
https://kafka.apache.org/
Kafka
Cluster
Producer ProducerProducer
Consumer ConsumerConsumer
Stream
Processor
Stream
Processor
Source
Connector
Sink Connector
Event-driven terminology
Event A message usually representing a fact at a particular time
Event stream A continuous, ordered, unbounded sequence of events
Stream processing Computation optimized for continuous processing, often with state
Stream history The historical sequence of the events on an event stream
© 2019 IBM Corporation
Apache Kafka as the event backbone
© 2019 IBM Corporation
Apache Kafka as the event backbone
© 2019 IBM Corporation
Microservice
Microservice
Apache Kafka as the event backbone
© 2019 IBM Corporation
1
Building Blocks
1 :: Event sources
Microservice
Microservice
Apache Kafka as the event backbone
© 2019 IBM Corporation
1
2
Building Blocks
1 :: Event sources
2 :: Stream processing
Microservice
Microservice
Apache Kafka as the event backbone
© 2019 IBM Corporation
1
2 App
3
Building Blocks
1 :: Event sources
2 :: Stream processing
3 :: Event archive
Microservice
Microservice
Apache Kafka as the event backbone
© 2019 IBM Corporation
App
1
2
3
4
Building Blocks
1 :: Event sources
2 :: Stream processing
3 :: Event archive
4 :: Notifications
Microservice
Microservice
How to get started
• You could run an event storming workshop
https://www.ibm.com/cloud/garage/architectures/eventDrivenArchitecture/event-storming-methodology
• Identify:
• Events
• Actors
• Data
• Commands
© 2019 IBM Corporation
A simple stream processing example
© 2019 IBM Corporation
Event backbone
Transactions
A simple stream processing example
© 2019 IBM Corporation
Event backbone
Transactions
Alerts
A simple stream processing example
© 2019 IBM Corporation
Event backbone
Transactions
Alerts
SMS alerts
Email alerts
Push alerts
A simple stream processing example
© 2019 IBM Corporation
Event backbone
Send SMS
Transactions
Alerts
Send emails
Send push
notifications
SMS alerts
Email alerts
Push alerts
© 2019 IBM Corporation
A more complex event-driven example
https://ibm-cloud-architecture.github.io/refarch-kc/design/readme/
A more complex example – component view
© 2019 IBM Corporation
Fleet
microservice
Containers
microservice
Voyages
microservice
Orders
microservice
APIAPI
A more complex example – component view
© 2019 IBM Corporation
Fleet
microservice
Containers
microservice
Voyages
microservice
Orders
microservice
APIAPI
A more complex example – component view
© 2019 IBM Corporation
Event backbone
ships containers orders voyages
Fleet
microservice
Containers
microservice
Voyages
microservice
Orders
microservice
APIAPI
A more complex example – component view
© 2019 IBM Corporation
Event backbone
ships containers problems orders voyages
Fleet
microservice
Containers
microservice
Voyages
microservice
Orders
microservice
Streaming
analytics
APIAPI
Patterns for event-driven microservices
• You want:
• Loose coupling
• Data consistency
• Efficient queries
© 2019 IBM Corporation
Patterns for event-driven microservices
• You want:
• Loose coupling
• Data consistency
• Efficient queries
• You don’t want:
• Chaos
© 2019 IBM Corporation
Patterns for event-driven microservices
• You want:
• Loose coupling
• Data consistency
• Efficient queries
• You don’t want:
• Chaos
• You need PATTERNS
© 2019 IBM Corporation
Pattern – Database per service
• Each microservice persists its own data
+ Protects independence of the microservice against external change
- Introduces complexity for data consistency across microservices
Event backbone
ships containers problems orders voyages
Fleet
microservice
Containers
microservice
Voyages
microservice
Orders
microservice
© 2019 IBM Corporation
Kafka log compaction for data replication
© 2019 IBM Corporation
0
key:a
val:A1
1
key:b
val:B1
2
key:a
val:A2
3
key:c
val:C1
Partition 0
4
key:c
val:C2
5
key:b
val:
Producer
writes
Consumer
takes latest
values and
builds own
data store
reads
Key Value
a A2
b <deleted>
c C2
Old New
Source change log Read
Kafka log compaction for data replication
© 2019 IBM Corporation
0
key:a
val:A1
1
key:b
val:B1
2
key:a
val:A2
3
key:c
val:C1
Partition 0
4
key:c
val:C2
5
key:b
val:
2
key:a
val:A2
4
key:c
val:C2
5
key:b
val:
Periodic compaction eliminates duplicate keys
to minimize storage
Partition 0
(rewritten)
Key Value
a A2
b <deleted>
c C2
Pattern – Event sourcing
• Every state change is captured as an event stored in sequence
+ Publishing events is atomic
- Event store is hard to query efficiently
© 2019 IBM Corporation
OrderCreated
OrderUpdated
OrderUpdated
OrderConfirmed
OrderShipped
OrderDelivered
OrderInTransit
Orders
microservice
Orders
DB
Command
handler
USER
Time
OrderPending
OrderBooked
OrderAssigned
Pattern – Sagas
• Orchestration of multi-step operations across microservices
+ Data consistency across microservices without distributed transactions
- Programming can be complex, particularly for failure compensation
© 2019 IBM Corporation
Event backbone
Fleet
microservice
Containers
microservice
Voyages
microservice
Orders
microservice
1 2 3 4 5
Pattern – CQRS
• Command Query Responsibility Segregation
+ Atomic writes and efficient reads at the same time
- Complex to program correctly
© 2019 IBM Corporation
Event backbone
1 2 3 4 5
Fleet MS
WRITE MODEL
Fleet MS READ
MODEL
Write-optimized
store
Read-optimized
store
Write API Read API
Summary
• Event-driven microservices offer an effective way to build loosely-
coupled applications
• Techniques such as event storming can be used to derive the objects,
commands and events in an application
• Patterns such as event sourcing and sagas make the complexity
manageable
© 2019 IBM Corporation
Event driven microservices

More Related Content

PPTX
Event-driven microservices
PDF
Introduction to Event-Driven Architecture
PDF
Monolithic vs Microservices Architecture
PDF
MuleSoft PKO - C4E and Platform Insights
PDF
Microservice Architecture
PPTX
Event Driven Microservices architecture
PPTX
Adopting OpenTelemetry
PDF
SRE & Kubernetes
Event-driven microservices
Introduction to Event-Driven Architecture
Monolithic vs Microservices Architecture
MuleSoft PKO - C4E and Platform Insights
Microservice Architecture
Event Driven Microservices architecture
Adopting OpenTelemetry
SRE & Kubernetes

What's hot (20)

PDF
Design patterns for microservice architecture
PPTX
Microservice architecture design principles
PPTX
Microservices Architecture & Testing Strategies
PPSX
Agile, User Stories, Domain Driven Design
KEY
Event Driven Architecture
PDF
Event-Driven Architecture (EDA)
PPTX
Introduction to Distributed Tracing
PDF
Process Oriented Architecture
PDF
Bizweb Microservices Architecture
PPTX
Microservices Architecture & Testing Strategies
PPTX
Designing Apps for Runtime Fabric: Logging, Monitoring & Object Store Persist...
PDF
Cloud-Native Observability
PPT
Three layer API Design Architecture
PPTX
MSA ( Microservices Architecture ) 발표 자료 다운로드
PPSX
Microservices Testing Strategies JUnit Cucumber Mockito Pact
PDF
Microservice Architecture | Microservices Tutorial for Beginners | Microservi...
PPTX
Microservices Part 3 Service Mesh and Kafka
PPTX
MuleSoft Architecture Presentation
PPTX
Introduction To Microservices
PDF
21 Story Splitting Patterns
Design patterns for microservice architecture
Microservice architecture design principles
Microservices Architecture & Testing Strategies
Agile, User Stories, Domain Driven Design
Event Driven Architecture
Event-Driven Architecture (EDA)
Introduction to Distributed Tracing
Process Oriented Architecture
Bizweb Microservices Architecture
Microservices Architecture & Testing Strategies
Designing Apps for Runtime Fabric: Logging, Monitoring & Object Store Persist...
Cloud-Native Observability
Three layer API Design Architecture
MSA ( Microservices Architecture ) 발표 자료 다운로드
Microservices Testing Strategies JUnit Cucumber Mockito Pact
Microservice Architecture | Microservices Tutorial for Beginners | Microservi...
Microservices Part 3 Service Mesh and Kafka
MuleSoft Architecture Presentation
Introduction To Microservices
21 Story Splitting Patterns
Ad

Similar to Event driven microservices (20)

PDF
Kafka with IBM Event Streams - Technical Presentation
PDF
Creating Microservices Application with IBM Cloud Private (ICP) - introductio...
PPT
IBM Cloud UCC Talk, 8th December 2020 - Cloud Native, Microservices, and Serv...
PDF
The resurgence of event driven architecture
PDF
IBM Hybrid Cloud Integration UCC Talk, 23rd November 2021 - Cloud Application...
PDF
Streaming Sensor Data Slides_Virender
PPTX
Jfokus - Reacting to an event-driven world
PPT
Developing for Hybrid Cloud with Bluemix
PPTX
JSpring Virtual 2020 - Reacting to an event-driven world
PPTX
IBM Cloud Integration Platform Introduction - Integration Tech Conference
PDF
Introduction to Serverless Computing - OOP Munich
PDF
Modern Applications Development on AWS
PDF
App Modernization
PDF
IBM BlueMix Presentation - Paris Meetup 17th Sept. 2014
PDF
Open Standards Enabling Digital Transformation
PDF
Sharing and Deploying Data Science with KNIME Server
PPTX
IBM Relay 2015: Opening Keynote
 
PPTX
DevNexus - Reacting to an event driven world
PDF
Montreal Cloud Computing Meetup - Feb 9th, 2016
PPT
Mainframe cloud computing presentation
Kafka with IBM Event Streams - Technical Presentation
Creating Microservices Application with IBM Cloud Private (ICP) - introductio...
IBM Cloud UCC Talk, 8th December 2020 - Cloud Native, Microservices, and Serv...
The resurgence of event driven architecture
IBM Hybrid Cloud Integration UCC Talk, 23rd November 2021 - Cloud Application...
Streaming Sensor Data Slides_Virender
Jfokus - Reacting to an event-driven world
Developing for Hybrid Cloud with Bluemix
JSpring Virtual 2020 - Reacting to an event-driven world
IBM Cloud Integration Platform Introduction - Integration Tech Conference
Introduction to Serverless Computing - OOP Munich
Modern Applications Development on AWS
App Modernization
IBM BlueMix Presentation - Paris Meetup 17th Sept. 2014
Open Standards Enabling Digital Transformation
Sharing and Deploying Data Science with KNIME Server
IBM Relay 2015: Opening Keynote
 
DevNexus - Reacting to an event driven world
Montreal Cloud Computing Meetup - Feb 9th, 2016
Mainframe cloud computing presentation
Ad

Recently uploaded (20)

PPTX
Online Work Permit System for Fast Permit Processing
PPTX
Introduction to Artificial Intelligence
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
history of c programming in notes for students .pptx
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
top salesforce developer skills in 2025.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
Online Work Permit System for Fast Permit Processing
Introduction to Artificial Intelligence
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
history of c programming in notes for students .pptx
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PTS Company Brochure 2025 (1).pdf.......
Adobe Illustrator 28.6 Crack My Vision of Vector Design
ManageIQ - Sprint 268 Review - Slide Deck
CHAPTER 2 - PM Management and IT Context
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
ISO 45001 Occupational Health and Safety Management System
Upgrade and Innovation Strategies for SAP ERP Customers
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Design an Analysis of Algorithms II-SECS-1021-03
VVF-Customer-Presentation2025-Ver1.9.pptx
top salesforce developer skills in 2025.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
2025 Textile ERP Trends: SAP, Odoo & Oracle

Event driven microservices

  • 1. Event-driven microservices using Apache Kafka Andrew Schofield Chief Architect, Event Streams IBM Hursley Park © 2019 IBM Corporation
  • 2. What and why microservices? Microservices is a technique for structuring an application as a collection of services: • Self-contained with clear interfaces and a distinct purpose • Loosely coupled – communicate over a network • Independently deployable, scalable, maintainable and testable © 2019 IBM Corporation Microservices ApplicationMonolithic Application
  • 3. Being event-driven is different © 2019 IBM Corporation Source: Gartner - From data-centric to event-centric IT priority
  • 4. Why event-driven? • Proper loose coupling means asynchronous communication • Enables responsive applications • In the real world, things often take time to complete © 2019 IBM Corporation
  • 5. Event-driven microservices • Microservices communicate primarily using events, with APIs where required • Microservices can produce and consume events using the publish/subscribe pattern • Events are handled by an event backbone • Data is eventually consistent © 2019 IBM Corporation Microservice Microservice Microservice Microservice Microservice Event backbone Publish Service discoveryMicroservice Microservice Microservice Subscribe Subscribe API API Publish JSON / HTTP JSON / HTTP Microservices application
  • 6. Apache Kafka is an Open-Source Streaming Platform © 2019 IBM Corporation PUBLISH & SUBSCRIBE Read and write streams of events, like a traditional messaging system. PROCESS Support scalable stream processing applications that react to events in real-time. STORE Store streams of data safely in a distributed, replicated, fault-tolerant cluster. https://kafka.apache.org/ Kafka Cluster Producer ProducerProducer Consumer ConsumerConsumer Stream Processor Stream Processor Source Connector Sink Connector
  • 7. Event-driven terminology Event A message usually representing a fact at a particular time Event stream A continuous, ordered, unbounded sequence of events Stream processing Computation optimized for continuous processing, often with state Stream history The historical sequence of the events on an event stream © 2019 IBM Corporation
  • 8. Apache Kafka as the event backbone © 2019 IBM Corporation
  • 9. Apache Kafka as the event backbone © 2019 IBM Corporation Microservice Microservice
  • 10. Apache Kafka as the event backbone © 2019 IBM Corporation 1 Building Blocks 1 :: Event sources Microservice Microservice
  • 11. Apache Kafka as the event backbone © 2019 IBM Corporation 1 2 Building Blocks 1 :: Event sources 2 :: Stream processing Microservice Microservice
  • 12. Apache Kafka as the event backbone © 2019 IBM Corporation 1 2 App 3 Building Blocks 1 :: Event sources 2 :: Stream processing 3 :: Event archive Microservice Microservice
  • 13. Apache Kafka as the event backbone © 2019 IBM Corporation App 1 2 3 4 Building Blocks 1 :: Event sources 2 :: Stream processing 3 :: Event archive 4 :: Notifications Microservice Microservice
  • 14. How to get started • You could run an event storming workshop https://www.ibm.com/cloud/garage/architectures/eventDrivenArchitecture/event-storming-methodology • Identify: • Events • Actors • Data • Commands © 2019 IBM Corporation
  • 15. A simple stream processing example © 2019 IBM Corporation Event backbone Transactions
  • 16. A simple stream processing example © 2019 IBM Corporation Event backbone Transactions Alerts
  • 17. A simple stream processing example © 2019 IBM Corporation Event backbone Transactions Alerts SMS alerts Email alerts Push alerts
  • 18. A simple stream processing example © 2019 IBM Corporation Event backbone Send SMS Transactions Alerts Send emails Send push notifications SMS alerts Email alerts Push alerts
  • 19. © 2019 IBM Corporation A more complex event-driven example https://ibm-cloud-architecture.github.io/refarch-kc/design/readme/
  • 20. A more complex example – component view © 2019 IBM Corporation Fleet microservice Containers microservice Voyages microservice Orders microservice APIAPI
  • 21. A more complex example – component view © 2019 IBM Corporation Fleet microservice Containers microservice Voyages microservice Orders microservice APIAPI
  • 22. A more complex example – component view © 2019 IBM Corporation Event backbone ships containers orders voyages Fleet microservice Containers microservice Voyages microservice Orders microservice APIAPI
  • 23. A more complex example – component view © 2019 IBM Corporation Event backbone ships containers problems orders voyages Fleet microservice Containers microservice Voyages microservice Orders microservice Streaming analytics APIAPI
  • 24. Patterns for event-driven microservices • You want: • Loose coupling • Data consistency • Efficient queries © 2019 IBM Corporation
  • 25. Patterns for event-driven microservices • You want: • Loose coupling • Data consistency • Efficient queries • You don’t want: • Chaos © 2019 IBM Corporation
  • 26. Patterns for event-driven microservices • You want: • Loose coupling • Data consistency • Efficient queries • You don’t want: • Chaos • You need PATTERNS © 2019 IBM Corporation
  • 27. Pattern – Database per service • Each microservice persists its own data + Protects independence of the microservice against external change - Introduces complexity for data consistency across microservices Event backbone ships containers problems orders voyages Fleet microservice Containers microservice Voyages microservice Orders microservice © 2019 IBM Corporation
  • 28. Kafka log compaction for data replication © 2019 IBM Corporation 0 key:a val:A1 1 key:b val:B1 2 key:a val:A2 3 key:c val:C1 Partition 0 4 key:c val:C2 5 key:b val: Producer writes Consumer takes latest values and builds own data store reads Key Value a A2 b <deleted> c C2 Old New Source change log Read
  • 29. Kafka log compaction for data replication © 2019 IBM Corporation 0 key:a val:A1 1 key:b val:B1 2 key:a val:A2 3 key:c val:C1 Partition 0 4 key:c val:C2 5 key:b val: 2 key:a val:A2 4 key:c val:C2 5 key:b val: Periodic compaction eliminates duplicate keys to minimize storage Partition 0 (rewritten) Key Value a A2 b <deleted> c C2
  • 30. Pattern – Event sourcing • Every state change is captured as an event stored in sequence + Publishing events is atomic - Event store is hard to query efficiently © 2019 IBM Corporation OrderCreated OrderUpdated OrderUpdated OrderConfirmed OrderShipped OrderDelivered OrderInTransit Orders microservice Orders DB Command handler USER Time OrderPending OrderBooked OrderAssigned
  • 31. Pattern – Sagas • Orchestration of multi-step operations across microservices + Data consistency across microservices without distributed transactions - Programming can be complex, particularly for failure compensation © 2019 IBM Corporation Event backbone Fleet microservice Containers microservice Voyages microservice Orders microservice 1 2 3 4 5
  • 32. Pattern – CQRS • Command Query Responsibility Segregation + Atomic writes and efficient reads at the same time - Complex to program correctly © 2019 IBM Corporation Event backbone 1 2 3 4 5 Fleet MS WRITE MODEL Fleet MS READ MODEL Write-optimized store Read-optimized store Write API Read API
  • 33. Summary • Event-driven microservices offer an effective way to build loosely- coupled applications • Techniques such as event storming can be used to derive the objects, commands and events in an application • Patterns such as event sourcing and sagas make the complexity manageable © 2019 IBM Corporation