← Back to Articles         
Message Broker in Microservices

Message Broker in Microservices

Published on 29 Sep 2026     17 min read Microservices
Messaging & Event-Driven

Message Broker in Microservices

1. What is a Message Broker?

A Message Broker is middleware that sits between applications or microservices and helps them send, receive, route, store, and deliver messages without requiring the services to communicate directly.

In simple terms:

A Message Broker acts as a middleman between a message producer and message consumer.

Basic architecture:

Producer
   │
   │ Message
   ▼
┌───────────────────────┐
│    Message Broker     │
│                       │
│ Queue / Topic         │
│ Routing               │
│ Retry                 │
│ Dead-Letter Handling  │
└───────────┬───────────┘
            │
            ▼
         Consumer

Common message brokers and messaging platforms include:

  • Azure Service Bus
  • RabbitMQ
  • Apache Kafka
  • Amazon SQS/SNS
  • Google Cloud Pub/Sub
  • ActiveMQ

2. Simple Real-World Example

Think about a courier service.

You want to send a parcel to someone.

You don't personally travel to the recipient's house. Instead:

You
 ↓
Courier Company
 ↓
Recipient

The courier company accepts the parcel, keeps track of it, routes it, and delivers it.

A Message Broker performs a similar role:

Order Service
      ↓
OrderCreated
      ↓
Message Broker
      ↓
Notification Service

The Order Service doesn't have to directly call the Notification Service.


3. Why Do We Need a Message Broker?

Consider three microservices:

Order Service
Payment Service
Notification Service

Without a broker:

Order Service
    │
    ├──HTTP──> Payment Service
    │
    └──HTTP──> Notification Service

The Order Service has direct runtime dependencies on those services.

For example:

await httpClient.PostAsync(
    "https://payment-service/api/payments", content);

await httpClient.PostAsync(
    "https://notification-service/api/email", content);

Now suppose Notification Service is unavailable.

Order Service
     │
     ▼
Notification Service
     X
    DOWN

The Order Service must decide whether to:

  • Wait
  • Retry
  • Fail the request
  • Ignore the error
  • Store work somewhere for later

A broker can provide that asynchronous buffer.


4. With a Message Broker

Instead:

Order Service
      │
      │ OrderCreated
      ▼
┌────────────────────┐
│   Message Broker   │
│                    │
│   OrderCreated     │
└─────────┬──────────┘
          │
          ▼
Notification Service

If Notification Service is temporarily unavailable:

Order Service
      ↓
Message Broker
      ↓
Message retained*
      ↓
Notification Service DOWN

Later:

Notification Service starts
          ↓
Message Broker
          ↓
OrderCreated
          ↓
Notification Service
          ↓
Send Email

* Retention/durability depends on the broker and configuration.

This is one of the major advantages of using a message broker.


5. Purpose of a Message Broker

A message broker can provide several capabilities:

Purpose Description
Decoupling Producer doesn't directly depend on consumer availability
Message storage Durable messages can wait for processing
Routing Messages can be sent to appropriate destinations
Asynchronous processing Producer doesn't wait for consumer business processing
Load leveling Traffic spikes can be buffered
Retry/redelivery Failed processing can be attempted again
Dead-lettering Problem messages can be isolated
Pub/Sub One message/event can reach multiple subscribers
Scalability Multiple consumers can process work
Reliability Helps reduce message loss when configured correctly

6. Main Components

A messaging architecture usually contains:

Producer
   ↓
Message
   ↓
Broker
   ↓
Queue / Topic
   ↓
Consumer

Let's understand each.


7. Producer

The Producer creates and sends/publishes a message.

Example:

Order Service

After creating an order:

OrderCreated

Example message:

{
  "eventId": "3bd0d47e",
  "eventType": "OrderCreated",
  "orderId": 1001,
  "customerId": 501,
  "amount": 2500
}

The Order Service is therefore the producer.


8. Consumer

The Consumer receives and processes a message.

Example:

Notification Service

It receives:

OrderCreated

and performs:

Send confirmation email

Another consumer might do:

Inventory Service
      ↓
Reserve stock

9. Message Broker

The broker sits between them:

Producer
   │
   │ OrderCreated
   ▼
┌────────────────────┐
│   Message Broker   │
└─────────┬──────────┘
          │
          ▼
       Consumer

The producer doesn't need to directly invoke the consumer's HTTP endpoint.


10. What is a Queue?

A Queue stores messages until consumers process them.

Producer
   ↓
┌─────────────────────┐
│        Queue        │
│                     │
│ Message 1           │
│ Message 2           │
│ Message 3           │
│ Message 4           │
└──────────┬──────────┘
           │
           ▼
        Consumer

Typical queue use cases:

ProcessPayment
GenerateInvoice
SendEmail
ResizeImage
ProcessOrder

11. Multiple Consumers on a Queue

Suppose there are 10,000 messages.

Instead of one consumer:

Queue
  ↓
Consumer 1

you could scale the consumer:

                 ┌──> Consumer 1
                 │
Queue ───────────┼──> Consumer 2
                 │
                 └──> Consumer 3

These are commonly called:

Competing Consumers

A particular queue message is normally processed by one consumer instance, not all three.

For example:

Message 1 → Consumer 1
Message 2 → Consumer 2
Message 3 → Consumer 3
Message 4 → Consumer 1

The exact distribution is broker-dependent.


12. What is a Topic?

A Topic is commonly used for Publish/Subscribe scenarios.

Suppose:

OrderCreated

needs to be processed by:

Inventory Service
Notification Service
Analytics Service

Architecture:

                   Order Service
                        │
                        │ OrderCreated
                        ▼
                ┌────────────────┐
                │  Orders Topic  │
                └───────┬────────┘
                        │
          ┌─────────────┼─────────────┐
          ▼             ▼             ▼
      Inventory     Notification   Analytics
    Subscription    Subscription  Subscription
          │             │             │
          ▼             ▼             ▼
      Inventory     Notification   Analytics
       Service        Service       Service

Each subscription gets its own logical copy of the event.


13. Queue vs Topic

This is an important interview question.

Queue Topic
Point-to-point/work queue Publish/Subscribe
One logical processing path Multiple independent subscribers
Competing consumers Fan-out
Work distribution Event distribution
Usually one consumer instance processes each message Each subscription can receive the event

Example:

Queue

ProcessPayment
      ↓
Payment Queue
      ↓
Payment Service

Topic

OrderCreated
      ↓
Orders Topic
      ├──> Inventory
      ├──> Notification
      └──> Analytics

14. How Does a Message Broker Work?

Let's take an e-commerce example.

Customer places an order.

Step 1 — Create Order

Client
  ↓
POST /api/orders
  ↓
Order Service

Step 2 — Store Order

Order Service
     ↓
Order Database

Step 3 — Create Event

OrderCreated

Step 4 — Publish

Order Service
     ↓
OrderCreated
     ↓
Message Broker

Step 5 — Broker stores/routes it

The broker determines which queue, topic, or subscription should receive the message.

Step 6 — Consumer receives it

Message Broker
      ↓
Notification Service

Step 7 — Consumer processes it

Notification Service
      ↓
Send Email

Step 8 — Acknowledge

After successful processing:

Consumer
    ↓
ACK / Complete
    ↓
Broker

The broker can then consider that message successfully processed.


15. Message Acknowledgement

Acknowledgement is extremely important.

Suppose the broker sends:

OrderCreated

to a consumer.

Broker
   │
   │ Deliver
   ▼
Consumer
   │
   │ Process
   ▼
Send Email

After successful processing:

Consumer
   │
   │ ACK
   ▼
Broker

This tells the broker:

I successfully processed this message.

Depending on the technology, this might be called:

ACK
Complete
Commit

16. What Happens When Processing Fails?

Suppose:

Broker
   ↓
OrderCreated
   ↓
Notification Service
   ↓
Email provider unavailable
   ↓
Exception

The message can be abandoned/not acknowledged and subsequently redelivered according to broker behavior and application configuration.

Conceptually:

Message
   ↓
Consumer
   ↓
FAIL
   ↓
Retry / Redelivery
   ↓
Consumer

17. Dead-Letter Queue

What if the message keeps failing?

For example:

Attempt 1 → Failed
Attempt 2 → Failed
Attempt 3 → Failed
...

Eventually the broker can move it to a:

Dead-Letter Queue (DLQ)

Message
   ↓
Consumer
   ↓
Failure
   ↓
Retry / Redelivery
   ↓
Still failing
   ↓
┌────────────────────┐
│ Dead-Letter Queue  │
└────────────────────┘

The operations/development team can investigate it later.


18. Poison Message

A message that repeatedly fails processing is often called a:

Poison Message

For example:

{
  "orderId": "ABC",
  "quantity": -500
}

Or the message could be valid but expose a bug in the consumer.

Without controlled retries and dead-letter handling:

Message
 ↓
Fail
 ↓
Retry
 ↓
Fail
 ↓
Retry
 ↓
Fail
 ↓
...

could continue unnecessarily.


19. Message Durability

A major capability of many message brokers is durable messaging.

Suppose:

Order Service publishes OrderCreated

but:

Notification Service = DOWN

With durable configuration:

Order Service
     ↓
OrderCreated
     ↓
Message Broker
     ↓
Stored
     ↓
Notification unavailable

Later:

Notification starts
     ↓
Broker delivers message
     ↓
Notification processes it

Exact guarantees depend on the broker, message persistence settings, retention, TTL, acknowledgement mode, and topology.


20. Load Leveling

Suppose normally:

100 orders/minute

but during a sale:

20,000 orders/minute

Without buffering:

Order Service
     ↓
20,000 direct requests
     ↓
Notification Service

OVERLOAD

With a broker:

20,000 messages
       ↓
┌───────────────────┐
│   Message Broker  │
│                   │
│   Queue Buffer    │
└─────────┬─────────┘
          │
          ▼
Consumers process
at sustainable rate

This is known as load leveling.


21. Message Routing

A broker can also route messages.

Suppose we have:

OrderCreated
OrderCancelled
PaymentCompleted
PaymentFailed

Depending on the broker, routing rules, topics, subscriptions, filters, routing keys, or bindings can determine which consumer receives which messages.

Conceptually:

                    Message Broker
                         │
             ┌───────────┼────────────┐
             │           │            │
             ▼           ▼            ▼
        Inventory    Notification   Analytics

For example:

OrderCreated
     ↓
Inventory + Notification + Analytics

PaymentFailed
     ↓
Notification + Payment Monitoring

22. Message Filtering

Some brokers support subscription filters.

For example:

Orders Topic
     │
     ├── OrderCreated
     ├── OrderCancelled
     └── OrderShipped

Inventory may only be interested in:

OrderCreated
OrderCancelled

Shipping might care about a different subset.

Broker-side filtering can reduce unnecessary consumer processing.


23. Message Broker and Event-Driven Architecture

A Message Broker is commonly a core infrastructure component in Event-Driven Architecture.

Event Producer
      ↓
OrderCreated
      ↓
Message Broker
      ↓
Event Consumers

For example:

                    OrderCreated
                         │
                         ▼
                  Message Broker
                         │
           ┌─────────────┼──────────────┐
           ▼             ▼              ▼
       Inventory     Notification    Analytics

The broker enables producers and consumers to operate more independently.


24. Message Broker vs Event-Driven Architecture

They are not the same thing.

Message Broker

A technology/infrastructure component used to transport and manage messages.

Examples:

Azure Service Bus
RabbitMQ
Kafka

Event-Driven Architecture

An architectural style where events drive system behavior.

OrderCreated
    ↓
Interested services react

Therefore:

A Message Broker can be used to implement Event-Driven Architecture, but the broker itself is not the architecture.


25. Message Broker vs API Gateway

This is another important distinction.

API Gateway

Handles client-facing synchronous requests:

Client
  ↓
API Gateway
  ↓
Microservice

Typical responsibilities include:

Routing
Authentication
Authorization
Rate limiting
Load balancing
Request transformation

Message Broker

Handles asynchronous messages between producers and consumers:

Producer
   ↓
Message Broker
   ↓
Consumer

Typical responsibilities include:

Queueing
Message routing
Delivery
Pub/Sub
Redelivery
Dead-lettering

26. API Gateway + Message Broker Together

A microservice architecture can use both.

                    Client
                      │
                      ▼
                 API Gateway
                      │
                      ▼
                Order Service
                      │
                      │ OrderCreated
                      ▼
              ┌────────────────┐
              │ Message Broker │
              └───────┬────────┘
                      │
           ┌──────────┼──────────┐
           ▼          ▼          ▼
       Inventory   Email     Analytics
        Service   Service     Service

They solve different problems.


27. Common Message Brokers

Azure Service Bus

Microsoft Azure managed messaging service.

Supports concepts such as:

Queues
Topics
Subscriptions
Dead-letter queues
Sessions
Duplicate detection
Scheduled messages
Filters

Very useful for Azure-hosted enterprise applications.


RabbitMQ

Popular open-source message broker.

Important concepts include:

Producer
Exchange
Queue
Binding
Consumer
Routing Key

Architecture:

Producer
   ↓
Exchange
   ↓
Routing
   ↓
Queue
   ↓
Consumer

Apache Kafka

Kafka is primarily a distributed event streaming platform rather than a traditional queue broker.

Core concepts include:

Producer
Topic
Partition
Consumer
Consumer Group
Offset

Architecture:

Producer
   ↓
Topic
   ↓
Partitions
   ↓
Consumer Group

Kafka is particularly useful for:

High-throughput event streams
Analytics pipelines
Log/event processing
Data integration
Event streaming

28. Azure Service Bus vs RabbitMQ vs Kafka

A simplified comparison:

Feature Azure Service Bus RabbitMQ Kafka
Primary model Enterprise messaging Message broker Event streaming
Queue Yes Yes Different model
Pub/Sub Yes Yes Yes
Managed cloud service Yes Available via hosted offerings Available via hosted offerings
Traditional message routing Strong Very strong Topic/partition based
Event replay Limited compared with Kafka Not primary model Strong
High-throughput event streaming Moderate Moderate Excellent
Azure integration Excellent Possible Possible
Typical use Enterprise workflows General messaging Streaming/event pipelines

Do not choose solely from this table—the correct choice depends on delivery semantics, throughput, ordering, replay, routing, operations, hosting model, and application requirements.


29. ASP.NET Core Example with Azure Service Bus

Let's implement:

Order Service
     ↓
Message Broker
     ↓
Notification Service

Required NuGet Package

dotnet add package Azure.Messaging.ServiceBus

Package:

Azure.Messaging.ServiceBus

30. appsettings.json

For a simple learning example:

{
  "AzureServiceBus": {
    "ConnectionString": "<your-connection-string>",
    "QueueName": "orders"
  }
}

For production, prefer secure configuration such as:

Managed Identity
Azure Key Vault
Environment Variables

rather than committing secrets into source control.


31. Message Model

public class OrderCreatedMessage
{
    public Guid MessageId { get; set; }

    public int OrderId { get; set; }

    public int CustomerId { get; set; }

    public decimal Amount { get; set; }

    public DateTime CreatedAt { get; set; }
}

32. Publisher Interface

public interface IMessagePublisher
{
    Task PublishAsync<T>(T message);
}

33. Azure Service Bus Publisher

using Azure.Messaging.ServiceBus;
using System.Text.Json;

public class AzureServiceBusPublisher : IMessagePublisher
{
    private readonly ServiceBusClient _client;
    private readonly IConfiguration _configuration;

    public AzureServiceBusPublisher(
        ServiceBusClient client,
        IConfiguration configuration)
    {
        _client = client;
        _configuration = configuration;
    }

    public async Task PublishAsync<T>(T message)
    {
        string queueName =
            _configuration["AzureServiceBus:QueueName"]!;

        ServiceBusSender sender =
            _client.CreateSender(queueName);

        string json =
            JsonSerializer.Serialize(message);

        var serviceBusMessage =
            new ServiceBusMessage(json);

        await sender.SendMessageAsync(
            serviceBusMessage);
    }
}

34. Program.cs

using Azure.Messaging.ServiceBus;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

string connectionString =
    builder.Configuration[
        "AzureServiceBus:ConnectionString"]!;

builder.Services.AddSingleton(
    new ServiceBusClient(connectionString));

builder.Services.AddScoped<
    IMessagePublisher,
    AzureServiceBusPublisher>();

var app = builder.Build();

app.MapControllers();

app.Run();

35. OrdersController

using Microsoft.AspNetCore.Mvc;

[ApiController]
[Route("api/[controller]")]
public class OrdersController : ControllerBase
{
    private readonly IMessagePublisher _publisher;

    public OrdersController(
        IMessagePublisher publisher)
    {
        _publisher = publisher;
    }

    [HttpPost]
    public async Task<IActionResult> Create()
    {
        // Normally save order to database.

        var message = new OrderCreatedMessage
        {
            MessageId = Guid.NewGuid(),
            OrderId = 1001,
            CustomerId = 501,
            Amount = 2500,
            CreatedAt = DateTime.UtcNow
        };

        await _publisher.PublishAsync(message);

        return Ok(new
        {
            Message = "Order created successfully",
            OrderId = message.OrderId
        });
    }
}

Now:

Client
  ↓
POST /api/orders
  ↓
OrdersController
  ↓
Save Order
  ↓
OrderCreatedMessage
  ↓
AzureServiceBusPublisher
  ↓
Azure Service Bus
  ↓
orders Queue

36. Consumer

Another microservice can consume the queue.

using Azure.Messaging.ServiceBus;

public class OrderConsumer : BackgroundService
{
    private readonly ServiceBusClient _client;
    private readonly IConfiguration _configuration;

    public OrderConsumer(
        ServiceBusClient client,
        IConfiguration configuration)
    {
        _client = client;
        _configuration = configuration;
    }

    protected override async Task ExecuteAsync(
        CancellationToken stoppingToken)
    {
        string queueName =
            _configuration[
                "AzureServiceBus:QueueName"]!;

        ServiceBusProcessor processor =
            _client.CreateProcessor(queueName);

        processor.ProcessMessageAsync +=
            ProcessMessageAsync;

        processor.ProcessErrorAsync +=
            ProcessErrorAsync;

        await processor.StartProcessingAsync(
            stoppingToken);

        await Task.Delay(
            Timeout.Infinite,
            stoppingToken);
    }

    private async Task ProcessMessageAsync(
        ProcessMessageEventArgs args)
    {
        string body =
            args.Message.Body.ToString();

        Console.WriteLine(
            $"Received: {body}");

        // Perform business operation.

        await args.CompleteMessageAsync(
            args.Message);
    }

    private Task ProcessErrorAsync(
        ProcessErrorEventArgs args)
    {
        Console.WriteLine(
            args.Exception.Message);

        return Task.CompletedTask;
    }
}

Register:

builder.Services.AddHostedService<OrderConsumer>();

37. Complete Flow

┌───────────────┐
│    Client     │
└───────┬───────┘
        │
        │ POST /orders
        ▼
┌───────────────┐
│ Order Service │
└───────┬───────┘
        │
        │ OrderCreated
        ▼
┌──────────────────────┐
│ Azure Service Bus    │
│                      │
│     orders Queue     │
└───────────┬──────────┘
            │
            │ Deliver
            ▼
┌──────────────────────┐
│ Notification Service │
└───────────┬──────────┘
            │
            ▼
      Send Email
            │
            ▼
        Complete

38. Important Production Considerations

Simply adding a broker isn't enough for a reliable production system.

You should also think about:

Retry
Dead-Letter Queue
Idempotency
Duplicate messages
Message ordering
Message expiration / TTL
Correlation IDs
Distributed tracing
Schema versioning
Monitoring
Security
Transactional Outbox

39. Idempotency

A broker may deliver the same logical message more than once depending on delivery semantics and failures.

Suppose:

MessageId = ABC123

The consumer processes it.

Before successful acknowledgement, the connection fails.

The message might be delivered again.

Therefore:

if (await AlreadyProcessed(messageId))
{
    return;
}

await ProcessMessage();

await MarkAsProcessed(messageId);

This helps avoid:

Duplicate payment
Duplicate invoice
Duplicate email
Duplicate inventory reduction

40. Transactional Outbox

Another important issue:

await SaveOrder();

await PublishMessage();

What happens if:

SaveOrder()      → SUCCESS

PublishMessage() → FAILURE

The order exists, but no message was published.

A common solution is the Transactional Outbox Pattern:

Order Service
      ↓
┌─────────────────────────┐
│ Database Transaction    │
│                         │
│ Insert Order            │
│ Insert Outbox Message   │
│                         │
│ COMMIT                  │
└───────────┬─────────────┘
            │
            ▼
      Outbox Processor
            │
            ▼
      Message Broker

The outbox processor retries publishing independently.


41. Advantages

Loose Coupling

Producer → Broker → Consumer

Producer doesn't need a direct runtime call to every consumer.

Asynchronous Processing

Producer can continue without waiting for downstream business processing.

Fault Tolerance

Temporary consumer failures can be absorbed by durable queues.

Scalability

Consumers can scale horizontally.

Load Leveling

The broker buffers traffic spikes.

Pub/Sub

Multiple services can react to the same event.

Reliability Features

Depending on the broker:

Durability
Acknowledgements
Retry/redelivery
Dead-lettering
Duplicate detection

may be available.


42. Disadvantages

Additional Infrastructure

The broker itself must be:

Configured
Secured
Monitored
Scaled
Maintained

unless using a managed service that handles part of this.

Increased Complexity

You now have:

Producer
Broker
Queue/Topic
Consumer
Retry
DLQ

instead of a simple HTTP call.

Eventual Consistency

Consumer processing may happen later.

Debugging Complexity

Distributed tracing becomes important.

Duplicate Processing

Consumers often need idempotency.

Ordering Problems

Message ordering must be considered explicitly.

Broker Dependency

The broker becomes critical infrastructure.


43. Key Points

For interview preparation, remember:

  • A Message Broker is middleware between message producers and consumers.
  • It receives, routes, stores, and delivers messages.
  • It helps create loose coupling between microservices.
  • Message brokers are heavily used for asynchronous communication.
  • Queues are commonly used for point-to-point/work distribution.
  • Topics + subscriptions are commonly used for publish/subscribe.
  • Multiple instances consuming a queue implement the Competing Consumers pattern.
  • Durable messaging allows temporary consumer downtime.
  • Acknowledgement/completion confirms successful processing.
  • Failed messages may be redelivered.
  • Repeatedly failing messages can be placed in a Dead-Letter Queue.
  • Consumers should consider idempotency.
  • Transactional Outbox helps prevent database/message inconsistencies.
  • Common technologies include Azure Service Bus, RabbitMQ, and Kafka.
  • A Message Broker is an infrastructure component; EDA is an architectural style.

44. Interview Questions and Answers

Q1. What is a Message Broker?

Answer:

A Message Broker is middleware that allows applications or microservices to communicate by exchanging messages without directly calling each other. It can receive, store, route and deliver messages between producers and consumers.


Q2. Why do we need a Message Broker?

Answer:

We use a Message Broker to reduce direct coupling between services, support asynchronous processing, buffer traffic spikes, improve resilience to temporary consumer failures, and enable messaging patterns such as queues and publish/subscribe.


Q3. What are examples of Message Brokers?

Answer:

Common technologies include:

Azure Service Bus
RabbitMQ
Apache Kafka
ActiveMQ
Amazon SQS/SNS

Kafka is more specifically an event-streaming platform, although it often fills a broker-like role in event-driven architectures.


Q4. What is the difference between Producer and Consumer?

Answer:

A Producer sends or publishes messages.

A Consumer receives and processes those messages.

Producer → Broker → Consumer

Q5. What is a Queue?

Answer:

A queue stores messages until they are processed. With competing consumers, each message is normally processed by one consumer instance.


Q6. What is a Topic?

Answer:

A topic is commonly used for publish/subscribe communication. Multiple independent subscriptions can receive the same published event.

OrderCreated Topic
       ├──> Inventory
       ├──> Notification
       └──> Analytics

Q7. What happens when the consumer is down?

Answer:

With durable messaging, the broker can retain messages until the consumer becomes available again, subject to message expiration, retention and broker configuration.


Q8. What is acknowledgement?

Answer:

Acknowledgement tells the broker that the consumer successfully processed the message. In Azure Service Bus, for example, a consumer can complete a received message after successful processing.


Q9. What is a Dead-Letter Queue?

Answer:

A Dead-Letter Queue stores messages that cannot be successfully processed or delivered according to configured rules. Developers or operations teams can investigate those messages separately.


Q10. What is a poison message?

Answer:

A poison message is a message that repeatedly fails processing because of invalid data, incompatible schema, business validation problems, or consumer defects.


Q11. Can the same message be received twice?

Answer:

Yes. Depending on the messaging system and delivery semantics, duplicate delivery is possible. Consumers should therefore be designed to be idempotent when duplicate processing could cause problems.


Q12. Queue vs Topic?

Answer:

Use a queue when a message should go through one logical processing pipeline.

Use topics/subscriptions when multiple independent services need to receive the same event.


Q13. Message Broker vs API Gateway?

Answer:

An API Gateway primarily manages synchronous client-to-service API traffic:

Client → API Gateway → Microservice

A Message Broker primarily facilitates asynchronous communication:

Producer → Message Broker → Consumer

They solve different problems and are commonly used together.


Q14. What is the difference between Message Broker and Event-Driven Architecture?

Answer:

A Message Broker is infrastructure used to transport messages.

Event-Driven Architecture is an architectural style where events such as OrderCreated or PaymentCompleted drive the behavior of other components.


Q15. How do you reliably publish an event after updating a database?

Answer:

A common approach is the Transactional Outbox Pattern. The application stores the business change and an outbox message in the same local database transaction. A background process then publishes the outbox record to the broker.


Interview-Friendly Final Answer

A Message Broker is middleware that sits between producers and consumers and manages the exchange of messages. Instead of one microservice directly calling another, the producer sends a message to the broker, and the broker stores, routes and delivers it to the appropriate consumer. Message brokers support asynchronous communication, loose coupling, load leveling, scalability and resilience. Common technologies include Azure Service Bus, RabbitMQ and Kafka. Important concepts include queues, topics, subscriptions, acknowledgements, retries, dead-letter queues, idempotency and message durability. In production microservices, patterns such as Transactional Outbox and idempotent consumers are often used with brokers to improve reliability.

← Back to Articles