Skip to content

gauraang01/kafka-practice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apache Kafka Fundamentals

This document covers the fundamentals of Kafka, including producers, consumers, consumer groups, and common configuration properties, with both theoretical explanations and coding examples.


🔹 What is Apache Kafka?

Apache Kafka is a distributed streaming platform used for building real-time data pipelines and streaming applications.
It provides:

  • Publish/Subscribe messaging.
  • Durability & Scalability through topic partitions.
  • Fault Tolerance via replication.
  • Stream Processing with Kafka Streams or external frameworks.

🔹 Key Kafka Concepts

Topics

  • A logical channel where records are published.
  • Split into partitions for parallelism and scalability.
  • Each partition is an ordered, immutable log of records.

Producers

  • Applications that publish (write) data to Kafka topics.
  • Can control durability, ordering, and delivery guarantees via configs.

Consumers

  • Applications that subscribe (read) data from Kafka topics.
  • Can be part of a consumer group for parallel consumption.

Consumer Groups

  • A set of consumers that share the work of reading from topic partitions.
  • Each partition is consumed by only one consumer in the group at a time.
  • Provides scalability and fault tolerance.

🔹 Common Kafka Properties

Producer Properties

Property Description Example
bootstrap.servers List of Kafka brokers localhost:9092
key.serializer Serializer class for keys StringSerializer
value.serializer Serializer class for values StringSerializer
acks Level of acknowledgment all (leader + ISR must ack)
retries Number of retries if request fails 3
linger.ms Delay before sending batch 5
batch.size Batch size in bytes 16384

🔑 Example: ACKS_CONFIG

props.put(ProducerConfig.ACKS_CONFIG, "all");
// "all" means leader + all in-sync replicas must acknowledge
// Provides strongest durability guarantees

Consumer Groups in Action

  • Suppose a topic has 4 partitions.
  • Group A with 2 consumers → each consumer will consume from 2 partitions.
  • Group B with 4 consumers → each consumer will consume from 1 partition.
  • If a consumer dies, Kafka will rebalance partitions among the remaining consumers.

CLI Commands

  • Produce Messages kafka-console-producer.sh --broker-list localhost:9092 --topic test-topic

  • Consume Messages kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-topic --from-beginning

  • List Topics kafka-topics.sh --list --bootstrap-server localhost:9092

  • Describe Topic kafka-topics.sh --describe --topic test-topic --bootstrap-server localhost:9092

About

Repository to have kafka practice projects on producer, consumer APIs. Kakfa connect, Kafka streams, Kafka schema registry

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors