<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Adwait Sathe on Medium]]></title>
        <description><![CDATA[Stories by Adwait Sathe on Medium]]></description>
        <link>https://medium.com/@adwaitsathe?source=rss-a6f22ee92daa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*0Td9VfuvMUUB9Vb9kaSqzw.png</url>
            <title>Stories by Adwait Sathe on Medium</title>
            <link>https://medium.com/@adwaitsathe?source=rss-a6f22ee92daa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:03:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adwaitsathe/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Getting Started With Apache Kafka]]></title>
            <link>https://medium.com/rock-your-data/getting-started-with-apache-kafka-efc616bd6dd5?source=rss-a6f22ee92daa------2</link>
            <guid isPermaLink="false">https://medium.com/p/efc616bd6dd5</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[analytics-architecture]]></category>
            <dc:creator><![CDATA[Adwait Sathe]]></dc:creator>
            <pubDate>Sat, 28 Dec 2019 18:42:56 GMT</pubDate>
            <atom:updated>2019-12-28T18:42:56.862Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*Whb-35gZ_pPg98mugZxevw.png" /></figure><h4>Modern Data Architecture with AWS</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*qazULjVzqqasypYYcJ7UdA.jpeg" /></figure><h4>Introduction</h4><p>In today’s world of increasing connectivity, technology is evolving in every field a human can think of. With technological advancement, the amount of data getting generated is enormous. There is some extremely huge growth in digital data that enterprises created. With the increase of data, the need to analyze data to draw insights from it also increased. Within an enterprise,<br>there is a multiple-source system that generates the data and this data is used by multiple systems across an enterprise. For example, the data generating from sensors could be used by multiple teams. If we have to leverage queues, there would be multiple queues and data would be duplicated. Also, the complexity would increase as the source system increases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*kkzHpnvsrFhcRali5UzuWw.jpeg" /></figure><p>So there is also a greater challenge to maintain that infrastructure and ensure the resiliency of the system and reliability and consistency of the data. The Solution that came out to help with the situation and simplify the architecture is termed “Kafka”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*rrn3gCnhnOF1LtW6IrfYjA.jpeg" /></figure><p>Kafka is a Distributed Streaming Publish-Subscribe messaging platform capable of handling millions of messages per minute.</p><ul><li>Apache Kafka was originally developed by LinkedIn, and was subsequently open-sourced in early 2011.</li><li>Netflix uses Kafka to apply recommendation in real-time while you are watching TV shows, Uber uses Kafka to gather taxi, user and trip data in real-time to compute and forecast demand and compute surge pricing in real-time, British Gas’ smart home uses for providing real-time analytics and predictive maintenance and LinkedIn uses to prevent scam and make better connection recommendation are some of the applications of Kafka.</li></ul><h4>Why we need Streaming?</h4><p>Streaming Data is data that is generated continuously by thousands of data sources, which typically send in the data records simultaneously. We use streaming data when data needs to be processed sequentially and incrementally on a record-by-record.</p><p>Examples:</p><p>1- Sensors in transportation vehicles, industrial equipment, and farm machinery send data to a streaming application.</p><p>2 -IoT data sent by connected vehicles and use that data to monitor the traffic on different routes.</p><h4><strong>USE CASES OF KAFKA</strong></h4><p><strong>Kafka Messaging</strong></p><p>Kafka is a distributed large-scale publish-subscribe message processing applications.</p><p><strong>Website Activity Tracking</strong></p><p>To be able to rebuild a user activity tracking pipeline as a set of real-time publish-subscribe feeds, it is the original Use Case for Kafka.</p><p><strong>Kafka Metrics</strong></p><p>For operational monitoring data, to produce centralized feeds of operational data, it includes aggregating statistics from distributed applications.</p><p><strong>Kafka Log Aggregation</strong></p><p>In order to collect logs from multiple services and make them available in a standard format to multiple consumers, we can use Kafka across an organization.</p><p><strong>Stream Processing</strong></p><p>Many users of Kafka process data in processing pipelines consisting of multiple stages, where raw input data is consumed from Kafka topics and then aggregated, enriched, or otherwise transformed into new topics for further consumption or follow-up processing.</p><p><strong>Commit Log</strong></p><p>While it comes to a distributed system, Kafka can serve as a kind of external commit-log for it. Generally, it replicates data between nodes. Also, acts as a re-syncing mechanism for failed nodes to restore their data. The feature of log compaction in Kafka helps to support this usage.</p><h4><strong>HIGH-LEVEL KAFKA DESIGN</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*lYsbKwGb9Ukia8s_WyJ19Q.jpeg" /></figure><h4><strong>Topics</strong></h4><ul><li>According to the Kafka documentation, A topic is a category or feed name to which records are published.</li><li>Topic is identified by its name.</li><li>If you have to send a message, you have to send it to a topic and if you have to read a message you have to read it from the topic.</li><li>Topics in Kafka are always multi-subscriber; that is, a topic can have zero, one, or many consumers that subscribe to the data written to it.</li><li>Application writing data to Kafka topics is called Producer and application reading data from topi is called Consumer.</li><li>Data in topics are kept for a specific time i.e TTL(Time to Live). One can configure the TTL according to need.</li><li>A topic is then divided into <strong>partitions</strong>, where each contains a subset of a topic’s messages.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*LaHnpVg-iumE_9Ra7I5M-g.png" /></figure><h4><strong>Partitions</strong></h4><ul><li>Topics are split into partitions. While creating a topic, one can specify the number of partitions in a topic.</li><li>Each partition is <strong>ordered</strong>.</li><li>Order is guaranteed only within a partition. (not across partitions)</li><li>Each record within a partition is assigned an incremental id called the <strong>offset.</strong></li><li>Offsets are identified with respect to partition, they do not mean anything on their own.</li><li>Once the data is written to a partition, it cannot be changed. i.e it is Immutable.</li><li>We have multiple partitions primarily to increase throughput; parallel access to the topic can occur.</li></ul><h4><strong>Brokers</strong></h4><ul><li>Kafka cluster is composed of multiple brokers. Broker is nothing but a server.</li><li>Every Broker is identified by an ID.(<em>broker.id</em>)</li><li>Once you connect to a broker, you get connected to whole Kafka cluster.</li><li>Brokers hold the topic and the partitions.</li><li>Below image has 2 Brokers, Topic 1 has 2 partitions and Topic 2 has one partition.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*BShzmZHzv4IXl_tgx9fY7g.png" /></figure><h4><strong>Replication Factor</strong></h4><ul><li>Kafka is a distributed system, so if a broker goes down we should still have the data. This is where replication comes into the picture.</li><li>Topic should have a replication factor &gt; 1. It is recommended to have 3 partitions. This is used only for Kafka to Kafka workflows.</li><li>Replication factor of 3 means, there would be 3 copies of data on 3 different servers.</li></ul><p><strong>Concept of Leader for a Partition.</strong></p><ul><li>Each partition will have a Leader and multiple ISR(in-sync replicas). ISR is the number of redundant copies apart the one that exist on the leader.</li><li>Only leader can receive and serve data for that partition.</li><li>If leader goes down, then one of ISR becomes the leader. When the leader comes back, the temporary leader goes back to ISR.</li></ul><p>Suppose We have 3 brokers, a Topic with 3 partition and replication factor of 3, all 3 partition would be on all 3 brokers. <strong>But only one broker can be a Leader for given partition.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*W2CzkLTmA47Wau20hIpwNA.png" /></figure><h4><strong>Producers</strong></h4><ul><li>Producer is an application which will write data to topics.</li><li>Producers knows which broker and partition to write to. If you send the messages without specifying key, the messages would be sent to brokers in round robin. This will ensure equal load on every broker i.e load balancing.</li><li>But if you send with messages with key, all the messages for that key will be stored in the same partition.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*uMsUYSGvcq2z2XS1IPUMQg.png" /></figure><ul><li>When the data is send to brokers, producer can be configured to receive confirmation of messages.</li></ul><p>ack=0 No acknowledgment, this has possible data loss.</p><p>ack=1 Only leader will send acknowledgment, it would have limited data loss.</p><p>ack=all All the ISR and leader will send acknowledgment, No data loss,slower speed of processing.</p><h4>Consumer<strong> Group and Consumers</strong></h4><ul><li>Consumer is an application which will read data from topic.</li><li>Consumer reads data from topic. Data is read in order within each partition.</li><li>Consumer groups have multiple consumers.</li><li>Within a consumer group, a consumer will read data from set of partitions. For any given partition, only one consumer will read from it.</li><li>If you have more consumers than partitions within a consumer group, some consumers would be inactive(in below diagram,Consumer 4 is incactive).</li><li>If you want to have high number of consumers, one should have high number of partitions. Therefore deciding on number of partitions is important.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*Wjya0ltnVjs3EIp0uMtLfQ.png" /></figure><h4><strong>Consumer Offset</strong></h4><ul><li>Kafka stores the offset of every consumer group which it has read.</li><li>As consumer group read data, the offset are committed live in a Kafka topic named _consumer_offsets.</li><li>When a consumer in a group has processed data received from Kafka, it should be committing the offset to above topic.(This is automatically done).</li><li>Consumer offset are important because if a consumer goes down, after its up it would know from which offset to read data.</li><li>Offsets can be committed in 3 ways as below</li></ul><p><em>At most once: </em>Offset are committed as soon as message is received. If processing goes wrong then message will be lost. (Not preferred way).</p><p>At least once: Offset are committed after message is processed. If processing goes wrong then message will be read again. (Preferred way).</p><p><em>Only once: </em>This is used only for Kafka to Kafka workflows.</p><h4>Zookeeper</h4><ul><li>Zookeeper manages all the brokers.</li><li>Zookeeper helps in leader election for partition i.e decides which partition would be the leader.</li><li>Zookeeper send notification to Kafka (when a broker goes down, it goes up, new topic created).</li><li>Zookeeper operates with only odd number of servers.</li><li>Zookeeper has a leader(which handles the write) and the rest of servers are followers(which handles read).</li></ul><h3>Setting up Kafka Cluster and Running :</h3><p>You need to have a Java Installed on your machine and you can download Kafka from <a href="https://kafka.apache.org/downloads">here</a>.</p><h4>Kafka Setup</h4><ul><li>Unzip the downloaded file.</li><li>Go to the Kafka folder . Under the Kafka folder create a directory data/zookeeper and data/kafka. (This will hold zookeepers and Kafka’s data).</li><li>Change the path of dataDir to /data/zookeeper folder in zookeeper.properties file which is in config directory. eg(dataDir=/home/adwait/Documents/kafka/data/zookeeper)</li><li>Changed the path of logs.dir to /data/kafka folder in server.properties file which is in config directory. eg(logs.dir=/home/adwait/Documents/kafka/data/kafka)</li></ul><p><em>Start the Zookeeper by the following command:</em></p><p>zookeeper-server-start.sh zookeeper.properties</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l3evS4O7MWEtY9El-bPjtw.png" /></figure><p>binding to port 0.0.0.0/0.0.0.0:2181 means the Zookeeper has started successfully.</p><p><em>Start the Kafka by the following command:</em></p><p>kafka-server-start.sh server.properties</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*rqXZACJe21qCtZyrhObQUA.png" /></figure><h4><em>Creating Topic and commands:</em></h4><p>Kafka topic is created by the following command.</p><p>kafka-topics.sh — create — zookeeper localhost:2181 — replication-factor 1 — partitions 1 — topic test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ASMLVQrHvdRS9FAy0-SkXQ.png" /></figure><p>Log folder after topic is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*cn_HE9EMDv-RaJKqsFX1xA.png" /></figure><p><em>Get all topics :</em></p><p>kafka-topics.sh — zookeeper 127.0.0.1:2181 — list</p><p>You can see by default<strong> __consumer_offsets</strong> topic is created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aIgEir7rTsJgnaSTaTSA3w.png" /></figure><p>Delete a topic:</p><p>kafka-topics.sh — zookeeper 127.0.0.1:2181 — topic test — delete</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sw4Oj4atQw6ZG9p7xS7iDg.png" /></figure><p><em>Describe partition in a Topic:</em></p><p>kafka-topics.sh — zookeeper 127.0.0.1:2181 — topic first_topic — describe</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VtwV6dPn2jM4EjiRwK0T-w.png" /></figure><p><em>What parameters you can pass to Kafka topic ?</em></p><p>Just type kafka-topics.sh and press enter you will get a list of parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*T_9Ir_yaVDkcmK0QCzhI0g.png" /></figure><h4>Creating Producer and Consumer</h4><p><em>Creating Producer</em></p><p>kafka-console-producer.sh — topic test — broker-list localhost:9092</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KCU99Tp_XoqRdSbRdPZx-w.png" /></figure><p><em>Creating Consumer and listening</em></p><p>kafka-console-consumer.sh — bootstrap-server 127.0.0.1:9092 — topic test — group test_group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LBW0Au3emylFMHj0QT7y5Q.png" /></figure><p>Reading from a topic from beginning.</p><p>If you read from beginning all the message in that topic will be listed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*sxTQbTU7cNuDXMJnNyh7vA.png" /></figure><h4><em>Consumer Group and Commands</em></h4><p><em>Get all Consumer in a consumer group</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*WN9kbC27HSJrZGTQblNuwQ.png" /></figure><p><em>Describe a consumer group</em></p><p>kafka-consumer-groups.sh — bootstrap-server 127.0.0:9092 — describe — group test_group1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tfbUGDu_jEAHmstfFL7jAg.png" /></figure><h4>CONCLUSION</h4><p>We have seen the architecture of Kafka and how Kafka producers and consumers work. You can find documentation of Kafka <a href="https://kafka.apache.org/documentation/">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efc616bd6dd5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/rock-your-data/getting-started-with-apache-kafka-efc616bd6dd5">Getting Started With Apache Kafka</a> was originally published in <a href="https://medium.com/rock-your-data">Rock Your Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>