SlideShare a Scribd company logo
Apache Kafka as
Message Queue
for your microservices and other occasions
Michael Reinsch

michael@movingfast.io

at Rug::B Feb 2018
Message Queues?
Message Queue
• Queue acts as buffer

• Indirect communication

• Multiple consumer processes

• Multiple producers
Message queueProducer
Hello! Hello!
Consumer
With Exchange
• Queue is strongly coupled to consumer

• Exchange needs to know system topology

• Adding additional consumers is relatively expensive
Message queue
Producer
Hello!
Hello!
Hello!
X
Exchange
Consumer X
Consumer Y
Apache Kafka
• Topics are always multi-publisher and multi-subscriber

• Adding / removing consumers is very cheap
Topic
Consumer X
Hello!
Hello!
Greets Consumer Y
Hello!
Producer
Apache Kafka:
Distributed Streaming Platform
Key capabilities:

• Publish and subscribe to streams of records

• Store streams of records in a fault-tolerant way

• Process streams of records as they occur
Topics
• ‘Category’ for a stream of records

• Producers only append

• All published records are retained
for a configurable retention period

• Consumers use offset pointers to
store their last processed event
Topic Partitions
• Topic can have many partitions

• Partitions are an ordered,
immutable sequence of records

• Partition size is limited by disk
space

• Partitions are replicated for fault-
tolerance

• Unit of parallelism
Consumer Groups
• Consumers can form consumer groups

• Each consumer in a group is the
exclusive consumer of a “fair share” of
partitions

• Strong ordering guaranty within a topic
partition
TopicProducer
Hello!
Hello!
greets
Hello!
Consumer Group X
Consumer Group Y
Demo!
Scripts at github.com/mreinsch/kafka_demo
Let’s compare
Kafka vs. REST API
• Asynchronous, indirect communication

• Less coupling in producer -> easier to extend

• Fewer critical paths
Topic
Producer
Ex: new users
Ex: new orders
Consumer Group X
Consumer Group Y
Kafka vs. job queue
• Similar, but different

• Less coupling in producer
Topic
Producer
Ex: new users
Ex: new orders
Consumer Group X
Consumer Group Y
Challenges
when using Kafka (or other message queues) 

for your microservices
Asynchronicity
• Example: existing clients use REST API, but processing is done by
some microservice

• Possible solution:

• Return `202 Accepted` pointing to a job resource

• Job resource returns status / actual resource location when
finished

• Use another Kafka topic to communicate job status changes

• http://restcookbook.com/Resources/asynchroneous-operations/
More Asynchronicity
• Example: need data from another service

• Pragmatic solution:

• Just keep using a REST API

• Scalable solution:

• Combine REST API with local cache which gets
invalidated by an asynchronous event
Error handling
• You need strategy for handling errors to avoid consumer
processes getting stuck

• ruby-kafka doesn’t provide this - higher level libs exist

• kafka_worker, minimalist worker abstraction

• Pushes message+metadata into error topic on hard
errors

• Work in progress…
Event Loops
• Example: 

• Consumer A: consumes topic-a, publishes to topic-b

• Consumer B: consumes topic-b, publishes to topic-a

• Usually much more complex…

• We haven’t had one yet, but with more services it
becomes more likely
Some Tips
• Add some common metadata to each event, such as
Origin-UUID (pass on when triggering other events),
Seen-By

• Document which service consumes / produces which
events

• Only include data relevant to the event, other data should
be fetched as needed
Get in touch
Michael Reinsch

michael@movingfast.io

GitHub: mreinsch
Looking
for new
interesting
projects
/ opportunities!

More Related Content

PDF
Messaging queue - Kafka
PPTX
Kafka 101
PPTX
Apache Kafka
PDF
PPTX
Esxi troubleshooting
PPTX
GFS & HDFS Introduction
PPTX
Apache Ranger Hive Metastore Security
Messaging queue - Kafka
Kafka 101
Apache Kafka
Esxi troubleshooting
GFS & HDFS Introduction
Apache Ranger Hive Metastore Security

What's hot (20)

PDF
Kafka: All an engineer needs to know
PDF
Xen & virtualization
PPTX
Html5 for mobiles
PDF
Cloud Service Life-cycle Management
PDF
Apache Kafka Introduction
PDF
Google Spanner
PPTX
Gfs vs hdfs
PPT
Server virtualization by VMWare
PDF
Kafka Overview
PDF
Real-Life Use Cases & Architectures for Event Streaming with Apache Kafka
PDF
Data Warehouse on Kubernetes: lessons from Clickhouse Operator
PDF
Confluent REST Proxy and Schema Registry (Concepts, Architecture, Features)
PDF
Cloud service lifecycle management
PDF
Multi cluster, multitenant and hierarchical kafka messaging service slideshare
PPT
Hadoop Security Architecture
PDF
Apache StreamPipes – Flexible Industrial IoT Management
PPTX
Session 23 - Kafka and Zookeeper
PPTX
IoT:what about data storage?
PPTX
Unit-I_part-II_Virtualization.pptx
PDF
Virtualization Technology Overview
Kafka: All an engineer needs to know
Xen & virtualization
Html5 for mobiles
Cloud Service Life-cycle Management
Apache Kafka Introduction
Google Spanner
Gfs vs hdfs
Server virtualization by VMWare
Kafka Overview
Real-Life Use Cases & Architectures for Event Streaming with Apache Kafka
Data Warehouse on Kubernetes: lessons from Clickhouse Operator
Confluent REST Proxy and Schema Registry (Concepts, Architecture, Features)
Cloud service lifecycle management
Multi cluster, multitenant and hierarchical kafka messaging service slideshare
Hadoop Security Architecture
Apache StreamPipes – Flexible Industrial IoT Management
Session 23 - Kafka and Zookeeper
IoT:what about data storage?
Unit-I_part-II_Virtualization.pptx
Virtualization Technology Overview
Ad

Similar to Apache Kafka as Message Queue for your microservices and other occasions (20)

PDF
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
PPTX
kafka_session_updated.pptx
PPTX
Kafka 0.8.0 Presentation to Atlanta Java User's Group March 2013
PPTX
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
PDF
Non-Kafkaesque Apache Kafka - Yottabyte 2018
PDF
Apache Kafka - Scalable Message-Processing and more !
PDF
Uber: Kafka Consumer Proxy
PDF
RabbitMQ vs Apache Kafka - Part 1
PDF
apachekafka-160907180205.pdf
PPTX
Introduction to Kafka and Event-Driven
PDF
Introduction to Kafka and Event-Driven
PPTX
Apache kafka
PPTX
Kafka tutorial
PPSX
Event Sourcing & CQRS, Kafka, Rabbit MQ
PPTX
Apache kafka
PDF
Apache Kafka - Scalable Message Processing and more!
DOCX
KAFKA Quickstart
PDF
Apache Kafka Scalable Message Processing and more!
PDF
Streaming Analytics unit 2 notes for engineers
PPTX
Microservices interaction at scale using Apache Kafka
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
kafka_session_updated.pptx
Kafka 0.8.0 Presentation to Atlanta Java User's Group March 2013
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
Non-Kafkaesque Apache Kafka - Yottabyte 2018
Apache Kafka - Scalable Message-Processing and more !
Uber: Kafka Consumer Proxy
RabbitMQ vs Apache Kafka - Part 1
apachekafka-160907180205.pdf
Introduction to Kafka and Event-Driven
Introduction to Kafka and Event-Driven
Apache kafka
Kafka tutorial
Event Sourcing & CQRS, Kafka, Rabbit MQ
Apache kafka
Apache Kafka - Scalable Message Processing and more!
KAFKA Quickstart
Apache Kafka Scalable Message Processing and more!
Streaming Analytics unit 2 notes for engineers
Microservices interaction at scale using Apache Kafka
Ad

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Big Data Technologies - Introduction.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation theory and applications.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
Review of recent advances in non-invasive hemoglobin estimation
Assigned Numbers - 2025 - Bluetooth® Document
Big Data Technologies - Introduction.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Reach Out and Touch Someone: Haptics and Empathic Computing
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation_ Review paper, used for researhc scholars
The Rise and Fall of 3GPP – Time for a Sabbatical?
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation theory and applications.pdf
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Per capita expenditure prediction using model stacking based on satellite ima...
Digital-Transformation-Roadmap-for-Companies.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf

Apache Kafka as Message Queue for your microservices and other occasions

  • 1. Apache Kafka as Message Queue for your microservices and other occasions Michael Reinsch michael@movingfast.io at Rug::B Feb 2018
  • 3. Message Queue • Queue acts as buffer • Indirect communication • Multiple consumer processes • Multiple producers Message queueProducer Hello! Hello! Consumer
  • 4. With Exchange • Queue is strongly coupled to consumer • Exchange needs to know system topology • Adding additional consumers is relatively expensive Message queue Producer Hello! Hello! Hello! X Exchange Consumer X Consumer Y
  • 5. Apache Kafka • Topics are always multi-publisher and multi-subscriber • Adding / removing consumers is very cheap Topic Consumer X Hello! Hello! Greets Consumer Y Hello! Producer
  • 6. Apache Kafka: Distributed Streaming Platform Key capabilities: • Publish and subscribe to streams of records • Store streams of records in a fault-tolerant way • Process streams of records as they occur
  • 7. Topics • ‘Category’ for a stream of records • Producers only append • All published records are retained for a configurable retention period • Consumers use offset pointers to store their last processed event
  • 8. Topic Partitions • Topic can have many partitions • Partitions are an ordered, immutable sequence of records • Partition size is limited by disk space • Partitions are replicated for fault- tolerance • Unit of parallelism
  • 9. Consumer Groups • Consumers can form consumer groups • Each consumer in a group is the exclusive consumer of a “fair share” of partitions • Strong ordering guaranty within a topic partition TopicProducer Hello! Hello! greets Hello! Consumer Group X Consumer Group Y
  • 12. Kafka vs. REST API • Asynchronous, indirect communication • Less coupling in producer -> easier to extend • Fewer critical paths Topic Producer Ex: new users Ex: new orders Consumer Group X Consumer Group Y
  • 13. Kafka vs. job queue • Similar, but different • Less coupling in producer Topic Producer Ex: new users Ex: new orders Consumer Group X Consumer Group Y
  • 14. Challenges when using Kafka (or other message queues) 
 for your microservices
  • 15. Asynchronicity • Example: existing clients use REST API, but processing is done by some microservice • Possible solution: • Return `202 Accepted` pointing to a job resource • Job resource returns status / actual resource location when finished • Use another Kafka topic to communicate job status changes • http://restcookbook.com/Resources/asynchroneous-operations/
  • 16. More Asynchronicity • Example: need data from another service • Pragmatic solution: • Just keep using a REST API • Scalable solution: • Combine REST API with local cache which gets invalidated by an asynchronous event
  • 17. Error handling • You need strategy for handling errors to avoid consumer processes getting stuck • ruby-kafka doesn’t provide this - higher level libs exist • kafka_worker, minimalist worker abstraction • Pushes message+metadata into error topic on hard errors • Work in progress…
  • 18. Event Loops • Example: • Consumer A: consumes topic-a, publishes to topic-b • Consumer B: consumes topic-b, publishes to topic-a • Usually much more complex… • We haven’t had one yet, but with more services it becomes more likely
  • 19. Some Tips • Add some common metadata to each event, such as Origin-UUID (pass on when triggering other events), Seen-By • Document which service consumes / produces which events • Only include data relevant to the event, other data should be fetched as needed
  • 20. Get in touch Michael Reinsch michael@movingfast.io GitHub: mreinsch Looking for new interesting projects / opportunities!