Azure Service Bus vs Event Hubs — Messaging Choice for Java
Fast recall
Quick revision
Core answer
Understanding of messaging semantics — queues vs. streams, delivery guarantees, and when each model fits.
Choosing Event Hubs for all messaging because it sounds more modern, missing that it lacks dead-letter queues and per-message TTL.
Mention Event Hubs Kafka surface — you can point a Kafka producer/consumer at Event Hubs without code changes.
Interview-ready guide
Interview answer
Azure Service Bus and Event Hub both move messages between services, but they serve fundamentally different consumption models — Service Bus is a message broker for transactional workloads; Event Hub is an event stream for high-throughput ingestion.
Service Bus — transactional message broker
- Service Bus delivers a message to exactly one consumer from a queue — when the consumer reads a message and calls
complete(), it's removed; if the consumer fails and callsabandon()or the lock expires, it becomes visible again for reprocessing - Topics and subscriptions extend this with fan-out: one message published to a topic can be delivered to multiple subscriptions, each with its own filter and dead-letter queue
- Service Bus supports message sessions (ordered processing per entity), deferred messages, scheduled delivery, and dead-letter queues for unprocessable messages — which makes it the right choice for order processing, payment workflows, and any use case where each message must be processed exactly once with retry
Event Hub — high-throughput event stream
- Event Hub stores events in partitioned ordered logs — multiple consumer groups can independently read the same stream from different offsets, which means one stream of telemetry events can be consumed independently by a metrics aggregator, a real-time dashboard, and a cold storage archiver
- Events are retained for a configurable period (1-7 days by default, up to 90 days with Event Hub Premium) — which means consumers can replay events without the producer knowing or caring
- Event Hub supports Kafka protocol — existing Kafka producers and consumers can connect to Event Hub with only a connection string change, which makes it a managed Kafka alternative on Azure
Spring integration
- Spring Cloud Azure provides
spring-cloud-azure-starter-servicebuswithServiceBusSenderClientand listener annotations;spring-cloud-azure-starter-eventhubswraps Event Hub with reactive and batch consumers
Azure Service Bus vs Event Hubs — Messaging Choice for Java
Direct Answer
Use Service Bus for enterprise messaging patterns (queues, topics, dead-letter, sessions, at-most-once/at-least-once delivery). Use Event Hubs for high-throughput event streaming where you need replay and consumer groups — analogous to Kafka.
Common Mistakes & Pitfalls
Choosing Event Hubs for all messaging because it sounds more modern, missing that it lacks dead-letter queues and per-message TTL.
Check your understanding
Answer these without looking back at the article.
- How do you configure a dead-letter queue handler in Spring Boot with Service Bus?
- What is the Event Hubs Kafka-compatible endpoint and when is it useful?
- How does Service Bus duplicate detection work?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.