SlideShare une entreprise Scribd logo
1  sur  43
Télécharger pour lire hors ligne
Apache Kafka
//TODO Insert Logo
About Me
David Arthur
http://mumrah.github.io/
● Software Engineer at LucidWorks
● Open source contributor
● Gardener
● Dad
TOC
● Project overview
● Architecture
● Implementation
● Miscellany
Project info
● http://kafka.apache.org
● Written in Scala
● Open sourced by LinkedIn SNA in 2011
● Soon after entered Apache Incubator
● Not just an idle "open source donation"
● Active development, 0.8 out now
● Apache TLP late 2012, 13 committers
● Still no logo
12 word overview
Apache Kafka is publish-subscribe messaging
rethought as a distributed commit log
Ok...
Kafka is a persistent, distributed, replicated
pub/sub messaging system. Publishers send
messages to a cluster of brokers. The brokers
persist the messages to disk.
Consumers then request a range of messages
using an (offset, length) style API. Use of NIO
FileChannel allows for very fast transfer of
data in and out of the system.
Highlights
● ZooKeeper for Broker coordination
● Configurable Producer acks
● Consumer Groups
● TTL persistence
● Sync/Async producer API
● Durable
● Scalable
● Fast
● <Additional buzzwords>
Motivation
● Activity stream processing (user interactions)
● Batch latency was too high
● Existing queues handle large volumes of
(unconsumed) data poorly - durability is
expensive
● Need something fast and durable
Key design choices
● Pub/sub messaging pattern
● Messages are persistent
● Everything is distributed - producers,
brokers, consumers, the queue itself
● Consumers maintain their own state (i.e.,
"dumb" brokers)
● Throughput is key
TOC
● Project overview
● Architecture
● Implementation
● Miscellany
Brokers
● Receive messages from Producers (push),
deliver messages to Consumers (pull)
● Responsible for persisting the messages for
some time
● Relatively lightweight - mostly just handling
TCP connections and keeping open file
handles to the queue files
Log-based queue
Messages are persisted to append-only log
files by the broker. Producers are appending to
these log files (sequential write), and
consumers are reading a range of these files
(sequential reads).
Log-based queue
Message 0
Message 1
Message 2
Message 3
Producer
Message 4
Message 5
Message 6
Consumer A read 0-4 Consumer Bread 1-3
Broker
Topics
Topics are queues. They are logical collections
of partitions (the physical files). A broker
contains some of the partitions for a topic
Partition 0 Partition 1
Topic A
Partition 0 Partition 1
Topic B
Broker 1
Partition 0 Partition 1
Topic A
Partition 0 Partition 1
Topic B
Broker 2
Replication
Partitions of a topic are replicated. One broker
is the "leader" of a partition. All writes and
reads must go to the leader. Replicas exist for
fault-tolerance, not scalability.
When writing, messages can be synchronously
written to N replicas (depending on the
producer's ACKiness)
Producers
Producers are responsible for load balancing
messages to the various brokers. They can
discover all brokers from any one broker.
In 0.7, producers are fire-and-forget. In 0.8,
there are 3 ack levels:
● No ack (0)
● Ack from N replicas (1..N)
● Ack from all replicas (-1)
Consumers
Consumers request a range of messages from
a Broker. They are responsible for their own
state
Default implementation uses ZooKeeper to
manage state. In 0.8.1, Brokers will expose an
API for offset management to remove direct
communication between consumers and
ZooKeeper (a good thing).
Result?
● Brokers keep very little state, mostly just
open file pointers and connections
● Can scale to thousands of producers and
consumers*
● Stable performance, good scalability
● In 0.7, 50MB/s producer throughput,
100MB/s consumer throughput
● No numbers yet from 0.8, but the same
comparable (with acks=0)
TOC
● Project overview
● Architecture
● Implementation
● Miscellany
High-level producer
API
Producer#send(KeyedMessage<K,V> datum)
KeyedMessage<K,V>(String topic, K key,
V value)
The Producer class determines where a
message is sent based on the routing key. If a
null key is given, the message is sent to a
random partition
Message routing
Partition 0 Partition 1
Topic A
Broker 1
Partition 0 Partition 1
Topic A
Broker 2
hash("foo") % 4
Partitioner
Producer.send("A", "foo",
messages)
Producer
Message routing
● Producers can be configured with a custom
routing function (implementing the Partitioner
interface)
● Default is hash-mod
● One side effect of routing is that there is no
total ordering for a topic, but there is within a
partition (this is actually really useful)
(Partially) Ordered
Messages
Consider a system that is processing updates.
If you partition the messages based on the
primary key you guarantee all messages for a
given key end up in the same partition. Since
Kafka guarantees ordering of the messages at
the partition level, your updates will be
processed in the correct sequence.
Persistent Messages
● MessageSets received by the broker and
flushed to append-only log files
● Simple log format (next slide)
● Zero-copy (i.e., sendfile) for file to socket
transfer
● Log files are not kept forever
Log Format
append
Log file
MessageSet
MessageSet
MessageSet
MessageSet
/tmp/kafka-logs/00000000000000000000.kafka
append
append
appendBroker
ByteBufferMessageSet#writeTo(FileChannel)
Index
0: 0
1: 1024
2: 2048
Message offset
index
Message sets
● To maximize throughput, the same binary
format for messages is used throughout the
system (producer API, consumer API, and
log file format)
● Broker only decodes far enough to read the
checksum and validate it, then writes it to the
disk
Compressed message sets
or, message batching
● The value of a Message can be a
compressed MessageSet
Message(value=gzip(MessageSet(...)))
● Useful for increasing throughput (especially
if you are buffering messages in the
producer)
● Can also be used as a way to atomically
write multiple messages
Zero-copy
Reading data out of Kafka is super fast thanks
to java.nio.channels.FileChannel#transferTo.
This method uses the "sendfile" system call
which allows for very efficient transfer of data
from a file to another file (including sockets).
This optimization is what allows us to pull
~100MB/s out of a single broker
High-level Consumer
API
Map topicMap = Collections.singletonMap("topic", 2);
Map<String,List<KafkaStream>> streams =
Consumer.createJavaConsumerConnector(topicMap);
● KafkaStream is an iterable
● Blocking or non-blocking behavior
● Auto-commit offset, or manual commit
● Participate in a "consumer group"
Consumer Groups
Multiple high-level consumers can participate in
a single "consumer group". A consumer group
is coordinated using ZooKeeper, so it can span
multiple machines. In a group, each partition
will be consumed by exactly one consumer (i.
e., KafkaStream).
This allows for broadcast or pub/sub type of
messaging pattern
Consumer Groups
P0 P1
Topic "foo"
Broker 1
Consumer Group A Consumer Group B
P2 P3
Topic "foo"
Broker 2
TOC
● Project overview
● Architecture
● Implementation
● Miscellany
But, I already have a MQ
Many people with distributed systems already
have something like JMS, RabbitMQ, Kestrel,
or ØMQ in place.
These are all different systems with different
implementation details and semantics. Decide
what features you need, and then chose a MQ -
not the other way around :)
RabbitMQ discussion: http://bit.ly/140ZMOx
Caveats
● Not designed for large payloads. Decoding is
done for a whole message (no streaming
decoding).
● Rebalancing can screw things up if you're
doing any aggregation in the consumer by
the partition key
● Number of partitions cannot be easily
changed (chose wisely)
● Lots of topics can hurt I/O performance
Clients
● Many exist, some more complete than
others
● No official clients (other than Java/Scala)
● Community maintained
● Most lack support for high-level consumer
due to ZooKeeper dependency (it's tricky)
● Excellent Python client: https://github.
com/mumrah/kafka-python (yes, I wrote it)
● Only Python, C, and Clojure support the 0.8
protocol
Hadoop InputFormat
● InputFormat/OutputFormat implementations
● Uses low-level consumer, no offsets in ZK
(they are stored on HDFS instead)
● Useful for long term storage of messages
● We use this!
● LinkedIn released Camus, a Kafka to HDFS
pipeline
Integration
A few good integration points. I expect more to
show up as Kafka gains adoption
● log4j appender (in Kafka itself)
● storm-kafka (in storm-contrib)
● camel-kafka
● LogStash (loges)
More listed on Kafka wiki http://bit.ly/1btZz8p
Applications
Log Aggregation
Many applications running on many machines.
You want centralized logging, but don't want to
install an agent (Flume, etc).
Kafka includes a log4j appender
<appender class="kafka.producer.KafkaLog4jAppender" name="kafka-solr">
<param name="zkConnect" value="localhost:2181"/>
<param name="topic" value="solr-logs"/>
<layout class="org.apache.log4j.PatternLayout">
<param value="%d{ISO8601} %p %c %m" name="ConversionPattern"/>
</layout>
</appender>
Applications
Notifications
Store data into data store A, need to sync it to
data store B. Suppose you can send a
message to Kafka when an update happens in
A
A
Kafka
Brecord X changed
get updated record X
Applications
Stream Processing
Using a stream processing tool like Storm or
Apache Camel, Kafka provides an excellent
backbone.
Data in
Kafka
topic A
Process A
Kafka
topic B
Process B
Bonus Slides
Stats
LinkedIn stats:
● Peak writes per second: 460k
● Average writes per day: 28 billion
● Average reads per second: 2.3 million
● ~700 topics
● Thousands of producers
● ~1000 consumers
Bonus Slides
Logos!
Being heatedly debated in JIRA as we speak!
Links!
● Slides: http://bit.ly/kafka-trihug
● Kafka Project: http://kafka.apache.org/
● Kafka Code: https://github.com/apache/kafka
● LinkedIn Camus: https://github.com/linkedin/camus
● Zero-Copy IBM article: http://ibm.co/gsETNm
● LinkedIn Kafka paper: http://bit.ly/mC8TLS
● LinkedIn blog post on replication: http://linkd.in/YAWslH

Contenu connexe

Tendances

Apache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals ExplainedApache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals Explainedconfluent
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureDan McKinley
 
APACHE KAFKA / Kafka Connect / Kafka Streams
APACHE KAFKA / Kafka Connect / Kafka StreamsAPACHE KAFKA / Kafka Connect / Kafka Streams
APACHE KAFKA / Kafka Connect / Kafka StreamsKetan Gote
 
Deep Dive into Apache Kafka
Deep Dive into Apache KafkaDeep Dive into Apache Kafka
Deep Dive into Apache Kafkaconfluent
 
Apache Kafka Introduction
Apache Kafka IntroductionApache Kafka Introduction
Apache Kafka IntroductionAmita Mirajkar
 
Apache Kafka - Martin Podval
Apache Kafka - Martin PodvalApache Kafka - Martin Podval
Apache Kafka - Martin PodvalMartin Podval
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsJonas Bonér
 
Apache Kafka Fundamentals for Architects, Admins and Developers
Apache Kafka Fundamentals for Architects, Admins and DevelopersApache Kafka Fundamentals for Architects, Admins and Developers
Apache Kafka Fundamentals for Architects, Admins and Developersconfluent
 
HBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBaseHBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBaseenissoz
 
A Deep Dive into Kafka Controller
A Deep Dive into Kafka ControllerA Deep Dive into Kafka Controller
A Deep Dive into Kafka Controllerconfluent
 
Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?confluent
 
Introduction to Kafka Cruise Control
Introduction to Kafka Cruise ControlIntroduction to Kafka Cruise Control
Introduction to Kafka Cruise ControlJiangjie Qin
 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.Taras Matyashovsky
 
Producer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaProducer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaJiangjie Qin
 
Netflix viewing data architecture evolution - QCon 2014
Netflix viewing data architecture evolution - QCon 2014Netflix viewing data architecture evolution - QCon 2014
Netflix viewing data architecture evolution - QCon 2014Philip Fisher-Ogden
 

Tendances (20)

Apache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals ExplainedApache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals Explained
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds Architecture
 
kafka
kafkakafka
kafka
 
APACHE KAFKA / Kafka Connect / Kafka Streams
APACHE KAFKA / Kafka Connect / Kafka StreamsAPACHE KAFKA / Kafka Connect / Kafka Streams
APACHE KAFKA / Kafka Connect / Kafka Streams
 
Deep Dive into Apache Kafka
Deep Dive into Apache KafkaDeep Dive into Apache Kafka
Deep Dive into Apache Kafka
 
Apache Kafka Introduction
Apache Kafka IntroductionApache Kafka Introduction
Apache Kafka Introduction
 
Intro to HBase
Intro to HBaseIntro to HBase
Intro to HBase
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 
Apache Kafka - Martin Podval
Apache Kafka - Martin PodvalApache Kafka - Martin Podval
Apache Kafka - Martin Podval
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 
Apache Kafka Fundamentals for Architects, Admins and Developers
Apache Kafka Fundamentals for Architects, Admins and DevelopersApache Kafka Fundamentals for Architects, Admins and Developers
Apache Kafka Fundamentals for Architects, Admins and Developers
 
HBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBaseHBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBase
 
Kafka presentation
Kafka presentationKafka presentation
Kafka presentation
 
A Deep Dive into Kafka Controller
A Deep Dive into Kafka ControllerA Deep Dive into Kafka Controller
A Deep Dive into Kafka Controller
 
Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?
 
Introduction to Kafka Cruise Control
Introduction to Kafka Cruise ControlIntroduction to Kafka Cruise Control
Introduction to Kafka Cruise Control
 
Apache Kafka Best Practices
Apache Kafka Best PracticesApache Kafka Best Practices
Apache Kafka Best Practices
 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
 
Producer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaProducer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache Kafka
 
Netflix viewing data architecture evolution - QCon 2014
Netflix viewing data architecture evolution - QCon 2014Netflix viewing data architecture evolution - QCon 2014
Netflix viewing data architecture evolution - QCon 2014
 

Similaire à Introduction and Overview of Apache Kafka, TriHUG July 23, 2013

Copy of Kafka-Camus
Copy of Kafka-CamusCopy of Kafka-Camus
Copy of Kafka-CamusDeep Shah
 
Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !Guido Schmutz
 
Data Pipelines with Apache Kafka
Data Pipelines with Apache KafkaData Pipelines with Apache Kafka
Data Pipelines with Apache KafkaBen Stopford
 
Session 23 - Kafka and Zookeeper
Session 23 - Kafka and ZookeeperSession 23 - Kafka and Zookeeper
Session 23 - Kafka and ZookeeperAnandMHadoop
 
Kafka 10000 feet view
Kafka 10000 feet viewKafka 10000 feet view
Kafka 10000 feet viewyounessx01
 
14th Athens Big Data Meetup - Landoop Workshop - Apache Kafka Entering The St...
14th Athens Big Data Meetup - Landoop Workshop - Apache Kafka Entering The St...14th Athens Big Data Meetup - Landoop Workshop - Apache Kafka Entering The St...
14th Athens Big Data Meetup - Landoop Workshop - Apache Kafka Entering The St...Athens Big Data
 
Developing Realtime Data Pipelines With Apache Kafka
Developing Realtime Data Pipelines With Apache KafkaDeveloping Realtime Data Pipelines With Apache Kafka
Developing Realtime Data Pipelines With Apache KafkaJoe Stein
 
Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !Guido Schmutz
 
Introduction to Kafka Streams Presentation
Introduction to Kafka Streams PresentationIntroduction to Kafka Streams Presentation
Introduction to Kafka Streams PresentationKnoldus Inc.
 
bigdata 2022_ FLiP Into Pulsar Apps
bigdata 2022_ FLiP Into Pulsar Appsbigdata 2022_ FLiP Into Pulsar Apps
bigdata 2022_ FLiP Into Pulsar AppsTimothy Spann
 
Timothy Spann: Apache Pulsar for ML
Timothy Spann: Apache Pulsar for MLTimothy Spann: Apache Pulsar for ML
Timothy Spann: Apache Pulsar for MLEdunomica
 
Introduction to Kafka
Introduction to KafkaIntroduction to Kafka
Introduction to KafkaDucas Francis
 
Columbus mule soft_meetup_aug2021_Kafka_Integration
Columbus mule soft_meetup_aug2021_Kafka_IntegrationColumbus mule soft_meetup_aug2021_Kafka_Integration
Columbus mule soft_meetup_aug2021_Kafka_IntegrationMuleSoft Meetup
 
Introduction to Kafka and Event-Driven
Introduction to Kafka and Event-DrivenIntroduction to Kafka and Event-Driven
Introduction to Kafka and Event-Drivenarconsis
 
Introduction to Kafka and Event-Driven
Introduction to Kafka and Event-DrivenIntroduction to Kafka and Event-Driven
Introduction to Kafka and Event-DrivenDimosthenis Botsaris
 

Similaire à Introduction and Overview of Apache Kafka, TriHUG July 23, 2013 (20)

Copy of Kafka-Camus
Copy of Kafka-CamusCopy of Kafka-Camus
Copy of Kafka-Camus
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !
 
Data Pipelines with Apache Kafka
Data Pipelines with Apache KafkaData Pipelines with Apache Kafka
Data Pipelines with Apache Kafka
 
Notes leo kafka
Notes leo kafkaNotes leo kafka
Notes leo kafka
 
Session 23 - Kafka and Zookeeper
Session 23 - Kafka and ZookeeperSession 23 - Kafka and Zookeeper
Session 23 - Kafka and Zookeeper
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Apache kafka introduction
Apache kafka introductionApache kafka introduction
Apache kafka introduction
 
Kafka 10000 feet view
Kafka 10000 feet viewKafka 10000 feet view
Kafka 10000 feet view
 
14th Athens Big Data Meetup - Landoop Workshop - Apache Kafka Entering The St...
14th Athens Big Data Meetup - Landoop Workshop - Apache Kafka Entering The St...14th Athens Big Data Meetup - Landoop Workshop - Apache Kafka Entering The St...
14th Athens Big Data Meetup - Landoop Workshop - Apache Kafka Entering The St...
 
Developing Realtime Data Pipelines With Apache Kafka
Developing Realtime Data Pipelines With Apache KafkaDeveloping Realtime Data Pipelines With Apache Kafka
Developing Realtime Data Pipelines With Apache Kafka
 
Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !
 
Introduction to Kafka Streams Presentation
Introduction to Kafka Streams PresentationIntroduction to Kafka Streams Presentation
Introduction to Kafka Streams Presentation
 
bigdata 2022_ FLiP Into Pulsar Apps
bigdata 2022_ FLiP Into Pulsar Appsbigdata 2022_ FLiP Into Pulsar Apps
bigdata 2022_ FLiP Into Pulsar Apps
 
Timothy Spann: Apache Pulsar for ML
Timothy Spann: Apache Pulsar for MLTimothy Spann: Apache Pulsar for ML
Timothy Spann: Apache Pulsar for ML
 
Introduction to Kafka
Introduction to KafkaIntroduction to Kafka
Introduction to Kafka
 
Columbus mule soft_meetup_aug2021_Kafka_Integration
Columbus mule soft_meetup_aug2021_Kafka_IntegrationColumbus mule soft_meetup_aug2021_Kafka_Integration
Columbus mule soft_meetup_aug2021_Kafka_Integration
 
Introduction to Kafka and Event-Driven
Introduction to Kafka and Event-DrivenIntroduction to Kafka and Event-Driven
Introduction to Kafka and Event-Driven
 
Introduction to Kafka and Event-Driven
Introduction to Kafka and Event-DrivenIntroduction to Kafka and Event-Driven
Introduction to Kafka and Event-Driven
 

Dernier

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Dernier (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

Introduction and Overview of Apache Kafka, TriHUG July 23, 2013

  • 2. About Me David Arthur http://mumrah.github.io/ ● Software Engineer at LucidWorks ● Open source contributor ● Gardener ● Dad
  • 3. TOC ● Project overview ● Architecture ● Implementation ● Miscellany
  • 4. Project info ● http://kafka.apache.org ● Written in Scala ● Open sourced by LinkedIn SNA in 2011 ● Soon after entered Apache Incubator ● Not just an idle "open source donation" ● Active development, 0.8 out now ● Apache TLP late 2012, 13 committers ● Still no logo
  • 5. 12 word overview Apache Kafka is publish-subscribe messaging rethought as a distributed commit log
  • 6. Ok... Kafka is a persistent, distributed, replicated pub/sub messaging system. Publishers send messages to a cluster of brokers. The brokers persist the messages to disk. Consumers then request a range of messages using an (offset, length) style API. Use of NIO FileChannel allows for very fast transfer of data in and out of the system.
  • 7. Highlights ● ZooKeeper for Broker coordination ● Configurable Producer acks ● Consumer Groups ● TTL persistence ● Sync/Async producer API ● Durable ● Scalable ● Fast ● <Additional buzzwords>
  • 8. Motivation ● Activity stream processing (user interactions) ● Batch latency was too high ● Existing queues handle large volumes of (unconsumed) data poorly - durability is expensive ● Need something fast and durable
  • 9. Key design choices ● Pub/sub messaging pattern ● Messages are persistent ● Everything is distributed - producers, brokers, consumers, the queue itself ● Consumers maintain their own state (i.e., "dumb" brokers) ● Throughput is key
  • 10. TOC ● Project overview ● Architecture ● Implementation ● Miscellany
  • 11. Brokers ● Receive messages from Producers (push), deliver messages to Consumers (pull) ● Responsible for persisting the messages for some time ● Relatively lightweight - mostly just handling TCP connections and keeping open file handles to the queue files
  • 12. Log-based queue Messages are persisted to append-only log files by the broker. Producers are appending to these log files (sequential write), and consumers are reading a range of these files (sequential reads).
  • 13. Log-based queue Message 0 Message 1 Message 2 Message 3 Producer Message 4 Message 5 Message 6 Consumer A read 0-4 Consumer Bread 1-3 Broker
  • 14. Topics Topics are queues. They are logical collections of partitions (the physical files). A broker contains some of the partitions for a topic Partition 0 Partition 1 Topic A Partition 0 Partition 1 Topic B Broker 1 Partition 0 Partition 1 Topic A Partition 0 Partition 1 Topic B Broker 2
  • 15. Replication Partitions of a topic are replicated. One broker is the "leader" of a partition. All writes and reads must go to the leader. Replicas exist for fault-tolerance, not scalability. When writing, messages can be synchronously written to N replicas (depending on the producer's ACKiness)
  • 16. Producers Producers are responsible for load balancing messages to the various brokers. They can discover all brokers from any one broker. In 0.7, producers are fire-and-forget. In 0.8, there are 3 ack levels: ● No ack (0) ● Ack from N replicas (1..N) ● Ack from all replicas (-1)
  • 17. Consumers Consumers request a range of messages from a Broker. They are responsible for their own state Default implementation uses ZooKeeper to manage state. In 0.8.1, Brokers will expose an API for offset management to remove direct communication between consumers and ZooKeeper (a good thing).
  • 18. Result? ● Brokers keep very little state, mostly just open file pointers and connections ● Can scale to thousands of producers and consumers* ● Stable performance, good scalability ● In 0.7, 50MB/s producer throughput, 100MB/s consumer throughput ● No numbers yet from 0.8, but the same comparable (with acks=0)
  • 19. TOC ● Project overview ● Architecture ● Implementation ● Miscellany
  • 20. High-level producer API Producer#send(KeyedMessage<K,V> datum) KeyedMessage<K,V>(String topic, K key, V value) The Producer class determines where a message is sent based on the routing key. If a null key is given, the message is sent to a random partition
  • 21. Message routing Partition 0 Partition 1 Topic A Broker 1 Partition 0 Partition 1 Topic A Broker 2 hash("foo") % 4 Partitioner Producer.send("A", "foo", messages) Producer
  • 22. Message routing ● Producers can be configured with a custom routing function (implementing the Partitioner interface) ● Default is hash-mod ● One side effect of routing is that there is no total ordering for a topic, but there is within a partition (this is actually really useful)
  • 23. (Partially) Ordered Messages Consider a system that is processing updates. If you partition the messages based on the primary key you guarantee all messages for a given key end up in the same partition. Since Kafka guarantees ordering of the messages at the partition level, your updates will be processed in the correct sequence.
  • 24. Persistent Messages ● MessageSets received by the broker and flushed to append-only log files ● Simple log format (next slide) ● Zero-copy (i.e., sendfile) for file to socket transfer ● Log files are not kept forever
  • 26. Message sets ● To maximize throughput, the same binary format for messages is used throughout the system (producer API, consumer API, and log file format) ● Broker only decodes far enough to read the checksum and validate it, then writes it to the disk
  • 27. Compressed message sets or, message batching ● The value of a Message can be a compressed MessageSet Message(value=gzip(MessageSet(...))) ● Useful for increasing throughput (especially if you are buffering messages in the producer) ● Can also be used as a way to atomically write multiple messages
  • 28. Zero-copy Reading data out of Kafka is super fast thanks to java.nio.channels.FileChannel#transferTo. This method uses the "sendfile" system call which allows for very efficient transfer of data from a file to another file (including sockets). This optimization is what allows us to pull ~100MB/s out of a single broker
  • 29. High-level Consumer API Map topicMap = Collections.singletonMap("topic", 2); Map<String,List<KafkaStream>> streams = Consumer.createJavaConsumerConnector(topicMap); ● KafkaStream is an iterable ● Blocking or non-blocking behavior ● Auto-commit offset, or manual commit ● Participate in a "consumer group"
  • 30. Consumer Groups Multiple high-level consumers can participate in a single "consumer group". A consumer group is coordinated using ZooKeeper, so it can span multiple machines. In a group, each partition will be consumed by exactly one consumer (i. e., KafkaStream). This allows for broadcast or pub/sub type of messaging pattern
  • 31. Consumer Groups P0 P1 Topic "foo" Broker 1 Consumer Group A Consumer Group B P2 P3 Topic "foo" Broker 2
  • 32. TOC ● Project overview ● Architecture ● Implementation ● Miscellany
  • 33. But, I already have a MQ Many people with distributed systems already have something like JMS, RabbitMQ, Kestrel, or ØMQ in place. These are all different systems with different implementation details and semantics. Decide what features you need, and then chose a MQ - not the other way around :) RabbitMQ discussion: http://bit.ly/140ZMOx
  • 34. Caveats ● Not designed for large payloads. Decoding is done for a whole message (no streaming decoding). ● Rebalancing can screw things up if you're doing any aggregation in the consumer by the partition key ● Number of partitions cannot be easily changed (chose wisely) ● Lots of topics can hurt I/O performance
  • 35. Clients ● Many exist, some more complete than others ● No official clients (other than Java/Scala) ● Community maintained ● Most lack support for high-level consumer due to ZooKeeper dependency (it's tricky) ● Excellent Python client: https://github. com/mumrah/kafka-python (yes, I wrote it) ● Only Python, C, and Clojure support the 0.8 protocol
  • 36. Hadoop InputFormat ● InputFormat/OutputFormat implementations ● Uses low-level consumer, no offsets in ZK (they are stored on HDFS instead) ● Useful for long term storage of messages ● We use this! ● LinkedIn released Camus, a Kafka to HDFS pipeline
  • 37. Integration A few good integration points. I expect more to show up as Kafka gains adoption ● log4j appender (in Kafka itself) ● storm-kafka (in storm-contrib) ● camel-kafka ● LogStash (loges) More listed on Kafka wiki http://bit.ly/1btZz8p
  • 38. Applications Log Aggregation Many applications running on many machines. You want centralized logging, but don't want to install an agent (Flume, etc). Kafka includes a log4j appender <appender class="kafka.producer.KafkaLog4jAppender" name="kafka-solr"> <param name="zkConnect" value="localhost:2181"/> <param name="topic" value="solr-logs"/> <layout class="org.apache.log4j.PatternLayout"> <param value="%d{ISO8601} %p %c %m" name="ConversionPattern"/> </layout> </appender>
  • 39. Applications Notifications Store data into data store A, need to sync it to data store B. Suppose you can send a message to Kafka when an update happens in A A Kafka Brecord X changed get updated record X
  • 40. Applications Stream Processing Using a stream processing tool like Storm or Apache Camel, Kafka provides an excellent backbone. Data in Kafka topic A Process A Kafka topic B Process B
  • 41. Bonus Slides Stats LinkedIn stats: ● Peak writes per second: 460k ● Average writes per day: 28 billion ● Average reads per second: 2.3 million ● ~700 topics ● Thousands of producers ● ~1000 consumers
  • 42. Bonus Slides Logos! Being heatedly debated in JIRA as we speak!
  • 43. Links! ● Slides: http://bit.ly/kafka-trihug ● Kafka Project: http://kafka.apache.org/ ● Kafka Code: https://github.com/apache/kafka ● LinkedIn Camus: https://github.com/linkedin/camus ● Zero-Copy IBM article: http://ibm.co/gsETNm ● LinkedIn Kafka paper: http://bit.ly/mC8TLS ● LinkedIn blog post on replication: http://linkd.in/YAWslH