跳到主要内容

Kafka: a Distributed Messaging System for Log Processing

Background

設計一套可以支援online and offlice且巨量資料的log aggregator。

Partition

每個topic可以含有複數個partition,當producer push message的時候,message根據partition key或是隨機分配到一個partition。

為了能提高throughput,每個partition概念上都是一個logic file,message來的時候只能append。實作上,每個parition含有數個檔案大小相近的log filebroker會紀錄每個log file的起始offset id,如果consumer要讀,就根據offset id決定從哪個檔案開始讀。

Stateless broker

broker不處理coordination,全部交給zookeeper處理(現在已經不需要zookeeperetcd也可以)。

對一個consumer group,每個partition只會assign給一個consumer,並且把這個consumer group在這個parition ack的offset id記在zookeeper,當有broker或是consumer掛掉導致rebalance的時候,接手的consumer才知道某個partition最後處理到哪個record。

Delivery Guarantees

Kafka支援at-least-once的delivery,如果有個record被處理完也ack了,但broker掛掉沒更新consumer group to partition的offset id,則message會被在transmit一遍。