Mission Critical Messaging with Apache Kafka
Total Page:16
File Type:pdf, Size:1020Kb
Jiangjie (Becket) Qin LinkedIn 1 2 Introduction to Apache Kafka Kafka based replication in Espresso Message Integrity guarantees Performance Large message handling Security Q&A 3 Introduction to Apache Kafka Kafka based replication in Espresso Message Integrity guarantees Performance Large message handling Security Q&A 4 5 6 7 Tracking events App2App msg. Online/Nearline Offline Metrics Data deployment ETL / Data deployment Logging Kafka (Messaging) Samza Media upload/Download Change Log (Stream proc.) (Images/Docs/Videos) Ambry Databus (Blob store) streams Media Brooklin Change Logs Online Media processing processing (Images/Docs/Videos) (Change capture) Applications Vector Hadoop Voldemort Nuage User data update /Venice Processed data (Our AWS) (K-V store) User data update Espresso Processed data (NoSQL DB) Stream Media Storage Nuage 8 Tracking events App2App msg. Online/Nearline Offline Metrics Data deployment ETL / Data deployment Logging Kafka (Messaging) Samza Media upload/Download Change Log (Stream proc.) (Images/Docs/Videos) Ambry Databus (Blob store) streams Media Brooklin Change Logs Online Media processing processing (Images/Docs/Videos) (Change capture) Applications Vector Hadoop Voldemort Nuage User data update /Venice Processed data (Our AWS) (K-V store) User data update Espresso Processed data (NoSQL DB) Stream Media Storage Nuage 下午16:40,百宴厅1,LinkedIn基于Kafka和ElasticSearch的实时日志分析 9 Tracking events App2App msg. Online/Nearline Offline Metrics Data deployment ETL / Data deployment Logging Kafka (Messaging) Samza Media upload/Download Change Log (Stream proc.) (Images/Docs/Videos) Ambry Databus (Blob store) streams Media Brooklin Change Logs Online Media processing processing (Images/Docs/Videos) (Change capture) Applications Vector Hadoop Voldemort Nuage User data update /Venice Processed data (Our AWS) (K-V store) User data update Espresso Processed data (NoSQL DB) Stream Media Storage Nuage 10 Tracking events App2App msg. Online/Nearline Offline Metrics Data deployment ETL / Data deployment Logging Kafka (Messaging) Samza Media upload/Download Change Log (Stream proc.) (Images/Docs/Videos) Ambry Databus (Blob store) streams Media Brooklin Change Logs Online Media processing processing (Images/Docs/Videos) (Change capture) Applications Vector Hadoop Voldemort Nuage User data update /Venice Processed data (Our AWS) (K-V store) User data update Espresso Processed data (NoSQL DB) Stream Media Storage Nuage 11 Tracking events App2App msg. Online/Nearline Offline Metrics Data deployment ETL / Data deployment Logging Kafka (Messaging) Samza Media upload/Download Change Log (Stream proc.) (Images/Docs/Videos) Ambry Databus (Blob store) streams Media Brooklin Change Logs Online Media processing processing (Images/Docs/Videos) (Change capture) Applications Vector Hadoop Voldemort Nuage User data update /Venice Processed data (Our AWS) (K-V store) User data update Espresso Processed data (NoSQL DB) Stream Media Storage Nuage 12 Tracking events App2App msg. Online/Nearline Offline Metrics Data deployment ETL / Data deployment Logging Kafka (Messaging) Samza Media upload/Download Change Log (Stream proc.) (Images/Docs/Videos) Ambry Databus (Blob store) streams Media Brooklin Change Logs Online Media processing processing (Images/Docs/Videos) (Change capture) Applications Vector Hadoop Voldemort Nuage User data update /Venice Processed data (Our AWS) (K-V store) User data update Espresso Processed data (NoSQL DB) Stream Media Storage Nuage 13 Tracking events App2App msg. Online/Nearline Offline Metrics Data deployment ETL / Data deployment Logging Kafka (Messaging) Samza Media upload/Download Change Log (Stream proc.) (Images/Docs/Videos) Ambry Databus (Blob store) streams Media Brooklin Change Logs Online Media processing processing (Images/Docs/Videos) (Change capture) Applications Vector Hadoop Voldemort Nuage User data update /Venice Processed data (Our AWS) (K-V store) User data update Espresso Processed data (NoSQL DB) Stream Media Storage Nuage 14 Introduction to Apache Kafka Kafka based replication in Espresso Message Integrity guarantees Performance Large message handling Security 15 Data Client Control HTTP Routing Table r Router r Router Router HTTP Apache Helix API Server API Server API Server API Server ZooKeeper r MySQL MySQL MySQL MySQL Storage Node Storage Node Storage Node Storage Node 16 MySQL instance level replication P1 P2 P3 P4 P5 P6 Node 1 Node 1 P1 P2 P3 P4 P5 P6 Node 2 Node 2 Master P1 P2 P3 P4 P5 P6 Slave Offline Node 3 Node 3 17 Kafka based partition level replication HTTP Client PUT/POST Master Slave Storage Node Storage Node API Server API Server binlog binlog SQL SQL INSERT..UPDATE INSERT..UPDATE binlog binlog MySQL event MySQL event SQL SQL INSERT..UPDATE INSERT..UPDATE Open Replicator Open Replicator Kafka Consumer Kafka Consumer Kafka Producer Kafka Producer Kafka Message Kafka Partition Kafka Message 18 No message loss In-order delivery Message Integrity Exactly once semantic High throughput Performance Low latency Handle large messages Security 19 Introduction to Apache Kafka Kafka based replication in Espresso Message Integrity guarantees Performance Large message handling Security 20 • No message loss • In-order delivery • Exactly once semantic Produce Replicate Consume 21 A well implemented producer usually supports: . Batching the messages . Sending the messages asynchronously Example: org.apache.kafka.clients.producer.KafkaProducer 22 User: producer.send(new ProducerRecord(“topic0”, “hello”), callback); topic=“topic0” topic=“topic0” Serializer Partitioner partition =0 compressor value=“hello” value=“hello” message Topic M free s Metadata callbacks CB • Serialization batch1 topic0, 0 Record Accumulator • Partitioning • Compression Tasks done by the user thread 23 Sender: 1. polls batches from the batch queues (one batch / partition) 2. groups batches based on the leader broker 3. sends the grouped batches to the brokers 4. Fire callbacks after receiving the response compressor message M free s callbacks CB batch1 topic0, 0 Broker 0 resp callbacks CB batch0 topic0, 1 …... Broker 1 batch0 batch1 batch2 topic1, 0 resp sender thread Record Accumulator 24 Enable retries in the sender . (e.g. retries=5) Keep the messages not acked yet . Espresso only checkpoints at the transaction boundary after the callback is fired acks=all 25 Leader Follower Broker 0 (leader) Broker 1 (follower) 1 ProduceRequest 2 3 Producer Log Log 4 ProduceResponse 1. [Network] Send ProduceRequest 2. [Broker] Append messages to the leader’s log 3. [Broker] Replication (before sending the response) 4. [Broker] ProduceResponse 26 In-Sync-Replica (ISR) . A replica that can keep up with the leader Semantic for acks acks Throughput Latency Durability no ack(0) high low No guarantee Leader only(1) medium medium leader All ISR(-1) low high All ISR 27 max.in.flight.requests.per.connection = 1 . Request pipelining message 0 message 1 message 0 failed Kafka Timeline Producer retry message 0 Broker message 1 ok message 0 ok max.in.flight.requests.per.connection=2 28 Close the producer in the callback with 0 timeout on failures . Callbacks are executed in the Sender thread 1.msg 0 2.callback(msg 0) ack expt. Timeline notify User Record Kafka Broker Thread Accumulator 3.msg 1 close prod. Sender Thread 29 Close the producer in the callback with 0 timeout on failures 1.msg 0 2.callback(msg 0) ack expt. Timeline User Record close(0) Kafka Broker Thread Accumulator notify Sender Thread 30 min.isr=2 . If acks=all, at least 2 copies of messages are required on the broker . replication.factor needs be 3 to tolerate single broker failure req. Broker 0 replication. Broker 1 Producer (Leader) (In-sync follower) resp. Replica = {0, 1} Replica = {0, 1} ISR = {0, 1} ISR = {0} 31 unclean.leader.election.enable= false . Only in-sync replicas can become leader Replica = {0, 1, 2} Producer ISR = {0, 1} req. resp. Broker 0 (Leader) replication. Broker 1 Broker 2 (In-sync follower) (out of sync follower) 32 Disable auto offset commit Manually commit offset . only commit offsets after successfully processing the messages 33 Exactly once delivery (Espresso) . Consumer only apply higher Generation:SCN Master Slave MySQ MySQ L L Consumer Producer Master Generation Consumer Producer Transaction Seq. (Generation:SCN) 3:100 3:101 3:102 3:102 3:102 3:103 3:104 3:104 3:104 DB_0: B,E B,E B E B,E B E B – Begin txn E – End txn C – Control 34 Introduction to Apache Kafka Kafka based replication in Espresso Message Integrity guarantees Performance Large message handling Security 35 Performance tuning is case by case . Traffic pattern sensitive . Application requirement specific Producer performance is more interesting . Especially for acks=all . See more ▪ Producer performance tuning for Apache Kafka (http://www.slideshare.net/JiangjieQin/producer-performance- tuning-for-apache-kafka-63147600) 36 Leader Follower Broker 0 (leader) Broker 1 (follower) 1 ProduceRequest 2 3 Producer Log Log 4 ProduceResponse 1. [Network] Send ProduceRequest 2. [Broker] Append messages to the leader’s log 3. [Broker] Replication (synchronously) increases latency 4. [Broker] ProduceResponse 37 Kafka replication is a pull model Increase num.replica.fetchers . Parallel fetch Not perfect solution . Diminishing effect (1/N) . Scalability concern ▪ Replica fetchers per broker = (Cluster_Size - 1 ) * num.replica.fetchers 38 Introduction to Apache Kafka Kafka based replication in Espresso Message Integrity guarantees Performance