SlideShare a Scribd company logo
BUILDING
EVENT-DRIVEN SYSTEMS
WITH APACHE KAFKA
BRIAN RITCHIE
CTO, XEOHEALTH
2016
@brian_ritchie
brian.ritchie@gmail.com
http://www.dotnetpowered.com
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
EVENT-DRIVEN SYSTEMS
Definition
Event-driven architecture, also known as message-driven architecture, is
a software architecture pattern promoting the production, detection,
consumption of, and reaction to events. An event can be defined as "a
significant change in state".
https://en.wikipedia.org/wiki/Event-driven_architecture
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
EVENT-DRIVEN SYSTEMS ARE ABOUT UNLOCKING DATA
• Data is the driving force behind innovation
• Event-driven systems allow you to unlock the data –
and unlock the innovation.
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
EVENTS ARE THE “WHAT HAPPENED” DATA
• It’s about recording “what happened”, but not coupling it to the “how”
• It’s the “transactions” of your system
• Product Views
• Completed Sales
• Page Visits
• Site Logins
• Shipping Notifications
• Inventory Received
• IoT
• …and much more
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
EVENTS – A HEALTHCARE EXAMPLE
Event
Stream
Healthcare
Claim
Fraud
Detection
Data Lake
Archive
Disease
Trending
Contract &
Pricing
More… You don’t need to
integrate with
consumers or even
know about a future
uses of your data
What happened?
A patient received a set of
services
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
EVENT-DRIVEN SYSTEMS MAKE SCALABILITY EASIER
• Scalability of processing
• Scalability of design
• Scalability of change
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
EVENT-DRIVEN SYSTEMS REQUIRE INFRASTRUCTURE
• Queue / Stream
• Persistence
• Distribution
• Pub / Sub
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE KAFKA IS THE INFRASTRUCTURE
• Apache Kafka is publish-subscribe messaging rethought as a distributed
commit log.
• Developed by LinkedIn
• Written in Java
• Open Sourced in 2011 and graduated Apache Incubator in 2012
• Unique features of Kafka
• Super fast
• Distributed & Replicated out of the box
• Extremely low cost
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
WHO USES APACHE KAFKA?
A few small companies you might have heard of…
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
MICROSOFT SUPPORTS KAFKA
Microsoft ♥ Linux
Microsoft ♥ Open Source
Nearly 1 in 3 VMs are Linux
Microsoft moves to GitHub
Microsoft sponsors the Kafka summit, releases Kafka .NET driver on GitHub, and
even buys LinkedIn. That is some Kafka love.
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE KAFKA – PERFORMANCE
Kafka performs amazingly well on modest hardware.
https://engineering.linkedin.com/kafka/benchmarking-apache-kafka-2-million-writes-second-three-cheap-machines
Producers and consumers
simultaneously accessing
cluster.
Test on the LinkedIn
Engineering Blog:
- 3 machines in Kafka
cluster, 3 to generate
load
- 6 SATA drives each, 32
GB RAM each
- 1 GB Ethernet
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE KAFKA – PERFORMANCE
Microsoft has one of the largest Kafka installations called “Siphon”
http://www.confluent.io/kafka-summit-2016-users-siphon-near-rea-time-databus-using-kafka
1.3 million
Events per second at peak
~1 trillion
Events per day at peak
3.5 petabytes
Processed per day
1,300
Production brokers
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE KAFKA – PERFORMANCE
Microsoft has one of the largest Kafka installations called “Siphon”
http://www.confluent.io/kafka-summit-2016-users-siphon-near-rea-time-databus-using-kafka
https://github.com/Microsoft/Availability-Monitor-for-Kafka
Availability & Latency monitor for Kafka using Canary messages
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE KAFKA – ARCHITECTURE
producer producer
consumer consumer consumer
Producers publish messages to a Kafka topic
Consumers subscribe to topics and process messages
Kafka cluster
broker
broker
broker
A Kafka cluster is made up of one or more brokers (nodes)
Zookeeper
Kafka uses Zookeeper for configuration
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE KAFKA – ROLE OF ZOOKEEPER
What is ZooKeeper?
ZooKeeper is a centralized service for maintaining
configuration information, naming, providing distributed
synchronization, and providing group services to
distributed applications.
Role of ZooKeeper in Kafka
It is responsible for: maintaining consumer offsets and
topic lists, leader election, and general state information.
Apache ZooKeeper
zk-web: Web UI for ZooKeeper
https://github.com/qiuxiafei/zk-web
Or get the Docker container
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE KAFKA – TOPICS
Kafka topic
producer
producer
0 1 2 3 4 5
writes
0 1 2 3 4
0 1 2 3 4
5
writes
consumer
consumer
reads
reads
Partition 0
Partition 1
Partition 2
Producers write messages to the end of a
partition
• Messages can be round robin load balanced across
partitions or assigned by a function.
Consumers read from the lowest offset to the
highest
• Unlike most queuing systems, state is not maintained on
the server. Each consumer tracks its own offset.
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE KAFKA – MORE ON PARTITIONS
Partitions for scalability
• The more partitions you have, the more throughput you get when consuming data.
• Each partition must fit entirely on a single server.
Partitions for ordering
• Kafka only guarantees message order within the same partition.
• If you need strong ordering, make sure that data is pinned to a single partition based
on some sort of key
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE KAFKA – PERSISTENCE
Kafka topic
0 1 2 3 4 5
0 1 2 3 4
0 1 2 3 4
5
Partition 0
Partition 1
Partition 2
All messages are written to disk and
replicated.
Messages are not removed from Kafka when
they are read from a topic.
A cleanup process will remove old messages
based on a sliding timeframe.
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE KAFKA – CONSUMER GROUPS
Kafka topic
consumer
1
consumer
2
consumer
reads
rea
ds
reads
Partition 0 Partition 1 Partition 2
Each consumer group is a “logical subscriber”
Messages are processed in parallel by
consumers
Only one consumer is assigned to a partition
in a consumer group.
consumer
3
reads
Consumer
Group 2
consumer
reads
Consumer
Group 1
Partition 3
consumer
4
reads
Note: consumers are responsible for handling duplicate
messages. These could be caused by failures of another
consumer in the group.
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE KAFKA – SERIALIZATION
Pick a format!
• JSON
• BSON
http://bsonspec.org/implementations.html
• PROTOCOL BUFFERS
https://github.com/google/protobuf
• BOND
https://github.com/Microsoft/bond
• AVRO
https://avro.apache.org/index.html
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE KAFKA – GETTING STARTED
Install Kafka & ZooKeeper
https://dzone.com/articles/running-apache-kafka-on-windows-os
• Install JDK
• Install ZooKeeper
• Install Kafka
Start Kafka & ZooKeeper
Start ZooKeeper
C:binzookeeper-3.4.8bin>zkServer.cmd
Start Kafka
C:binkafka_2.11-0.8.2.2>.binwindowskafka-server-start.bat .configserver.properties
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE KAFKA – GETTING STARTED
Create a topic
kafka-topics.bat --create --zookeeper localhost:2181
--replication-factor 1 --partitions 1 --topic SampleTopic1
Other Useful Topic Commands
List Topics
• kafka-topics.bat --list --zookeeper localhost:2181
Describe Topics
• kafka-topics.bat --describe --zookeeper localhost:2181 --topic [Topic Name]
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
KAFKA MANAGER
https://github.com/yahoo/kafka-manager
A tool for managing Apache Kafka
created by Yahoo.
Or get the Docker container
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
DEMO
Producing and consuming message in C#
Sample code:
https://github.com/dotnetpowered/StreamProcessingSample
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE
• Apache Spark is a fast and general engine for large-scale data
processing, Runs programs up to 100x faster than Hadoop MapReduce in
memory, or 10x faster on disk.
• Spark Streaming makes it easy to build scalable fault-tolerant streaming
applications.
https://spark.apache.org/streaming/
• Supports streaming directly from Apache Kafka.
http://spark.apache.org/docs/latest/streaming-kafka-integration.html
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE - FIRING UP THE CLUSTER
• Start the master
• Start one or more slaves
• Access the Spark cluster via browser
spark-class org.apache.spark.deploy.master.Master
spark-class org.apache.spark.deploy.worker.Worker spark://spark-master:7077
http://spark-master:8080
Spark is made up of master and slave processes…
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
APACHE WITH MOBIUS
Mobius is a .NET language binding for Spark. It is a Java wrapper for building
workers in C# and other CLR-based languages.
• Reference the Microsoft.SparkCLR Nuget Package
• Build a console application utilizing the API
• Submit your program to Spark using the following script
sparkclr-submit.cmd
--master spark://spark-master:7077
--jars <path>runtimedependenciesspark-streaming-kafka-assembly_2.10-1.6.1.jar
--exe StreamingRulesEngineHost.exe
C:srcStreamProcessingStreamProcessingHostbinDebug
https://github.com/Microsoft/Mobius
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
DEMO
Consuming messages in C# using Spark
Sample code:
https://github.com/dotnetpowered/StreamProcessingSample
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
USING THE ELK STACK FOR INTEGRATION & VISUALIZATION
Use Logstack to ingest events and/or consume events. Allows for “ETL” and
integration with tools such as Elastic Search.
Shipper
(for non-Kafka
enabled producers)
Indexer
search
https://www.elastic.co/blog/just-enough-kafka-for-the-elastic-stack-part1
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
CONNECTING KAFKA TO ELASTIC SEARCH
For consumers: Configure a Kafka input
input {
kafka {
zk_connect => "kafka:2181"
group_id => "logstash"
topic_id => "apache_logs"
consumer_threads => 16
}
}
Don’t forget about to select a codec for serialization!
C:binlogstash-2.3.2bin>logstash -e "input { kafka { topic_id
=> 'SampleTopic2' } } output { elasticsearch { index=>'sample-
%{+YYYY.MM.dd}' document_id => '%{docid}' } }"
Putting it all together:
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
LET’S REVIEW
• Event-driven systems are a key ingredient to
unlocking your organization’s potential. Make data
available to current and future apps, improve
scalability, and decrease complexity.
• Kafka is foundational infrastructure for event-driven
systems and is battle tested at scale.
• The ecosystem building around Kafka is rich -
allowing you to connect using various tools.
BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA
QUESTIONS?
THANK YOU!
BRIAN RITCHIE
CTO, XEOHEALTH
2016
@brian_ritchie
brian.ritchie@gmail.com
http://www.dotnetpowered.com
Sample code:
https://github.com/dotnetpowered/StreamProcessingSample

More Related Content

PDF
20190806 AWS Black Belt Online Seminar AWS Glue
PPTX
いまさら、AWSのネットワーク設計
PPTX
AWS Elastic Compute Cloud (EC2)
PPTX
セキュリティの基本とAWSでのセキュリティ対策をフルコースで味あう
PDF
AWS를 위한 도커, 컨테이너 (이미지) 환경 보안 방안 - 양희선 부장, TrendMicro :: AWS Summit Seoul 2019
PPTX
Manage your kubernetes cluster with cluster api, azure and git ops
PDF
Kafka Streams: What it is, and how to use it?
PPTX
Virtualization Vs. Containers
20190806 AWS Black Belt Online Seminar AWS Glue
いまさら、AWSのネットワーク設計
AWS Elastic Compute Cloud (EC2)
セキュリティの基本とAWSでのセキュリティ対策をフルコースで味あう
AWS를 위한 도커, 컨테이너 (이미지) 환경 보안 방안 - 양희선 부장, TrendMicro :: AWS Summit Seoul 2019
Manage your kubernetes cluster with cluster api, azure and git ops
Kafka Streams: What it is, and how to use it?
Virtualization Vs. Containers

What's hot (20)

PDF
Apache Kafka for Automotive Industry, Mobility Services & Smart City
PDF
Amazon Pinpoint × グロースハック活用事例集
PDF
AWS Black Belt Online Seminar 2016 AWS Key Management Service
PDF
AWS 엣지 서비스를 통한 글로벌 서비스 관리 전략 - AWS Summit Seoul 2017
PPTX
Apache Kafka 0.8 basic training - Verisign
PDF
AWS Black Belt Online Seminar 2017 AWS WAF
PDF
Az 104 session 6 azure networking part2
PDF
Laravel for e commerce build small store now and scale big later
PDF
JP1/AJS2オペレータ勉強会
PDF
An Introduction to Apache Kafka
PDF
Introduction to Kafka Streams
PPTX
vSAN architecture components
PDF
インフラ野郎AzureチームProX
PDF
Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018
PDF
ECS to EKS 마이그레이션 경험기 - 유용환(Superb AI) :: AWS Community Day Online 2021
PDF
Elastic Kubernetes Services (EKS)
PDF
Amazon Kinesis Familyを活用したストリームデータ処理
PDF
AWS 기반 클라우드 아키텍처 모범사례 - 삼성전자 개발자 포털/개발자 워크스페이스 - 정영준 솔루션즈 아키텍트, AWS / 유현성 수석,...
PPTX
パスキーでリードする: NGINXとKeycloakによる効率的な認証・認可
PDF
효과적인 NoSQL (Elasticahe / DynamoDB) 디자인 및 활용 방안 (최유정 & 최홍식, AWS 솔루션즈 아키텍트) :: ...
Apache Kafka for Automotive Industry, Mobility Services & Smart City
Amazon Pinpoint × グロースハック活用事例集
AWS Black Belt Online Seminar 2016 AWS Key Management Service
AWS 엣지 서비스를 통한 글로벌 서비스 관리 전략 - AWS Summit Seoul 2017
Apache Kafka 0.8 basic training - Verisign
AWS Black Belt Online Seminar 2017 AWS WAF
Az 104 session 6 azure networking part2
Laravel for e commerce build small store now and scale big later
JP1/AJS2オペレータ勉強会
An Introduction to Apache Kafka
Introduction to Kafka Streams
vSAN architecture components
インフラ野郎AzureチームProX
Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018
ECS to EKS 마이그레이션 경험기 - 유용환(Superb AI) :: AWS Community Day Online 2021
Elastic Kubernetes Services (EKS)
Amazon Kinesis Familyを活用したストリームデータ処理
AWS 기반 클라우드 아키텍처 모범사례 - 삼성전자 개발자 포털/개발자 워크스페이스 - 정영준 솔루션즈 아키텍트, AWS / 유현성 수석,...
パスキーでリードする: NGINXとKeycloakによる効率的な認証・認可
효과적인 NoSQL (Elasticahe / DynamoDB) 디자인 및 활용 방안 (최유정 & 최홍식, AWS 솔루션즈 아키텍트) :: ...
Ad

Similar to Building Event-Driven Systems with Apache Kafka (20)

PPTX
Kafkha real time analytics platform.pptx
PDF
Connect K of SMACK:pykafka, kafka-python or?
PDF
Devoxx university - Kafka de haut en bas
PDF
Kafka Up And Running For Network Devops Set Your Network Data In Motion Eric ...
PDF
Event driven-arch
PPTX
Apache Kafka with Spark Streaming: Real-time Analytics Redefined
PPTX
Building streaming data applications using Kafka*[Connect + Core + Streams] b...
PDF
Event streaming: A paradigm shift in enterprise software architecture
PDF
Apache Kafka as Event Streaming Platform for Microservice Architectures
PDF
Apache Kafka - Scalable Message-Processing and more !
PPTX
Event Driven Architectures with Apache Kafka
PPTX
Learn Apache Kafka Online | Comprehensive Kafka Course & Training
PPTX
Kafka Basic For Beginners
PDF
Building Streaming Data Applications Using Apache Kafka
PDF
Trivadis TechEvent 2016 Apache Kafka - Scalable Massage Processing and more! ...
PPTX
Apache kafka
PPTX
Westpac Bank Tech Talk 1: Dive into Apache Kafka
PDF
Building Event Driven Services with Apache Kafka and Kafka Streams - Devoxx B...
PPTX
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
PPTX
What is Kafka & why is it Important? (UKOUG Tech17, Birmingham, UK - December...
Kafkha real time analytics platform.pptx
Connect K of SMACK:pykafka, kafka-python or?
Devoxx university - Kafka de haut en bas
Kafka Up And Running For Network Devops Set Your Network Data In Motion Eric ...
Event driven-arch
Apache Kafka with Spark Streaming: Real-time Analytics Redefined
Building streaming data applications using Kafka*[Connect + Core + Streams] b...
Event streaming: A paradigm shift in enterprise software architecture
Apache Kafka as Event Streaming Platform for Microservice Architectures
Apache Kafka - Scalable Message-Processing and more !
Event Driven Architectures with Apache Kafka
Learn Apache Kafka Online | Comprehensive Kafka Course & Training
Kafka Basic For Beginners
Building Streaming Data Applications Using Apache Kafka
Trivadis TechEvent 2016 Apache Kafka - Scalable Massage Processing and more! ...
Apache kafka
Westpac Bank Tech Talk 1: Dive into Apache Kafka
Building Event Driven Services with Apache Kafka and Kafka Streams - Devoxx B...
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
What is Kafka & why is it Important? (UKOUG Tech17, Birmingham, UK - December...
Ad

More from Brian Ritchie (7)

PPTX
Transforming your application with Elasticsearch
PPTX
From Dev to Ops:Delivering an API to Production with Splunk
PPT
Extending the Enterprise with MEF
PPTX
CQRS: Command/Query Responsibility Segregation
PPTX
IIS Always-On Services
PPTX
Scaling Out .NET
PPT
Document Databases & RavenDB
Transforming your application with Elasticsearch
From Dev to Ops:Delivering an API to Production with Splunk
Extending the Enterprise with MEF
CQRS: Command/Query Responsibility Segregation
IIS Always-On Services
Scaling Out .NET
Document Databases & RavenDB

Recently uploaded (20)

PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Big Data Technologies - Introduction.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
MIND Revenue Release Quarter 2 2025 Press Release
Reach Out and Touch Someone: Haptics and Empathic Computing
Big Data Technologies - Introduction.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Review of recent advances in non-invasive hemoglobin estimation
Digital-Transformation-Roadmap-for-Companies.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Network Security Unit 5.pdf for BCA BBA.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Electronic commerce courselecture one. Pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Programs and apps: productivity, graphics, security and other tools
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Weekly Chronicles - August'25 Week I
Encapsulation_ Review paper, used for researhc scholars
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

Building Event-Driven Systems with Apache Kafka

  • 1. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA BRIAN RITCHIE CTO, XEOHEALTH 2016 @brian_ritchie [email protected] http://www.dotnetpowered.com
  • 2. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA EVENT-DRIVEN SYSTEMS Definition Event-driven architecture, also known as message-driven architecture, is a software architecture pattern promoting the production, detection, consumption of, and reaction to events. An event can be defined as "a significant change in state". https://en.wikipedia.org/wiki/Event-driven_architecture
  • 3. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA EVENT-DRIVEN SYSTEMS ARE ABOUT UNLOCKING DATA • Data is the driving force behind innovation • Event-driven systems allow you to unlock the data – and unlock the innovation.
  • 4. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA EVENTS ARE THE “WHAT HAPPENED” DATA • It’s about recording “what happened”, but not coupling it to the “how” • It’s the “transactions” of your system • Product Views • Completed Sales • Page Visits • Site Logins • Shipping Notifications • Inventory Received • IoT • …and much more
  • 5. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA EVENTS – A HEALTHCARE EXAMPLE Event Stream Healthcare Claim Fraud Detection Data Lake Archive Disease Trending Contract & Pricing More… You don’t need to integrate with consumers or even know about a future uses of your data What happened? A patient received a set of services
  • 6. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA EVENT-DRIVEN SYSTEMS MAKE SCALABILITY EASIER • Scalability of processing • Scalability of design • Scalability of change
  • 7. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA EVENT-DRIVEN SYSTEMS REQUIRE INFRASTRUCTURE • Queue / Stream • Persistence • Distribution • Pub / Sub
  • 8. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE KAFKA IS THE INFRASTRUCTURE • Apache Kafka is publish-subscribe messaging rethought as a distributed commit log. • Developed by LinkedIn • Written in Java • Open Sourced in 2011 and graduated Apache Incubator in 2012 • Unique features of Kafka • Super fast • Distributed & Replicated out of the box • Extremely low cost
  • 9. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA WHO USES APACHE KAFKA? A few small companies you might have heard of…
  • 10. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA MICROSOFT SUPPORTS KAFKA Microsoft ♥ Linux Microsoft ♥ Open Source Nearly 1 in 3 VMs are Linux Microsoft moves to GitHub Microsoft sponsors the Kafka summit, releases Kafka .NET driver on GitHub, and even buys LinkedIn. That is some Kafka love.
  • 11. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE KAFKA – PERFORMANCE Kafka performs amazingly well on modest hardware. https://engineering.linkedin.com/kafka/benchmarking-apache-kafka-2-million-writes-second-three-cheap-machines Producers and consumers simultaneously accessing cluster. Test on the LinkedIn Engineering Blog: - 3 machines in Kafka cluster, 3 to generate load - 6 SATA drives each, 32 GB RAM each - 1 GB Ethernet
  • 12. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE KAFKA – PERFORMANCE Microsoft has one of the largest Kafka installations called “Siphon” http://www.confluent.io/kafka-summit-2016-users-siphon-near-rea-time-databus-using-kafka 1.3 million Events per second at peak ~1 trillion Events per day at peak 3.5 petabytes Processed per day 1,300 Production brokers
  • 13. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE KAFKA – PERFORMANCE Microsoft has one of the largest Kafka installations called “Siphon” http://www.confluent.io/kafka-summit-2016-users-siphon-near-rea-time-databus-using-kafka https://github.com/Microsoft/Availability-Monitor-for-Kafka Availability & Latency monitor for Kafka using Canary messages
  • 14. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE KAFKA – ARCHITECTURE producer producer consumer consumer consumer Producers publish messages to a Kafka topic Consumers subscribe to topics and process messages Kafka cluster broker broker broker A Kafka cluster is made up of one or more brokers (nodes) Zookeeper Kafka uses Zookeeper for configuration
  • 15. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE KAFKA – ROLE OF ZOOKEEPER What is ZooKeeper? ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services to distributed applications. Role of ZooKeeper in Kafka It is responsible for: maintaining consumer offsets and topic lists, leader election, and general state information. Apache ZooKeeper zk-web: Web UI for ZooKeeper https://github.com/qiuxiafei/zk-web Or get the Docker container
  • 16. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE KAFKA – TOPICS Kafka topic producer producer 0 1 2 3 4 5 writes 0 1 2 3 4 0 1 2 3 4 5 writes consumer consumer reads reads Partition 0 Partition 1 Partition 2 Producers write messages to the end of a partition • Messages can be round robin load balanced across partitions or assigned by a function. Consumers read from the lowest offset to the highest • Unlike most queuing systems, state is not maintained on the server. Each consumer tracks its own offset.
  • 17. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE KAFKA – MORE ON PARTITIONS Partitions for scalability • The more partitions you have, the more throughput you get when consuming data. • Each partition must fit entirely on a single server. Partitions for ordering • Kafka only guarantees message order within the same partition. • If you need strong ordering, make sure that data is pinned to a single partition based on some sort of key
  • 18. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE KAFKA – PERSISTENCE Kafka topic 0 1 2 3 4 5 0 1 2 3 4 0 1 2 3 4 5 Partition 0 Partition 1 Partition 2 All messages are written to disk and replicated. Messages are not removed from Kafka when they are read from a topic. A cleanup process will remove old messages based on a sliding timeframe.
  • 19. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE KAFKA – CONSUMER GROUPS Kafka topic consumer 1 consumer 2 consumer reads rea ds reads Partition 0 Partition 1 Partition 2 Each consumer group is a “logical subscriber” Messages are processed in parallel by consumers Only one consumer is assigned to a partition in a consumer group. consumer 3 reads Consumer Group 2 consumer reads Consumer Group 1 Partition 3 consumer 4 reads Note: consumers are responsible for handling duplicate messages. These could be caused by failures of another consumer in the group.
  • 20. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE KAFKA – SERIALIZATION Pick a format! • JSON • BSON http://bsonspec.org/implementations.html • PROTOCOL BUFFERS https://github.com/google/protobuf • BOND https://github.com/Microsoft/bond • AVRO https://avro.apache.org/index.html
  • 21. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE KAFKA – GETTING STARTED Install Kafka & ZooKeeper https://dzone.com/articles/running-apache-kafka-on-windows-os • Install JDK • Install ZooKeeper • Install Kafka Start Kafka & ZooKeeper Start ZooKeeper C:binzookeeper-3.4.8bin>zkServer.cmd Start Kafka C:binkafka_2.11-0.8.2.2>.binwindowskafka-server-start.bat .configserver.properties
  • 22. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE KAFKA – GETTING STARTED Create a topic kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic SampleTopic1 Other Useful Topic Commands List Topics • kafka-topics.bat --list --zookeeper localhost:2181 Describe Topics • kafka-topics.bat --describe --zookeeper localhost:2181 --topic [Topic Name]
  • 23. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA KAFKA MANAGER https://github.com/yahoo/kafka-manager A tool for managing Apache Kafka created by Yahoo. Or get the Docker container
  • 24. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA DEMO Producing and consuming message in C# Sample code: https://github.com/dotnetpowered/StreamProcessingSample
  • 25. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE • Apache Spark is a fast and general engine for large-scale data processing, Runs programs up to 100x faster than Hadoop MapReduce in memory, or 10x faster on disk. • Spark Streaming makes it easy to build scalable fault-tolerant streaming applications. https://spark.apache.org/streaming/ • Supports streaming directly from Apache Kafka. http://spark.apache.org/docs/latest/streaming-kafka-integration.html
  • 26. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE - FIRING UP THE CLUSTER • Start the master • Start one or more slaves • Access the Spark cluster via browser spark-class org.apache.spark.deploy.master.Master spark-class org.apache.spark.deploy.worker.Worker spark://spark-master:7077 http://spark-master:8080 Spark is made up of master and slave processes…
  • 27. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA APACHE WITH MOBIUS Mobius is a .NET language binding for Spark. It is a Java wrapper for building workers in C# and other CLR-based languages. • Reference the Microsoft.SparkCLR Nuget Package • Build a console application utilizing the API • Submit your program to Spark using the following script sparkclr-submit.cmd --master spark://spark-master:7077 --jars <path>runtimedependenciesspark-streaming-kafka-assembly_2.10-1.6.1.jar --exe StreamingRulesEngineHost.exe C:srcStreamProcessingStreamProcessingHostbinDebug https://github.com/Microsoft/Mobius
  • 28. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA DEMO Consuming messages in C# using Spark Sample code: https://github.com/dotnetpowered/StreamProcessingSample
  • 29. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA USING THE ELK STACK FOR INTEGRATION & VISUALIZATION Use Logstack to ingest events and/or consume events. Allows for “ETL” and integration with tools such as Elastic Search. Shipper (for non-Kafka enabled producers) Indexer search https://www.elastic.co/blog/just-enough-kafka-for-the-elastic-stack-part1
  • 30. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA CONNECTING KAFKA TO ELASTIC SEARCH For consumers: Configure a Kafka input input { kafka { zk_connect => "kafka:2181" group_id => "logstash" topic_id => "apache_logs" consumer_threads => 16 } } Don’t forget about to select a codec for serialization! C:binlogstash-2.3.2bin>logstash -e "input { kafka { topic_id => 'SampleTopic2' } } output { elasticsearch { index=>'sample- %{+YYYY.MM.dd}' document_id => '%{docid}' } }" Putting it all together:
  • 31. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA LET’S REVIEW • Event-driven systems are a key ingredient to unlocking your organization’s potential. Make data available to current and future apps, improve scalability, and decrease complexity. • Kafka is foundational infrastructure for event-driven systems and is battle tested at scale. • The ecosystem building around Kafka is rich - allowing you to connect using various tools.
  • 32. BUILDING EVENT-DRIVEN SYSTEMS WITH APACHE KAFKA QUESTIONS?
  • 33. THANK YOU! BRIAN RITCHIE CTO, XEOHEALTH 2016 @brian_ritchie [email protected] http://www.dotnetpowered.com Sample code: https://github.com/dotnetpowered/StreamProcessingSample

Editor's Notes

  • #10: http://blog.underdog.io/post/107602021862/inside-datadogs-tech-stack
  • #12: https://engineering.linkedin.com/kafka/benchmarking-apache-kafka-2-million-writes-second-three-cheap-machines
  • #13: https://engineering.linkedin.com/kafka/benchmarking-apache-kafka-2-million-writes-second-three-cheap-machines
  • #14: https://engineering.linkedin.com/kafka/benchmarking-apache-kafka-2-million-writes-second-three-cheap-machines