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:
from kafka import KafkaProducerimport jsonproducer = 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:
from kafka import KafkaConsumerimport jsonconsumer = 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.valueprint(f"Processing order #{order['order_id']} for ₹{order['amount']}")# ship to fulfilment, send WhatsApp, write to warehouse, etc.
Key takeaways
- 01Kafka decouples producers from consumers via topics — the central nervous system of event-driven systems.
- 02Topics are split into partitions for parallelism; each partition is an ordered append-only log.
- 03Consumers track their own offsets — they pull at their own pace, replays are free.
- 04Group consumers with the same group_id share work; different group_ids each get the full stream.
- 05You can build a working producer-consumer pair in 30 lines of Python — start there before reaching for Kafka Streams.


