Apache Kafka Partitions as Unit of Durability
Learn what to consider when designing your Kafka replication strategy
replica.lag.time.max.ms
will be marked as out-of-sync replicas. Anecdotally, they don't use OSR as an acronym. 🤷🏻ack
property from the producer configuration. Setting this property to 0
will tell the producer to not wait for anything after events are sent to the brokers. The acknowledgment comes back right away, and no guarantees are provided. Setting this property to 1
provides the guarantee that at least the leader replica needs to store the event before returning the acknowledgement. Finally, setting this property to all
provides the guarantee that all ISRs need to store the event before returning the acknowledgment. While it may be tempting to set the ack
property to all
at all times, please be aware that doing so also increases the producer latency. By producer latency, I mean the time it takes for the producer to write events to Kafka. But for the sake of end-to-end latency, this isn't much of a problem. To ensure data consistency, Kafka doesn't allow consumers to read events that haven't been written to all ISRs, anyway.kafka-topics
that are available in the /bin
folder of your Kafka distribution can be used to investigate the details about the topic's partitions, replicas, and which replicas are ISRs.1
kafka-topics --bootstrap-server <BROKER_ENDPOINT> --topic <TOPIC_NAME> --describe
1
2
3
4
5
Topic: replicasTest TopicId: VAE9FZCOTH2OlLLM8Mn82A PartitionCount: 4 ReplicationFactor: 3 Configs: segment.bytes=1073741824
Topic: replicasTest Partition: 0 Leader: 2 Replicas: 2,1,0 Isr: 2,1,0 Offline:
Topic: replicasTest Partition: 1 Leader: 1 Replicas: 1,0,2 Isr: 1,0,2 Offline:
Topic: replicasTest Partition: 2 Leader: 0 Replicas: 0,2,1 Isr: 0,2,1 Offline:
Topic: replicasTest Partition: 3 Leader: 2 Replicas: 2,0,1 Isr: 2,0,1 Offline:
poll()
function from the consumer is invoked. Because it is the same fetch request for both — they are served by the same request processing model. Here is how it works. Fetch requests are received by one thread from a pool called network threads. These threads are associated with the listener port of each broker. Once a network thread finishes receiving the request, it adds the request to an in-memory FIFO queue that will be eventually processed by one thread from another pool called I/O threads. Figure 4 shows this in more details.3
and the default value set for the I/O thread pool is 8
. In theory, a naïve solution to resolve the problem of busy threads is increasing these pools in higher numbers. However, doing this doesn't solve the problem. In fact, it may actually make the situation worse, as more threads mean more context switching between the CPUs. If you don't have enough CPUs in the broker node, then this is likely to happen. Having partitions as your unit-of-durability is a good thing for the sake of data consistency, but you must use this information wisely to avoid problems with busy clusters.