Skip to main content
Albero Academy

Apache Kafka: Building Real-Time Data Streaming Pipelines

A beginner-friendly guide to Apache Kafka — covering core concepts like topics, partitions, producers, consumers, and how to build your first real-time streaming pipeline.

Albero Academy TeamAlbero curriculum
1 May 20269 min read
Apache Kafka: Building Real-Time Data Streaming Pipelines

Apache Kafka is the backbone of modern real-time data systems. Uber, Netflix, LinkedIn, Razorpay — all run massive Kafka clusters to move billions of events per day. In this post we'll cut through the jargon and build a working producer-consumer pair in under 30 lines of Python.

Why Kafka?

Before Kafka, moving events between systems meant point-to-point integrations. Service A calls service B which calls service C. One outage and the whole graph collapses. Kafka inverts the model: services publish events to topics, and any number of services can subscribe. The producer doesn't care who's listening, and the consumer doesn't care who wrote the event.

Core concepts in 60 seconds

  • Topic. A named stream of events. e.g. orders.placed, user.signups.
  • Partition. A topic is split into partitions for parallelism. Each partition is an ordered, append-only log.
  • Producer. An app that writes events to a topic.
  • Consumer. An app that reads events from a topic. Multiple consumers can read the same topic independently.
  • Offset. A consumer's bookmark inside a partition. Kafka doesn't push — consumers pull at their own pace.

Your first producer

Install kafka-python and connect to a local broker:

producer.py
from kafka import KafkaProducer
import json
producer = KafkaProducer(
bootstrap_servers="localhost:9092",
value_serializer=lambda v: json.dumps(v).encode("utf-8")
)
order = {
"order_id": 7842,
"user_id": 412,
"amount": 1499.00,
"currency": "INR"
}
producer.send("orders.placed", value=order)
producer.flush()
print("Order published!")

Your first consumer

Now read those events from another script:

consumer.py
from kafka import KafkaConsumer
import json
consumer = KafkaConsumer(
"orders.placed",
bootstrap_servers="localhost:9092",
auto_offset_reset="earliest",
group_id="order-fulfilment",
value_deserializer=lambda b: json.loads(b.decode("utf-8"))
)
for msg in consumer:
order = msg.value
print(f"Processing order #{order['order_id']} for ₹{order['amount']}")
# ship to fulfilment, send WhatsApp, write to warehouse, etc.

Key takeaways

  1. 01Kafka decouples producers from consumers via topics — the central nervous system of event-driven systems.
  2. 02Topics are split into partitions for parallelism; each partition is an ordered append-only log.
  3. 03Consumers track their own offsets — they pull at their own pace, replays are free.
  4. 04Group consumers with the same group_id share work; different group_ids each get the full stream.
  5. 05You can build a working producer-consumer pair in 30 lines of Python — start there before reaching for Kafka Streams.