Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 58

    Kafka Messaging

    Apache Kafka is the durable, partitioned log behind every event-driven enterprise.

    Course progress0%
    Focus
    3 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    Apache Kafka is the durable, partitioned log behind every event-driven enterprise. Producers append to topics; consumers read at their own pace; Kafka stores it all for days.

    Informative example

    ts
    # application.yml
    spring:
    kafka:
    bootstrap-servers: kafka:9092
    consumer:
    group-id: orders-svc
    auto-offset-reset: earliest
    @Service @RequiredArgsConstructor
    public class OrderEvents {
    private final KafkaTemplate<String, OrderPlaced> kafka;
    public void publish(OrderPlaced e) {
    kafka.send("order.placed", String.valueOf(e.orderId()), e);
    }
    }
    @KafkaListener(topics = "order.placed", groupId = "billing-svc")
    public void onOrderPlaced(OrderPlaced e) {
    billing.charge(e);
    }

    Best practices

    • Pick a stable partition key (userId / orderId) — ordering hangs on it.
    • Make consumers idempotent; at-least-once delivery means duplicates happen.
    • Schema with Avro/Protobuf in a registry — never JSON without schemas.
    Ready to mark this lesson complete?Track your journey across the entire course.