Apache Kafka® is a distributed streaming platform that. Kafka is run as a cluster on one or more servers that can span multiple datacenters. The Kafka cluster stores streams of records in categories called topics. Kafka is used for these broad classes of applications: Building real-time streaming data pipelines that reliably get data between systems or applications; Building real-time streaming applications that transform or react to the streams of data.
Apache Kafka® is a distributed streaming platform that:
Kafka is used for these broad classes of applications:
Kafka is run as a cluster on one or more servers that can span multiple datacenters. The Kafka cluster stores streams of records in categories called topics. Each record consists of a key, a value, and a timestamp.
Applications can publish a stream of records to one or more Kafka topics.
Applications can subscribe to topics and process the stream of records produced to them.
Applications can act as a stream processor, consuming an input stream from one or more topics and producing an output stream to one or more output topics, effectively transforming the input streams to output streams.
Build and run reusable producers or consumers that connect Kafka topics to existing applications or data systems. For example, a connector to a relational database might capture every change to a table.
In Kafka the communication between the clients and the servers is done with a simple, high-performance, language agnostic TCP protocol. This protocol is versioned and maintains backwards compatibility with older version. The Java client is provided for Kafka, but clients are available in many languages.
The core abstraction Kafka provides for a stream of records is the topic.
A topic is a category or feed name to which records are published. Topics in Kafka are always multi-subscriber. This means that a topic can have zero, one, or many consumers that subscribe to the data written to it.
For each topic, the Kafka cluster maintains a partitioned log that looks like this:
Each partition is an ordered, immutable sequence of records that is continually appended to a structured commit log. The records in the partitions are each assigned a sequential ID number called the offset, that uniquely identifies each record within the partition.
The Kafka cluster durably persists all published records, whether they have been consumed using a configurable retention period or not. For example, if the retention policy is set to two days, then for the two days after a record is published, it is available for consumption, and then after the two days have passed it is discarded to free up space. Kafka’s performance is effectively constant with respect to data size, which means storing data for a long time is not a problem.
The only metadata retained on a per-consumer basis is the offset or position of that consumer in the log. This offset is controlled by the consumer. Normally a consumer will advance its offset linearly as it reads records, however, because the position is controlled by the consumer it can consume records in any order. For example, a consumer can reset to an older offset to reprocess data from the past or skip ahead to the most recent record and start consuming from “now”.
This combination of features means that Kafka consumers can come and go without much impact on the cluster or on other consumers. For example, you can use the command line tools to “tail” the contents of any topic without changing what is consumed by existing consumers.
The partitions in the log allow it to scale beyond a size that will fit on a single server. Each individual partition must fit on the servers that host it, but a topic can have many partitions so it can handle an arbitrary amount of data. Partitions can also act as the unit of parallelism.
The partitions of the log are distributed over the servers in the Kafka cluster with each server handling data and requests for a share of the partitions. Each partition is replicated across a configurable number of servers for fault tolerance.
Each partition has one server that acts as the “leader” and zero or more servers which act as “followers”. The leader handles all read and write requests for the partition while the followers passively replicate the leader. If the leader fails, one of the followers will automatically become the new leader. Each server acts as a leader for some of its partitions and a follower for others so that load is successfully balanced within the cluster.
Confluent Replicator and Kafka MirrorMaker provide geo-replication support for your clusters. You can replicate messages across multiple datacenters or cloud regions. You can use this in active/passive scenarios for backup and recovery; or in active/active scenarios to place data closer to your users, or support data locality requirements. For more information, see Multi-DC Deployment Architectures.
Producers publish data to the topics of their choice. The producer is responsible for choosing which record to assign to which partition within the topic. This can be done in a round-robin fashion for load balancing or it can be done according to some semantic partition function (e.g., based on some key in the record).
For more information, see Kafka Producer.
Consumers label themselves with a consumer group name, and each record published to a topic is delivered to one consumer instance within each subscribing consumer group. Consumer instances can be in separate processes or on separate machines.
If all the consumer instances have the same consumer group, then the records will effectively be load balanced over the consumer instances.
If all the consumer instances have different consumer groups, then each record will be broadcast to all the consumer processes.
A two-server Kafka cluster hosting four partitions (P0-P3) with two consumer groups. Consumer group A has two consumer instances and group B has four.
Generally topics have a small number of consumer groups, one for each “logical subscriber”. Each group is composed of many consumer instances for scalability and fault tolerance. In this publish-subscribe scenario, the subscriber is a cluster of consumers instead of a single process.
The way consumption is implemented in Kafka is by dividing up the partitions in the log over the consumer instances so that each instance is the exclusive consumer of a “fair share” of partitions at any point in time. This process of maintaining membership in the group is handled dynamically by the Kafka protocol. If new instances join the group they will take over some partitions from other members of the group. If an instance dies, its partitions will be distributed to the remaining instances.
Kafka only provides a total order over records within a partition, not between different partitions in a topic. Per-partition ordering combined with the ability to partition data by key is sufficient for most applications. However, if you require a total order over records this can be achieved with a topic that has only one partition, though this will mean only one consumer process per consumer group.
For more information, see Kafka Consumer.
You can deploy Kafka as a multi-tenant solution. Multi-tenancy is enabled by configuring which topics can produce or consume data. There is also operations support for quotas. Administrators can define and enforce quotas on requests to control the broker resources that are used by clients. For more information, see Security.
At a high-level Kafka gives the following guarantees:
Messaging is traditionally based on these models:
In a queue, a pool of consumers may read from a server and each record goes to one of them.
The record is broadcast to all consumers.
The strength of queuing is that it allows you to divide up the processing of data over multiple consumer instances. This lets you scale your processing. Unfortunately, queues aren’t multi-subscriber. After one process reads the data, it’s gone. Publish-subscribe allows you to broadcast data to multiple processes, but has no way of scaling processing because every message goes to every subscriber.
The consumer group concept in Kafka generalizes these two concepts. As with the queue, the consumer group allows you to divide up processing over a collection of processes (the members of the consumer group). As with publish-subscribe, Kafka allows you to broadcast messages to multiple consumer groups.
The advantage of Kafka’s model is that every topic can scale processing and every topic is multi-subscriber. Kafka also has stronger ordering guarantees than a traditional messaging system.
A traditional queue retains ordered records on the server, and if multiple consumers consume from the queue then the server distributes records in the order they are stored. However, the records are delivered asynchronously to consumers, so they may arrive out of order on different consumers. This means the ordering of the records is lost in the presence of parallel consumption. Messaging systems often get around this with the notion of “exclusive consumer” that allows only one process to consume from a queue. However, this means that there is no parallelism in processing.
With partitions, Kafka has the notion of parallelism within the topics. Kafka provides ordering guarantees and load balancing over a pool of consumer processes. This is achieved by assigning the partitions in the topic to the consumers in the consumer group. This means that each partition is consumed by exactly one consumer in the group. This ensures that the consumer is the only reader of that partition and consumes the data in order. Because there are many partitions, the load is still balanced over many consumer instances.
You cannot have more consumer instances in a consumer group than partitions.
Any message queue that publishes messages decoupled from consumption of them is acting as a storage system for the in-flight messages. Kafka is a very good storage system.
Data written to Kafka is written to disk and replicated for fault-tolerance. Kafka allows producers to wait on acknowledgement. A write isn’t considered complete until it is fully replicated and guaranteed to persist even if the server written to fails.
The disk structures Kafka uses are able to scale well. Kafka performs the same whether you have 50 KB or 50 TB of persistent data on the server.
Kafka allows the clients to control their read position and can be thought of as a special purpose distributed filesystem, dedicated to high-performance, low-latency commit log storage, replication, and propagation.
For details about Kafka’s commit log storage and replication design, see Design Details.
In Kafka a stream processor is anything that takes continual streams of data from input topics, performs some processing on this input, and produces continual streams of data to output topics. For example, a retail application might take in input streams of sales and shipments, and output a stream of reorders and price adjustments computed off this data.
You can do simple processing directly using the producer and consumer APIs. However for more complex transformations, Kafka provides a fully integrated Streams API. You can build applications with the Streams API that do non-trivial processing tasks that compute aggregations off of streams or join streams together.
Streams help solve problems such as: handling out-of-order data, reprocessing input as code changes, performing stateful computations, etc.
The streams API builds on the core Kafka primitives, specifically it uses:
This combination of messaging, storage, and stream processing is essential to Kafka’s role as a streaming platform.
A distributed file system, like HDFS, allows static files storage for batch processing. These types of systems allow storing and processing of historical data from the past.
A traditional enterprise messaging system allows processing future messages that will arrive after you subscribe. Applications built in this way process future data as it arrives.
Kafka combines the capabilities of a distributed file system and traditional enterprise messaging system, to deliver a platform for streaming applications and data pipelines.
By combining storage and low-latency subscriptions, streaming applications can handle both past and future data the same way. A single application can process historical, stored data and continue processing as future data arrives. This is a generalized notion of stream processing that subsumes batch processing and message-driven applications.
For streaming data pipelines, the combination of subscription to real-time events make it possible to use Kafka for very low-latency pipelines. Kafka’s ability to store data reliably means it can be used for critical data, where data delivery must be guaranteed; or for integration with offline systems that load data only periodically or may go down for extended periods of time for maintenance. The stream processing facilities make it possible to transform data as it arrives.
Originally published at https://docs.confluent.io
‘Data is the new science. Big Data holds the key answers’ - Pat Gelsinger The biggest advantage that the enhancement of modern technology has brought
We need no rocket science in understanding that every business, irrespective of their size in the modern-day business world, needs data insights for its expansion. Big data analytics is essential when it comes to understanding the needs and wants of a significant section of the audience.
Corona Virus Pandemic has brought the world to a standstill. Countries are on a major lockdown. Schools, colleges, theatres, gym, clubs, and all other public
In this article, see the role of big data in healthcare and look at the new healthcare dynamics. Big Data is creating a revolution in healthcare, providing better outcomes while eliminating fraud and abuse, which contributes to a large percentage of healthcare costs.
Big Data Analytics is the next big thing in business, and it is a reality that is slowly dawning amongst companies. With this article, we have tried to show you the importance of Big Data in business and urge you to take advantage of this immense...