Get Started. It's Free
or sign up with your email address
Kafka by Mind Map: Kafka

1. message queue issues

1.1. brokers need to record client positions

1.2. spaghetti of queues

1.3. skip messages

2. solutions

2.1. vs ActiveMQ/RabbitMQ

2.1.1. maintain explicit order is overkill does not guarantee that messages are processed in the order that they were received

2.1.2. how it deals with message consumers messages are not removed from system when they have been consumed. Instead relying on consumers to keep track of the offset of the last message consumed keep track of the last offset by ZooKeeper

2.2. vs Flume

2.2.1. Flume Flume is a more complete Hadoop ingestion solution has good supports for writing data to Hadoop including HDFS, HBase and Solr handles many common issues in writing data to HDFS such as reliability, optimal file sizes, file formats, updating metadata and partitioning

2.2.2. Kafka generic message broker if the requirements involve need to develop own producers and consumers

3. features

3.1. fast

3.1.1. hundred mb/s from thousands of clients

3.2. scalable

3.2.1. easily scale up and down without downtime

3.3. durable

3.3.1. messages are persisted on disk to prevent data loss

3.4. developed in Linked using Scala

4. internal structures

4.1. logical structure

4.1.1. Topic def main unit of application level data separation physical storage consists of partitions Log-structured storage append-only mechanism maintain separate logs for each partition of each topic partitions of the same topic can be spread across many brokers why each topic will be replicated to multiple partitions

4.1.2. Untitled

4.2. API name and usage

4.2.1. publish data onto a topic $publish topic data

4.2.2. consume from a topic $consume topic offset

4.3. brokers

4.3.1. def physical processes that make up a Kafka cluster each broker corresponds to a separate physical server

4.4. producers

4.4.1. in charge of sending messages to kafka broker

4.5. consumers

4.5.1. consumer pull messages from Kafka broker

4.5.2. can use offset to target a specific message on a partition by default point to the latest offset can set the offset to an older to read old data

4.5.3. consumer maintain message state

4.5.4. No ACK

4.6. consumer groups

4.6.1. one or more consumers each consumer reads one or more partitions of a topic

4.6.2. why used for load balancing higher throughput than a consumer could handle used for high availability if one consumer fails, partitions it is reading will be assigned to other consumers in the group

4.6.3. each message will be delivered to only one consumer within a group

5. architecture

5.1. stores all messages for a preconfigured length of time

5.2. pull vs push

5.2.1. push model high throughput complex server logic

5.2.2. pull model reply feature simple server logic

5.2.3. used pull model storing all messages for a period of time and not tracking acknowledgements for individual consumers and messages scale to more than 10,000 consumers support consumers that read data in batches

5.3. log file format

5.3.1. vs rabbitmq/activemq push model

5.3.2. one partition is a physical folder

5.3.3. one message offset message length magic value, 1 byte CRC value, 4 bytes payload, n bytes

5.3.4. overview Untitled active segment list maintains mapping to segment files log entries in segment files

5.4. IO optimization

5.4.1. Append-only writing reads do not block writes super fast writing speed because one partition is one log file

5.4.2. zerocopy original Untitled OS reads data from disk into page cache in kernel space application reads data from kernel space into user space application writes data back o kernel space into socket buffer os copies data from socket buffer to NIC buffer improved Untitled zerocopy copies data into page cache only once and reuse

5.5. data replication

5.5.1. handled at the topic level process producer write through partition leader partition leader write the message into local disk partition follower pull from partition leader once leader received configurable ACK from partitions, it is written structure each partition of a topic has a leader partition

5.5.2. ISR(in-sync Replica) replicas do not need to be completely consistent a nice balance between sync and async copy configurable lag behind if one replica is too slow, will be removed from ISR follower can batch read from leader Untitled

5.5.3. when writing data, producer can choose methods whether the write will be acknowledged by all synchronized replicas whether the write will be acknowledged by a specified number of replicas whether the write will be acknowledged by just the leader whether to wait for acknowledge at all criteria reliability a concern or not

5.5.4. when reading data consumer will only read committed messages messages that were written to all synchronized replicas

5.6. delivery mechanism

5.6.1. at least once if the consumer advances the offset after processing message if the consumer crash after processing the data but before advancing the last offset a new consumer will reread messages since the last offset

5.6.2. at most once if the consumer first advances the offset and then processes offset if the consumer crash after advancing the last offset but before processing the data a new consumer will read data from the new offset

5.6.3. exactly once if the consumer uses a two-phase commit to process data and advance the offset at the same time usually done in batch consumers and not in streaming because of overhead

6. Use cases

6.1. in place of a traditional message broker to decouple services

6.2. log aggregation

6.2.1. forward all the logs into specific kafka topic

6.2.2. setup consumer/consumer group on the topic and forward to indexing service

6.2.3. query on the data through kibana

6.3. real-time analysis

6.3.1. forward interested data into kafka topic

6.3.2. integrate with spark/samza for stream processing