Understanding Topics, Partitions, and Brokers: Ryan Plant
Understanding Topics, Partitions, and Brokers: Ryan Plant
Brokers
Ryan Plant
COURSE AUTHOR
@ryan_plant blog.ryanplant.com
Basic Apache Kafka installation:
- Download the binary package
Demo - Extract the archive
- Explore the installation directory
contents
Prerequisites:
- Linux operating system
- Java 8 JDK installed
- Scala 2.11.x installed
Apache Kafka Topics
Logical entity
Physically represented as a log
to: “my_topic”
to: “my_other_topic”
0 1 2 3 4 5 6 7 8 9
“MY_TOPIC”
Event Sourcing
An architectural style or approach to maintaining an
application’s state by capturing all changes as a
sequence of time-ordered, immutable events.
older newer
0 1 2 3 4 5 6 7 8 9
“MY_TOPIC”
Message Content
{timestamp}
Each message has a:
- Timestamp
[data content]
0 1 2 3 4 5 6 7 8 9
“MY_TOPIC”
The Offset
A placeholder:
- Last read message position
- Maintained by the Kafka Consumer
- Corresponds to the message identifier
0 1 2 3 n
“MY_TOPIC”
“from beginning”
offset: 0
offset: 0
offset: 3
0 1 2 3 4 5 6 7 8 9
“MY_TOPIC”
3 8
Message Retention Policy
older newer
0 1 2 3 4 5 6 7 8 9
TOPIC
Append-only
Ordered sequence (by time)
Immutable facts as events
Transaction or Commit Logs
Source of truth
Physically stored and maintained
Higher-order data structures derive from
the log
- Tables, indexes, views, etc.
Point of recovery
Basis for replication and distribution
Apache Kafka is publish-
subscribe messaging
rethought as a distributed
commit log.
Kafka Partitions
0 1 2 3 4 5 6 7 8 n
/tmp/kafka-logs/{topic}-{partition}
“my_topic-0”
.index
Broker
.log
Partition 0
0 1 2 3 4 5 6 7 8 9
Partition 1
0 1 2 3 4 5 6 7 8 9
Partition 2
0 1 2 3 4 5 6 7 8
older newer
$.s
--create h
1 available brokers
--topic my_topic ZK
--partitions 3 2
--rep-factor 1 assign partitions to leaders
3 status checks
I have
partition 1 of
my_topic I have
id=0 id=1 partition 2 of id=2
my_topic
I have
partition 0 of
my_topic-1 my_topic my_topic-0 my_topic-2
metadata metadata metadata
$.s
h
--broker-list {broker:2}
--topic my_topic ZK
metadata
…
3 1
2
id=0 id=1 id=2
I now have
id=0 id=1 partition 0 of id=2
my_topic
my_topic-0
my_topic-1 my_topic-0 my_topic-2
Guarantees
- N-1 broker failure tolerance
- 2 or 3 minimum
Kafka in action
- Demos
- Configuration