Apache Kafka for Beginners – What It Is and How to Use It

July 1, 2025 (2w ago)

Kafka Explained Simply

🔄 Apache Kafka — A Beginner’s Guide to Moving Data in Real Time

Have you ever wondered how companies like Netflix, Uber, or LinkedIn move data quickly between different parts of their systems?

How do they:

They use something called Apache Kafka.

And no, it’s not complicated — at least not when explained simply 😄


🌟 What Is Kafka?

Imagine you run a pizza delivery app.

All these steps need to talk to each other — and quickly.

That’s what Kafka helps with. It’s like a super-fast messenger that lets different parts of your system send and receive messages.

In short: Kafka = A real-time message delivery system for apps.


📦 How Does Kafka Work?

Let’s use a very simple idea:

It’s just like a WhatsApp group:


🛠️ Basic Kafka Example (with Code)

Let’s try a simple example using Node.js and the kafkajs library.

1. Install Kafka and kafkajs:

npm install kafkajs

You’ll also need Kafka running locally. The easiest way is Docker (ask me if you need that setup).


2. Producer Code – Sending a message

// producer.js
const { Kafka } = require('kafkajs');
 
const kafka = new Kafka({ clientId: 'pizza-app', brokers: ['localhost:9092'] });
const producer = kafka.producer();
 
async function runProducer() {
  await producer.connect();
  await producer.send({
    topic: 'pizza-orders',
    messages: [{ value: 'Order #42 - Pepperoni Pizza' }],
  });
  console.log("🍕 Order sent!");
  await producer.disconnect();
}
 
runProducer();

3. Consumer Code – Receiving the message

// consumer.js
const { Kafka } = require('kafkajs');
 
const kafka = new Kafka({ clientId: 'kitchen', brokers: ['localhost:9092'] });
const consumer = kafka.consumer({ groupId: 'kitchen-group' });
 
async function runConsumer() {
  await consumer.connect();
  await consumer.subscribe({ topic: 'pizza-orders', fromBeginning: true });
 
  await consumer.run({
    eachMessage: async ({ message }) => {
      console.log(`👨‍🍳 New order received: ${message.value.toString()}`);
    },
  });
}
 
runConsumer();

📈 Real-Life Use Cases

Kafka is used by tons of companies for:


💡 Why Use Kafka?

Need Why Kafka Helps
I want to move data fast Kafka is super quick
I want to connect multiple apps Kafka acts like a bridge
I want to store and process messages later Kafka stores messages for days
I want to stream data in real time That’s exactly what Kafka does

🤝 Kafka in Simple Words

Term Think of it as...
Producer The sender (e.g., order system)
Consumer The receiver (e.g., kitchen)
Topic The group/chat/channel
Broker The Kafka server
Message The data (e.g., order info)

🚀 Final Thoughts

Kafka may sound like a big, scary thing — but at its core, it’s just a fast and reliable way to send data between parts of your app.

Once you understand the basics, you can do amazing things with it.