Introduction
Imagine youβre building a food delivery app like Talabat or Zomato. When a customer places an order, they want instant updates:
- β Order confirmed
- π¨βπ³ Food is being prepared
- π΅ Delivery on the way
- π¦ Delivered
How do you make this real-time experience possible?
The answer: event streaming, and one of the best tools for that is Redpanda β a fast, Kafka-compatible streaming platform with no Java dependencies and a simpler developer experience.
In this tutorial, weβll build a real-time order tracking system using Redpanda.
πͺ° What Youβll Need
- Docker installed
- Python 3.8+ installed
kafka-python
orconfluent-kafka
(pip install kafka-python
)- Basic Python knowledge
π οΈ Step 1: Run Redpanda Locally (via Docker)
Letβs spin up Redpanda with a single command:
docker run -d --pull=always --name=redpanda \
-p 9092:9092 -p 9644:9644 \
docker.redpanda.com/redpandadata/redpanda:latest \
redpanda start --overprovisioned --smp 1 --memory 1G --reserve-memory 0M \
--node-id 0 --check=false --kafka-addr PLAINTEXT://0.0.0.0:9092
π Ports:
9092
= Kafka API (for producers/consumers)9644
= Redpanda Admin API
π Step 2: Define the Use Case
Letβs simulate this real-life order journey:
Step | Status Event |
---|---|
1 | Order Placed |
2 | Preparing Food |
3 | Out for Delivery |
4 | Delivered |
Each event will be sent as a message to Redpanda, and the frontend can subscribe in real-time.
π¨ Step 3: Create a Topic for Orders
Use Python to create a topic called order-status
:
from kafka.admin import KafkaAdminClient, NewTopic
admin = KafkaAdminClient(bootstrap_servers="localhost:9092")
topic = NewTopic(name="order-status", num_partitions=1, replication_factor=1)
admin.create_topics([topic])
π¨βπ³ Step 4: Simulate Order Status Updates (Producer)
from kafka import KafkaProducer
import json, time
producer = KafkaProducer(
bootstrap_servers='localhost:9092',
value_serializer=lambda v: json.dumps(v).encode('utf-8')
)
order_id = "ORDER123"
status_updates = [
{"order_id": order_id, "status": "Order Placed"},
{"order_id": order_id, "status": "Preparing Food"},
{"order_id": order_id, "status": "Out for Delivery"},
{"order_id": order_id, "status": "Delivered"}
]
for update in status_updates:
producer.send('order-status', update)
print(f"Sent update: {update}")
time.sleep(2) # simulate delay
producer.flush()
π¬ Step 5: Real-Time Order Tracker (Consumer)
from kafka import KafkaConsumer
import json
consumer = KafkaConsumer(
'order-status',
bootstrap_servers='localhost:9092',
auto_offset_reset='earliest',
group_id='tracker-service',
value_deserializer=lambda v: json.loads(v.decode('utf-8'))
)
print("Listening for order updates...\n")
for message in consumer:
update = message.value
print(f"Order {update['order_id']} - Status: {update['status']}")
π₯οΈ What This Looks Like in Real Life
π¨βπ» Backend (Producer):
Keeps sending order updates to Redpanda.
π± Frontend (Consumer):
Subscribes to updates and instantly shows users when the rider is nearby.
You can plug the consumer into a WebSocket or REST API to stream updates to a frontend or mobile app.
π Why Redpanda?
- β‘ Blazing-fast performance
- π§Ή Kafka-compatible (reuse existing tools)
- π©Ά No JVM needed β lightweight and easy to run
- π οΈ Built-in CLI and monitoring tools
β Next Steps
- Add multiple topics (e.g.
order-payments
,user-feedback
) - Connect Redpanda to a frontend via WebSockets
- Deploy Redpanda on Kubernetes or Redpanda Cloud
- Monitor your streams with Redpanda Console
π¬ Final Thoughts
Redpanda makes it easier than ever to build real-time systems. Whether you’re handling food orders, stock prices, or IoT sensors β streaming is the future, and Redpanda helps you get there faster.
π Stay Connected
Want help setting up Redpanda for your own use case? Reach out or comment below!