SlideShare a Scribd company logo
1 of 33
© 2015, Conversant, Inc. All rights reserved.
PRESENTED BY
November 10, 2016
Data Loss and Data Duplication
in Kafka
Jayesh Thakrar
© 2015, Conversant, Inc. All rights reserved.2
Kafka is a distributed, partitioned, replicated,
durable commit log service. It provides the
functionality of a messaging system, but with a
unique design.
Exactly once - each message is delivered once
and only once
© 2015, Conversant, Inc. All rights reserved.3
 Kafka Overview
 Data Loss
 Data Duplication
 Data Loss and Duplicate Prevention
 Monitoring
AGENDA
© 2015, Conversant, Inc. All rights reserved.4
Kafka Overview
© 2015, Conversant, Inc. All rights reserved.5
Kafka As A Log Abstraction
Client: Producer
Client: Consumer BClient: Consumer A
Kafka Server = Kafka Broker
Topic: app_events
Source: https://engineering.linkedin.com/distributed-systems/log-what-every-software-engineer-should-know-about-real-time-datas-unifying
© 2015, Conversant, Inc. All rights reserved.6
Topic Partitioning . . .
Kafka Broker
Client: Producer or Consumer
Source: https://engineering.linkedin.com/distributed-systems/log-what-every-software-engineer-should-know-about-real-time-datas-unifying
Topic: app_events
© 2015, Conversant, Inc. All rights reserved.7
Topic Partitioning – Scalability
Clients: Producer, Consumer
Leader
Replica
Replica
Leader
Replica
Replica
Leader
Replica
Replica
Kafka Broker 0
Kafka Broker 1
Kafka Broker 2
© 2015, Conversant, Inc. All rights reserved.8
Topic Partitioning – redundancy
Client: Producer, Consumer
Kafka Broker 2
Leader
Replica
Replica
Leader
Replica
Replica
Leader
Replica
Replica
Kafka Broker 0
Kafka Broker 1
© 2015, Conversant, Inc. All rights reserved.9
Topic Partitioning – Redundancy/durability
Kafka Broker 2
Leader
Replica
Replica
Leader
Replica
Replica
Leader
Replica
Replica
Kafka Broker 0
Kafka Broker 1
Pull-based inter-broker replication
© 2015, Conversant, Inc. All rights reserved.10
Topic Partitioning – summary
 Log sharded into partitions
 Messages assigned to partitions by API or custom partitioner
 Partitions assigned to brokers (manual or automatic)
 Partitions replicated (as needed)
 Messages ordered within each partition
 Message offset = absolute position in partition
 Partitions stored on filesystem as
ordered sequence of log segments (files)
© 2015, Conversant, Inc. All rights reserved.11
Other Key Concepts
 Cluster = collection of brokers
 Broker-id = a unique id (integer) assigned to each broker
 Controller = functionality within each broker responsible for leader
assignment and management, with one being the active controller
 Replica = partition copy, represented (identified) by the broker-id
 Assigned replicas = set of all replicas (broker-ids) for a partition
 ISR = In-Sync Replicas = subset of assigned replicas (brokers) that
are “in-sync/caught-up”* with the leader (ISR always includes the leader)
© 2015, Conversant, Inc. All rights reserved.12
Data Loss
© 2015, Conversant, Inc. All rights reserved.13
Data Loss : Inevitable
Upto 0.01% data loss
For 700 billion messages / day,
that's up to 7 million / day
© 2015, Conversant, Inc. All rights reserved.14
Data loss at the producer
Kafka Producer API
API Call-tree
kafkaProducer.send()
…. accumulator.append() // buffer
…. sender.send() // network I/O
•Messages accumulate in buffer in batches
•Batched by partition, retry at batch level
•Expired batches dropped after retries
•Error count and other metrics via JMX
Data Loss at Producer
•Failure to close / flush producer on
termination
•Dropped batches due to communication
or other errors when acks = 0 or retry
exhaustion
•Data produced faster than delivery,
causing BufferExhaustedException
(deprecated in 0.10+)
© 2015, Conversant, Inc. All rights reserved.15
dATA LOSS AT The CLUSTER (BY BROKERS)
Was it
a
leader?
Detected by
Controller via
zookeeper
Was it
in ISR?
Other
replicas
in ISR?
Elect another
leader
Allow
unclean
election?
ISR >=
min.insync
.replicas?
Relax, everything will
be fine
Partition
unavailable !!
Other
replicas
available?
Y Y
N
N
Y
Y
Y
Y
N
Broker
Crashes
N
N
N
1
2
4
5 6
3
7
© 2015, Conversant, Inc. All rights reserved.16
Non-leader broker crash
Was it
a
leader?
Detected by
Controller via
zookeeper
Was it
in ISR?
Other
replicas
in ISR?
Elect another
leader
Allow
unclean
election?
ISR >=
min.insync
.replicas?
Relax, everything will
be fine
Partition
unavailable !!
Other
replicas
available?
Y Y
N
N
Y
Y
Y
Y
N
Broker
Crashes
N
N
N
1
2
4
5 6
3
7
© 2015, Conversant, Inc. All rights reserved.17
Leader broker crash: Scenario 1
Was it
a
leader?
Detected by
Controller via
zookeeper
Was it
in ISR?
Other
replicas
in ISR?
Elect another
leader
Allow
unclean
election?
ISR >=
min.insync
.replicas?
Relax, everything will
be fine
Partition
unavailable !!
Other
replicas
available?
Y Y
N
N
Y
Y
Y
Y
N
Broker
Crashes
N
N
N
1
2
4
5 6
3
7
© 2015, Conversant, Inc. All rights reserved.18
Leader broker crash: Scenario 2
Was it
a
leader?
Detected by
Controller via
zookeeper
Was it
in ISR?
Other
replicas
in ISR?
Elect another
leader
Allow
unclean
election?
ISR >=
min.insync
.replicas?
Relax, everything will
be fine
Partition
unavailable !!
Other
replicas
available?
Y Y
N
N
Y
Y
Y
Y
N
Broker
Crashes
N
N
N
1
2
4
5 6
3
7
© 2015, Conversant, Inc. All rights reserved.19
dATA LOSS AT The CLUSTER (BY BROKERS)
Was it
a
leader?
Detected by
Controller via
zookeeper
Was it
in ISR?
Other
replicas
in ISR?
Elect another
leader
Allow
unclean
election?
ISR >=
min.insync
.replicas?
Relax, everything will
be fine
Partition
unavailable !!
Other
replicas
available?
Y Y
N
N
Y
Y
Y
Y
N
Potential data-loss
depending upon acks
config at producer. See
KAFKA-3919
KAFKA-4215
Broker
Crashes
N
N
N
1
2
4
5 6
3
7
© 2015, Conversant, Inc. All rights reserved.20
FROM KAFKA-3919
© 2015, Conversant, Inc. All rights reserved.21
FROM KAFKA-4215
© 2015, Conversant, Inc. All rights reserved.22
Config for Data Durability and Consistency
 Producer config
- acks = -1 (or all)
- max.block.ms (blocking on buffer full, default = 60000) and retries
- request.timeout.ms (default = 30000) – it triggers retries
 Topic config
- min.insync.replicas = 2 (or higher)
 Broker config
- unclean.leader.election.enable = false
- timeout.ms (default = 30000) – inter-broker timeout for acks
© 2015, Conversant, Inc. All rights reserved.23
Config for Availability and Throughput
 Producer config
- acks = 0 (or 1)
- buffer.memory, batch.size, linger.ms (default = 100)
- request.timeout.ms, max.block.ms (default = 60000), retries
- max.in.flight.requests.per.connection
 Topic config
- min.insync.replicas = 1 (default)
 Broker config
- unclean.leader.election.enable = true
© 2015, Conversant, Inc. All rights reserved.24
Data Duplication
© 2015, Conversant, Inc. All rights reserved.25
Data Duplication: How it occurs
Client: Producer
Client: Consumer BClient: Consumer A
Kafka Broker
Topic: app_events
Producer (API)
retries = messages
resent after timeout
when retries > 1
Consumer
consumes messages
more than once after
restart from unclean
shutdown / crash
© 2015, Conversant, Inc. All rights reserved.26
Data Loss &
Duplication
Detection
© 2015, Conversant, Inc. All rights reserved.27
How to Detect Data loss & Duplication - 1
Memcache /
HBase /
Cassandra /
Other
Producer Kafka Consumer
Topic, Partition, Offset | Msg Key or
Hash
KEY | VALUE
1) Msg from producer to Kafka
2) Ack from Kafka with details
3) Producer inserts into store
4) Consumer reads msg
5) Consumer validates msg
If exists
not duplicate
consume msg
delete msg
If missing
duplicate msg
Audit: Remaining msgs in store are
"lost" or "unconsumed" msgs
11
22
33
44
55Store
© 2015, Conversant, Inc. All rights reserved.28
How to Detect Data loss & Duplication - 2
Memcache /
HBase /
Cassandra /
Other
Producer Kafka Consumer
Source, time-window | Msg count or some other checksum (e.g. totals, etc)
KEY | VALUE
1) Msg from producer to Kafka
2) Ack from Kafka with details
3) Producer maintains window stats
4) Consumer reads msg
5) Consumer validates window
stats at end of interval
11
22
33
44
55Store
© 2015, Conversant, Inc. All rights reserved.29
Data Duplication: How to minimize at consumer
Client: Producer
Client: Consumer BClient: Consumer A
Kafka Broker
Topic: app_events
If possible,
lookup last
processed offset
in destination at
startup
© 2015, Conversant, Inc. All rights reserved.30
Monitoring
© 2015, Conversant, Inc. All rights reserved.31
Monitoring and Operations: JMX Metrics
Producer JMX Consumer JMX
© 2015, Conversant, Inc. All rights reserved.32
Questions?
© 2015, Conversant, Inc. All rights reserved.33
Jayesh Thakrar
jthakrar@conversantmedia.com

More Related Content

What's hot

What's hot (20)

Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)
 
Improving Kafka at-least-once performance at Uber
Improving Kafka at-least-once performance at UberImproving Kafka at-least-once performance at Uber
Improving Kafka at-least-once performance at Uber
 
Apache Kafka – (Pattern and) Anti-Pattern
Apache Kafka – (Pattern and) Anti-PatternApache Kafka – (Pattern and) Anti-Pattern
Apache Kafka – (Pattern and) Anti-Pattern
 
Apache Kafka
Apache KafkaApache Kafka
Apache Kafka
 
How Apache Kafka® Works
How Apache Kafka® WorksHow Apache Kafka® Works
How Apache Kafka® Works
 
Tradeoffs in Distributed Systems Design: Is Kafka The Best? (Ben Stopford and...
Tradeoffs in Distributed Systems Design: Is Kafka The Best? (Ben Stopford and...Tradeoffs in Distributed Systems Design: Is Kafka The Best? (Ben Stopford and...
Tradeoffs in Distributed Systems Design: Is Kafka The Best? (Ben Stopford and...
 
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
 
Getting up to speed with MirrorMaker 2 | Mickael Maison, IBM and Ryanne Dolan...
Getting up to speed with MirrorMaker 2 | Mickael Maison, IBM and Ryanne Dolan...Getting up to speed with MirrorMaker 2 | Mickael Maison, IBM and Ryanne Dolan...
Getting up to speed with MirrorMaker 2 | Mickael Maison, IBM and Ryanne Dolan...
 
Kafka 101 and Developer Best Practices
Kafka 101 and Developer Best PracticesKafka 101 and Developer Best Practices
Kafka 101 and Developer Best Practices
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
ksqlDB: A Stream-Relational Database System
ksqlDB: A Stream-Relational Database SystemksqlDB: A Stream-Relational Database System
ksqlDB: A Stream-Relational Database System
 
Deep Dive into Apache Kafka
Deep Dive into Apache KafkaDeep Dive into Apache Kafka
Deep Dive into Apache Kafka
 
Kafka Tutorial: Advanced Producers
Kafka Tutorial: Advanced ProducersKafka Tutorial: Advanced Producers
Kafka Tutorial: Advanced Producers
 
kafka
kafkakafka
kafka
 
Apache Kafka - Martin Podval
Apache Kafka - Martin PodvalApache Kafka - Martin Podval
Apache Kafka - Martin Podval
 
Kafka Streams vs. KSQL for Stream Processing on top of Apache Kafka
Kafka Streams vs. KSQL for Stream Processing on top of Apache KafkaKafka Streams vs. KSQL for Stream Processing on top of Apache Kafka
Kafka Streams vs. KSQL for Stream Processing on top of Apache Kafka
 
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?
 
Apache Kafka at LinkedIn
Apache Kafka at LinkedInApache Kafka at LinkedIn
Apache Kafka at LinkedIn
 
Building Microservices with Apache Kafka
Building Microservices with Apache KafkaBuilding Microservices with Apache Kafka
Building Microservices with Apache Kafka
 
Kafka 101
Kafka 101Kafka 101
Kafka 101
 

Similar to Data Loss and Duplication in Kafka

Kafka/SMM Crash Course
Kafka/SMM Crash CourseKafka/SMM Crash Course
Kafka/SMM Crash Course
DataWorks Summit
 

Similar to Data Loss and Duplication in Kafka (20)

BDW Chicago 2016 - Jayesh Thakrar, Sr. Software Engineer, Conversant - Data...
BDW Chicago 2016 -  Jayesh Thakrar, Sr. Software Engineer, Conversant -  Data...BDW Chicago 2016 -  Jayesh Thakrar, Sr. Software Engineer, Conversant -  Data...
BDW Chicago 2016 - Jayesh Thakrar, Sr. Software Engineer, Conversant - Data...
 
Sf bay area Kubernetes meetup dec8 2016 - deployment models
Sf bay area Kubernetes meetup dec8 2016 - deployment modelsSf bay area Kubernetes meetup dec8 2016 - deployment models
Sf bay area Kubernetes meetup dec8 2016 - deployment models
 
Can Containers be Secured in a PaaS?
Can Containers be Secured in a PaaS?Can Containers be Secured in a PaaS?
Can Containers be Secured in a PaaS?
 
Can Containers be secured in a PaaS?
Can Containers be secured in a PaaS?Can Containers be secured in a PaaS?
Can Containers be secured in a PaaS?
 
Not Your Mother's Kafka - Deep Dive into Confluent Cloud Infrastructure | Gwe...
Not Your Mother's Kafka - Deep Dive into Confluent Cloud Infrastructure | Gwe...Not Your Mother's Kafka - Deep Dive into Confluent Cloud Infrastructure | Gwe...
Not Your Mother's Kafka - Deep Dive into Confluent Cloud Infrastructure | Gwe...
 
Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...
Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...
Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...
 
Running Kubernetes with Amazon EKS - AWS Online Tech Talks
Running Kubernetes with Amazon EKS - AWS Online Tech TalksRunning Kubernetes with Amazon EKS - AWS Online Tech Talks
Running Kubernetes with Amazon EKS - AWS Online Tech Talks
 
CFSummit ColdFusion 2015 Load Balancing, Failover and Scalability
CFSummit ColdFusion 2015 Load Balancing, Failover and ScalabilityCFSummit ColdFusion 2015 Load Balancing, Failover and Scalability
CFSummit ColdFusion 2015 Load Balancing, Failover and Scalability
 
Load Balancing, Failover and Scalability with ColdFusion
Load Balancing, Failover and Scalability with ColdFusionLoad Balancing, Failover and Scalability with ColdFusion
Load Balancing, Failover and Scalability with ColdFusion
 
Cloud Foundry Diego, Lattice, Docker and more
Cloud Foundry Diego, Lattice, Docker and moreCloud Foundry Diego, Lattice, Docker and more
Cloud Foundry Diego, Lattice, Docker and more
 
Kafka/SMM Crash Course
Kafka/SMM Crash CourseKafka/SMM Crash Course
Kafka/SMM Crash Course
 
Flavors of HA
Flavors of HAFlavors of HA
Flavors of HA
 
(Very) Loose proposal to revamp MPI_INIT and MPI_FINALIZE
(Very) Loose proposal to revamp MPI_INIT and MPI_FINALIZE(Very) Loose proposal to revamp MPI_INIT and MPI_FINALIZE
(Very) Loose proposal to revamp MPI_INIT and MPI_FINALIZE
 
Presentazione SimpliVity @ VMUGIT UserCon 2015
Presentazione SimpliVity @ VMUGIT UserCon 2015Presentazione SimpliVity @ VMUGIT UserCon 2015
Presentazione SimpliVity @ VMUGIT UserCon 2015
 
OpenSlava Infrastructure Automation Patterns
OpenSlava   Infrastructure Automation PatternsOpenSlava   Infrastructure Automation Patterns
OpenSlava Infrastructure Automation Patterns
 
intro-kafka
intro-kafkaintro-kafka
intro-kafka
 
K8Guard - An Auditing System For Kubernetes
K8Guard - An Auditing System For KubernetesK8Guard - An Auditing System For Kubernetes
K8Guard - An Auditing System For Kubernetes
 
Declarative Infrastructure with Cloud Foundry BOSH
Declarative Infrastructure with Cloud Foundry BOSHDeclarative Infrastructure with Cloud Foundry BOSH
Declarative Infrastructure with Cloud Foundry BOSH
 
Gatekeeper: API gateway
Gatekeeper: API gatewayGatekeeper: API gateway
Gatekeeper: API gateway
 
Cisco at v mworld 2015 shipped-vmworld
Cisco at v mworld 2015 shipped-vmworldCisco at v mworld 2015 shipped-vmworld
Cisco at v mworld 2015 shipped-vmworld
 

More from Jayesh Thakrar

ApacheCon-Flume-Kafka-2016
ApacheCon-Flume-Kafka-2016ApacheCon-Flume-Kafka-2016
ApacheCon-Flume-Kafka-2016
Jayesh Thakrar
 
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Jayesh Thakrar
 

More from Jayesh Thakrar (7)

ApacheCon North America 2018: Creating Spark Data Sources
ApacheCon North America 2018: Creating Spark Data SourcesApacheCon North America 2018: Creating Spark Data Sources
ApacheCon North America 2018: Creating Spark Data Sources
 
Apache big-data-2017-spark-profiling
Apache big-data-2017-spark-profilingApache big-data-2017-spark-profiling
Apache big-data-2017-spark-profiling
 
Data Modeling for IoT and Big Data
Data Modeling for IoT and Big DataData Modeling for IoT and Big Data
Data Modeling for IoT and Big Data
 
Apache big-data-2017-scala-sql
Apache big-data-2017-scala-sqlApache big-data-2017-scala-sql
Apache big-data-2017-scala-sql
 
ApacheCon-Flume-Kafka-2016
ApacheCon-Flume-Kafka-2016ApacheCon-Flume-Kafka-2016
ApacheCon-Flume-Kafka-2016
 
ApacheCon-HBase-2016
ApacheCon-HBase-2016ApacheCon-HBase-2016
ApacheCon-HBase-2016
 
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
 

Data Loss and Duplication in Kafka

  • 1. © 2015, Conversant, Inc. All rights reserved. PRESENTED BY November 10, 2016 Data Loss and Data Duplication in Kafka Jayesh Thakrar
  • 2. © 2015, Conversant, Inc. All rights reserved.2 Kafka is a distributed, partitioned, replicated, durable commit log service. It provides the functionality of a messaging system, but with a unique design. Exactly once - each message is delivered once and only once
  • 3. © 2015, Conversant, Inc. All rights reserved.3  Kafka Overview  Data Loss  Data Duplication  Data Loss and Duplicate Prevention  Monitoring AGENDA
  • 4. © 2015, Conversant, Inc. All rights reserved.4 Kafka Overview
  • 5. © 2015, Conversant, Inc. All rights reserved.5 Kafka As A Log Abstraction Client: Producer Client: Consumer BClient: Consumer A Kafka Server = Kafka Broker Topic: app_events Source: https://engineering.linkedin.com/distributed-systems/log-what-every-software-engineer-should-know-about-real-time-datas-unifying
  • 6. © 2015, Conversant, Inc. All rights reserved.6 Topic Partitioning . . . Kafka Broker Client: Producer or Consumer Source: https://engineering.linkedin.com/distributed-systems/log-what-every-software-engineer-should-know-about-real-time-datas-unifying Topic: app_events
  • 7. © 2015, Conversant, Inc. All rights reserved.7 Topic Partitioning – Scalability Clients: Producer, Consumer Leader Replica Replica Leader Replica Replica Leader Replica Replica Kafka Broker 0 Kafka Broker 1 Kafka Broker 2
  • 8. © 2015, Conversant, Inc. All rights reserved.8 Topic Partitioning – redundancy Client: Producer, Consumer Kafka Broker 2 Leader Replica Replica Leader Replica Replica Leader Replica Replica Kafka Broker 0 Kafka Broker 1
  • 9. © 2015, Conversant, Inc. All rights reserved.9 Topic Partitioning – Redundancy/durability Kafka Broker 2 Leader Replica Replica Leader Replica Replica Leader Replica Replica Kafka Broker 0 Kafka Broker 1 Pull-based inter-broker replication
  • 10. © 2015, Conversant, Inc. All rights reserved.10 Topic Partitioning – summary  Log sharded into partitions  Messages assigned to partitions by API or custom partitioner  Partitions assigned to brokers (manual or automatic)  Partitions replicated (as needed)  Messages ordered within each partition  Message offset = absolute position in partition  Partitions stored on filesystem as ordered sequence of log segments (files)
  • 11. © 2015, Conversant, Inc. All rights reserved.11 Other Key Concepts  Cluster = collection of brokers  Broker-id = a unique id (integer) assigned to each broker  Controller = functionality within each broker responsible for leader assignment and management, with one being the active controller  Replica = partition copy, represented (identified) by the broker-id  Assigned replicas = set of all replicas (broker-ids) for a partition  ISR = In-Sync Replicas = subset of assigned replicas (brokers) that are “in-sync/caught-up”* with the leader (ISR always includes the leader)
  • 12. © 2015, Conversant, Inc. All rights reserved.12 Data Loss
  • 13. © 2015, Conversant, Inc. All rights reserved.13 Data Loss : Inevitable Upto 0.01% data loss For 700 billion messages / day, that's up to 7 million / day
  • 14. © 2015, Conversant, Inc. All rights reserved.14 Data loss at the producer Kafka Producer API API Call-tree kafkaProducer.send() …. accumulator.append() // buffer …. sender.send() // network I/O •Messages accumulate in buffer in batches •Batched by partition, retry at batch level •Expired batches dropped after retries •Error count and other metrics via JMX Data Loss at Producer •Failure to close / flush producer on termination •Dropped batches due to communication or other errors when acks = 0 or retry exhaustion •Data produced faster than delivery, causing BufferExhaustedException (deprecated in 0.10+)
  • 15. © 2015, Conversant, Inc. All rights reserved.15 dATA LOSS AT The CLUSTER (BY BROKERS) Was it a leader? Detected by Controller via zookeeper Was it in ISR? Other replicas in ISR? Elect another leader Allow unclean election? ISR >= min.insync .replicas? Relax, everything will be fine Partition unavailable !! Other replicas available? Y Y N N Y Y Y Y N Broker Crashes N N N 1 2 4 5 6 3 7
  • 16. © 2015, Conversant, Inc. All rights reserved.16 Non-leader broker crash Was it a leader? Detected by Controller via zookeeper Was it in ISR? Other replicas in ISR? Elect another leader Allow unclean election? ISR >= min.insync .replicas? Relax, everything will be fine Partition unavailable !! Other replicas available? Y Y N N Y Y Y Y N Broker Crashes N N N 1 2 4 5 6 3 7
  • 17. © 2015, Conversant, Inc. All rights reserved.17 Leader broker crash: Scenario 1 Was it a leader? Detected by Controller via zookeeper Was it in ISR? Other replicas in ISR? Elect another leader Allow unclean election? ISR >= min.insync .replicas? Relax, everything will be fine Partition unavailable !! Other replicas available? Y Y N N Y Y Y Y N Broker Crashes N N N 1 2 4 5 6 3 7
  • 18. © 2015, Conversant, Inc. All rights reserved.18 Leader broker crash: Scenario 2 Was it a leader? Detected by Controller via zookeeper Was it in ISR? Other replicas in ISR? Elect another leader Allow unclean election? ISR >= min.insync .replicas? Relax, everything will be fine Partition unavailable !! Other replicas available? Y Y N N Y Y Y Y N Broker Crashes N N N 1 2 4 5 6 3 7
  • 19. © 2015, Conversant, Inc. All rights reserved.19 dATA LOSS AT The CLUSTER (BY BROKERS) Was it a leader? Detected by Controller via zookeeper Was it in ISR? Other replicas in ISR? Elect another leader Allow unclean election? ISR >= min.insync .replicas? Relax, everything will be fine Partition unavailable !! Other replicas available? Y Y N N Y Y Y Y N Potential data-loss depending upon acks config at producer. See KAFKA-3919 KAFKA-4215 Broker Crashes N N N 1 2 4 5 6 3 7
  • 20. © 2015, Conversant, Inc. All rights reserved.20 FROM KAFKA-3919
  • 21. © 2015, Conversant, Inc. All rights reserved.21 FROM KAFKA-4215
  • 22. © 2015, Conversant, Inc. All rights reserved.22 Config for Data Durability and Consistency  Producer config - acks = -1 (or all) - max.block.ms (blocking on buffer full, default = 60000) and retries - request.timeout.ms (default = 30000) – it triggers retries  Topic config - min.insync.replicas = 2 (or higher)  Broker config - unclean.leader.election.enable = false - timeout.ms (default = 30000) – inter-broker timeout for acks
  • 23. © 2015, Conversant, Inc. All rights reserved.23 Config for Availability and Throughput  Producer config - acks = 0 (or 1) - buffer.memory, batch.size, linger.ms (default = 100) - request.timeout.ms, max.block.ms (default = 60000), retries - max.in.flight.requests.per.connection  Topic config - min.insync.replicas = 1 (default)  Broker config - unclean.leader.election.enable = true
  • 24. © 2015, Conversant, Inc. All rights reserved.24 Data Duplication
  • 25. © 2015, Conversant, Inc. All rights reserved.25 Data Duplication: How it occurs Client: Producer Client: Consumer BClient: Consumer A Kafka Broker Topic: app_events Producer (API) retries = messages resent after timeout when retries > 1 Consumer consumes messages more than once after restart from unclean shutdown / crash
  • 26. © 2015, Conversant, Inc. All rights reserved.26 Data Loss & Duplication Detection
  • 27. © 2015, Conversant, Inc. All rights reserved.27 How to Detect Data loss & Duplication - 1 Memcache / HBase / Cassandra / Other Producer Kafka Consumer Topic, Partition, Offset | Msg Key or Hash KEY | VALUE 1) Msg from producer to Kafka 2) Ack from Kafka with details 3) Producer inserts into store 4) Consumer reads msg 5) Consumer validates msg If exists not duplicate consume msg delete msg If missing duplicate msg Audit: Remaining msgs in store are "lost" or "unconsumed" msgs 11 22 33 44 55Store
  • 28. © 2015, Conversant, Inc. All rights reserved.28 How to Detect Data loss & Duplication - 2 Memcache / HBase / Cassandra / Other Producer Kafka Consumer Source, time-window | Msg count or some other checksum (e.g. totals, etc) KEY | VALUE 1) Msg from producer to Kafka 2) Ack from Kafka with details 3) Producer maintains window stats 4) Consumer reads msg 5) Consumer validates window stats at end of interval 11 22 33 44 55Store
  • 29. © 2015, Conversant, Inc. All rights reserved.29 Data Duplication: How to minimize at consumer Client: Producer Client: Consumer BClient: Consumer A Kafka Broker Topic: app_events If possible, lookup last processed offset in destination at startup
  • 30. © 2015, Conversant, Inc. All rights reserved.30 Monitoring
  • 31. © 2015, Conversant, Inc. All rights reserved.31 Monitoring and Operations: JMX Metrics Producer JMX Consumer JMX
  • 32. © 2015, Conversant, Inc. All rights reserved.32 Questions?
  • 33. © 2015, Conversant, Inc. All rights reserved.33 Jayesh Thakrar jthakrar@conversantmedia.com