How does Event Streaming with Kafka differ from a traditional message queue?

Topic: microservices, Messaging. Level: Intermediate.

Answer

Kafka is a distributed, append-only **commit log**, not just a queue. Key differences: - **Retention & replay**: messages are kept for a configured time/size, so consumers can re-read from any offset — a queue usually deletes on ack. - **Consumer groups**: multiple groups each get every message (pub/sub) while partitions are load-balanced within a group. - **Ordering**: guaranteed per partition (choose a partition key, e.g. `orderId`, to keep related events ordered). - **Throughput**: sequential disk writes + partitioning scale to millions of events/sec. Use Kafka for event sourcing, stream processing, and multiple independent consumers of the same event. ```java // Partition key keeps all events for one order in order kafkaTemplate.send("orders", order.getId(), new OrderPlaced(order)); @KafkaListener(topics = "orders", groupId = "billing") public void bill(OrderPlaced e) { /* billing group sees every event */ } @KafkaListener(topics = "orders", groupId = "analytics") public void track(OrderPlaced e) { /* analytics group also sees every event */ } ```