Skip to content
Ameen Abozaid
MID-028

Apache Kafka

  • 9 Lessons
  • 4 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Brokers
  • topics
  • partitions
  • consumer groups
  • offsets
  • ordering

Learn first

4 h of practice (estimate)

Learning outcomes

  1. Explain brokers, topics, partitions, replicas, and the log model.
  2. Choose partition keys to preserve the ordering that matters.
  3. Explain consumer groups, offsets, commits, and rebalancing.
  4. Produce and consume with Spring for Apache Kafka, with error handling and a DLT.
  5. Configure producer durability (acks, idempotent producer).

Lessons

  1. 01Kafka as a distributed log
  2. 02Topics, partitions, replicas
  3. 03Keys and ordering
  4. 04Consumer groups and offsets
  5. 05Spring for Apache Kafka
  6. 06Error handling and dead-letter topics
  7. 07Producer durability settings
  8. 08Demo: order events end to end
  9. 09Demo: what a rebalance does to in-flight messages

Lab and exercises

Lab

MID-028-LAB1 · Order events on Kafka

Outcomes: 1–5 · Time: ~4 h

  1. Create orders (3 partitions). orders publishes OrderPlaced keyed by order ID with acks=all and idempotence enabled.
  2. inventory and payments consume in separate groups with a DefaultErrorHandler, back-off, and a DLT.
  3. Make handlers idempotent by eventId.
  4. Test: events of one order stay in order; restart a consumer mid-stream and confirm nothing is lost; send a poison record and find it in the DLT.

Acceptance: per-order ordering preserved; consumer restart loses nothing.

Exercises (assessment: partitioning and ordering scenarios; six exercises)

IDOutcomeTask
MID-028-EX011Draw a topic with 4 partitions and replication factor 3 over 3 brokers; mark leaders and followers.
MID-028-EX022Pick a key for: order events, per-customer notifications, sensor readings per device. Say what ordering you get.
MID-028-EX033A group has 3 consumers and a topic has 2 partitions. Describe the assignment and what happens when one consumer leaves.
MID-028-EX043Explain the failure when offsets are committed before processing and the failure when committed after.
MID-028-EX054Configure a Spring Kafka error handler that retries 3 times, 1 s apart, then publishes to a DLT.
MID-028-EX065Choose acks, min.insync.replicas, and idempotence for payment events and explain the trade-off.
Show solutions
  • EX01 Each partition has one leader and two followers on different brokers; leaders spread across brokers.
  • EX02 Order events: orderId (per-order order). Notifications: customerId. Sensors: deviceId. No ordering across keys.
  • EX03 Two consumers get one partition each; one idles. If an active one leaves, rebalance gives its partition to the idle one.
  • EX04 Commit before: crash loses the record. Commit after: crash causes redelivery, so handlers must be idempotent.
  • EX05 new DefaultErrorHandler(new DeadLetterPublishingRecoverer(template), new FixedBackOff(1000L, 3)).
  • EX06 acks=all, replication factor 3, min.insync.replicas=2, enable.idempotence=true; cost is extra latency and reduced availability if two replicas are down.

Quiz

Outcomes: O1 log model · O2 keys and ordering · O3 groups and offsets · O4 Spring and error handling · O5 producer durability.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1In Kafka, a consumed record is:O1
  2. 2Ordering is guaranteed:O1
  3. 3To keep all events of an order in order, key by:O2
  4. 4A null key means:O2
  5. 5Two groups subscribe to one topic. Each group gets:O3
  6. 6Within one group, a partition is read by:O3
  7. 7Committing offsets before processing risks:O3
  8. 8After retries are exhausted, a failed record is typically sent to:O4
  9. 9acks=all makes the leader wait for:O5
  10. 10The idempotent producer helps prevent:O5

Practical part

Six exercises MID-028-EX01 to EX06 plus the lab. Pass: at least five exercises correct, per-order ordering demonstrated, no loss on consumer restart, and a poison record found in the DLT.

Common mistakes

Random keys where order matters; auto-commit before processing; one partition for everything.

Assessment

Partitioning and ordering scenarios.

Career relevance

Large-scale messaging (SRB-006).

Type to search levels, phases, modules and lessons.