Skip to main content

📩 Azure Service Bus & Azure Event Hub (Interview Guide)

🟢 Azure Service Bus

✅ What is it?

  • A fully managed enterprise message broker.
  • Used for asynchronous communication between apps and services.
  • Ensures reliable delivery, ordering, and advanced messaging patterns.

👉 Think of it as a postal service → messages are sent, stored, and delivered reliably.

✅ Key Features

  • Queues → Point-to-point messaging (1 sender → 1 receiver).
  • Topics & Subscriptions → Publish/Subscribe model (1 sender → many receivers).
  • Sessions → Ordered message processing (FIFO).
  • Dead-letter Queue (DLQ) → Stores undeliverable messages.
  • Duplicate Detection → Avoid processing the same message twice.
  • Scheduled Delivery & Deferral → Send messages to be delivered later.

✅ Example Use Cases

  • Order processing systems.
  • Background job processing.
  • Microservices communication.

🟢 Azure Event Hub

✅ What is it?

  • A big data streaming platform and event ingestion service.
  • Designed to handle millions of events per second.
  • Best for real-time analytics, telemetry, IoT, and logs.

👉 Think of it as a highway where events flow continuously.

✅ Key Features

  • Partitions → divide stream for scalability.
  • Consumer Groups → multiple apps can independently read the same stream.
  • Throughput Units (TU) → defines capacity (events/sec).
  • Capture → automatically save data to Blob or Data Lake for batch processing.
  • Low latency ingestion → < 1 second.

✅ Example Use Cases

  • IoT telemetry ingestion.
  • Application logs & monitoring.
  • Real-time analytics (with Azure Stream Analytics, Spark, Databricks).

🟢 Service Bus vs. Event Hub (Comparison)

Feature Service Bus 📨 Event Hub 📊
Purpose Reliable messaging (integration) Event streaming (big data pipeline)
Pattern Message queue / Pub-Sub Append-only event stream
Message Size Up to 256 KB (Standard), 1 MB (Premium) Up to 1 MB per event
Ordering Supported (via Sessions) No strict ordering, partition-based
Retention Until consumed / TTL expiry Default 1–7 days (configurable)
Advanced Features DLQ, Sessions, Transactions Consumer groups, Auto Capture
Use Case Order processing, async workflows IoT, telemetry, log ingestion

👉 Interview Tip:

  • If asked “Which one for IoT telemetry?” → Event Hub.
  • If asked “Which one for business transactions (order queue)?” → Service Bus.

🟢 Example: Sending Message to Service Bus (C#)

using Azure.Messaging.ServiceBus;

string connStr = "<ServiceBusConnectionString>";
string queueName = "orders";

ServiceBusClient client = new ServiceBusClient(connStr);
ServiceBusSender sender = client.CreateSender(queueName);

ServiceBusMessage msg = new ServiceBusMessage("Order #123");
await sender.SendMessageAsync(msg);

Console.WriteLine("✅ Message sent to Service Bus queue!");

🟢 Example: Sending Event to Event Hub (C#)

using Azure.Messaging.EventHubs;
using Azure.Messaging.EventHubs.Producer;

string connStr = "<EventHubConnectionString>";
string eventHubName = "myeventhub";

await using var producer = new EventHubProducerClient(connStr, eventHubName);

// Create a batch
using EventDataBatch batch = await producer.CreateBatchAsync();
batch.TryAdd(new EventData("Event 1"));
batch.TryAdd(new EventData("Event 2"));

// Send batch
await producer.SendAsync(batch);
Console.WriteLine("✅ Events sent to Event Hub!");

🟢 Security

  • Shared Access Signature (SAS).
  • Azure AD / Managed Identity (preferred, no secrets in code).
  • Network Security → Private Endpoints, Firewall rules.

🟢 Common Interview Questions

Service Bus

  1. What is the difference between Queue and Topic?
  2. How do Dead-letter Queues work?
  3. What is FIFO processing? How does Service Bus support it?
  4. Difference between Service Bus and Storage Queue?
  5. Can Service Bus handle transactions?

Event Hub

  1. Difference between Service Bus and Event Hub?
  2. What are Consumer Groups in Event Hub?
  3. How do partitions work?
  4. What is Event Hub Capture?
  5. Typical use cases for Event Hub?

🟢 Pros & Cons

Service Bus

✅ Advanced features (DLQ, Sessions, Transactions).
✅ Guaranteed delivery.
❌ Limited throughput compared to Event Hub.
❌ More complex pricing in Premium tier.

Event Hub

✅ Handles millions of events/sec.
✅ Integration with real-time analytics tools.
❌ No DLQ or transaction features.
❌ Events cannot be modified once published.


✅ Quick Recap

  • Service Bus → enterprise messaging, guaranteed delivery, advanced features.
  • Event Hub → massive event streaming, telemetry, real-time ingestion.
  • Interviewers love to ask “Service Bus vs. Event Hub” → focus on use case differences.


Comments