Why this matters
- When the inventory service, notification service, and analytics pipeline all need to know about a new order, point-to-point HTTP calls create a fragile web of dependencies.
- Kafka persists messages to a log — consumers can restart, replay from an offset, and scale independently by adding members to a consumer group.
- Spring for Apache Kafka wraps the raw client with
KafkaTemplateand@KafkaListener, handling serialization and error hooks with minimal boilerplate.
KafkaTemplate
L1 · FresherSend messages to topics with keys for partitioning — BookStore order events keyed by orderId keep ordering per order.
@KafkaListener
L2 · IntermediateConsumers declare topics and group IDs; offset commits define at-least-once vs effectively-once with idempotent handlers.
Error handling
L3 · AdvancedDead-letter topics and DefaultErrorHandler prevent poison messages from stalling the whole consumer group.
Serialization
L4 · ExpertUse Schema Registry or JSON contracts with compatibility rules — never change event schemas without versioned subjects.
Spring Kafka essentials
KafkaTemplate<K, V>— the producer API; send synchronously, asynchronously, or with callbacks.@KafkaListener— declares a method that consumes from one or more topics.- Consumer groups — partition assignment and offset tracking; each message is delivered to one member per group.
- Serializers — convert Java objects to bytes; JSON with Jackson is common for BookStore DTOs.
- Dead-letter topic (DLT) — routes poison messages after retries exhaust, so one bad payload does not block the partition.
Dependencies and configuration
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 2 sections
- Publishing order events
- Consuming with error handling
Test yourself
Answer these before moving on — recall is what makes it stick.