DT4: Streams, big data and file formats

Lesson 2 of 5 · reading 15–25 minutes; practice and project time is on the module page

Events and Kafka

🎯You'll be able to

Explain events, topics, partitions, offsets and consumer groups, and why event keys decide ordering.

🏠The everyday picture

A railway announcement board logs every train event in order: arrived, departed, delayed. Different people read it at their own pace, and each remembers where they stopped reading.

📘What it really is

📝A worked example

Input: SabziSathi publishes order_status_changed events with the order id as the key, to a topic with 6 partitions. A consumer group of 3 workers updates a live order table.

Expected output (illustrative, not run in the kit): each worker reads 2 partitions. All of order SS-100562's status changes (placed → packed → delivered) arrive at the same worker in order. If a worker stops, its 2 partitions move to the other workers, which carry on from the saved offsets. Some events may be processed twice, so the table is updated by order id, not appended.

🌍Where it's used

📝Case scenario

A delivery app used the rider's id as the key for order events. When one order changed riders, its events went to two partitions and arrived out of order: "delivered" was processed before "picked up". Keying by order id kept each order's events in order.

🖱️Try it

For each event, choose a key that keeps the right events in order: payment_captured, stock_level_changed, customer_address_updated. Success: payment id or order id, product and store together, and customer id, each with a reason.

⚠️Common mistakes

🛠️For your project

Not in the kit's tests. The capstone's design notes ask which events SabziSathi would stream first, and with which key.

✅Quick check

Where does Kafka keep events in order?

Show the answer

Within a partition, so events with the same key stay in order.

What does a consumer group's offset do?

Show the answer

It records how far each member has read, so a restart carries on from there.

← PreviousBatch or stream?
ProLearners Assist