Design infrastructure solutions · Topic 3 of 10

Messaging and Event Driven Architecture

AZ-305 integration design: choose Service Bus, Storage queues, Event Grid and Event Hubs for messages, events and streams, and design event driven systems.

  • 5 min
  • Includes a diagram
In a nutshell
  • Service Bus gives ordering with sessions, transactions, duplicate detection, dead lettering and topics. Storage queues give none of these but hold huge backlogs.
  • Event Grid routes discrete events with push delivery and no ordering. Event Hubs streams high volume data with partitions, replay and Kafka support.
  • Ordering in Event Hubs is only within a partition.

What it is

Loosely coupled systems talk through messages and events instead of direct calls. A message carries data that one component wants another to process, and the sender expects it to be handled. An event announces that something happened, and the sender does not care who reacts. A stream is a high volume sequence of events read by analysers. Azure has a service for each pattern, and picking the right one is a classic design question.

ProducersendsMessaging servicequeue, topic, event, streamConsumersprocess independentlyResilient systemdecoupled and scalable

How it works

The four services

ServicePatternBest for
Azure Service BusEnterprise messaging (queues and topics)Reliable business transactions between apps, ordering, transactions
Azure Storage queuesSimple queueVery large backlogs of basic work items at low cost
Azure Event GridEvent routing (push)Reacting to state changes, such as a blob created or a resource changed
Azure Event HubsEvent streamingTelemetry and log ingestion at huge scale, replay by consumers

Service Bus features

FeatureBehaviour
QueuesPoint to point. One consumer processes each message
Topics and subscriptionsPublish and subscribe. Each subscription gets a copy, with filters and rules
SessionsFirst in, first out ordering per session id
Dead letter queueAutomatically holds messages that fail or expire, for investigation
Duplicate detectionDrops duplicate messages within a time window
TransactionsGroup operations atomically
Scheduled and deferred messagesDeliver later
Premium tierDedicated capacity, large messages, zone redundancy, private endpoints, geo disaster recovery pairing

Use Service Bus when the requirement mentions ordering, transactions, duplicate detection, dead lettering or pub/sub with filters. A common pattern is competing consumers: several workers read one queue to scale out processing.

Storage queues

Storage queues are simple and cheap, hold more than 80 GB of messages, and give server side logs. They have no ordering guarantee, duplicate detection or automatic dead lettering. Choose them for a large backlog of simple tasks with no advanced needs.

Event Grid and Event Hubs

  • Event Grid is a push based event router. Publishers include Azure services and custom topics, and subscribers include Functions, Logic Apps, webhooks, Service Bus and Event Hubs. It has retry and dead lettering, no ordering guarantee, and it handles discrete events.
  • Event Hubs receives millions of events per second into partitions. Consumers read independently with consumer groups and can replay from an offset. Ordering is guaranteed only within a partition. It has Kafka protocol compatibility and Capture to write data to storage. Stream processing uses Stream Analytics, Spark or Functions.

Choosing between them

For a message that needs ordering or dead lettering use Service Bus, otherwise a Storage queue for a huge simple backlog. For an event, use Event Hubs for a high volume stream and Event Grid to react to changes.

RequirementChoice
Orders must be processed in sequence per customerService Bus queue with sessions
Bad messages must go to a dead letter storeService Bus
One event, many independent subscribers with filtersService Bus topic, or Event Grid
React to a blob upload or resource changeEvent Grid
Ingest telemetry from thousands of devicesEvent Hubs (or IoT Hub)
Massive simple backlog, lowest costStorage queue
A workflow where an event triggers a business processEvent Grid sends to a Service Bus queue

Event driven architecture patterns

  • Publish and subscribe decouples senders from receivers.
  • Competing consumers scale processing across workers.
  • Queue based load leveling absorbs bursts so the back end is not overwhelmed.
  • Event sourcing and CQRS store events as the source of truth.
  • Saga coordinates a transaction across services with compensating steps.
  • Idempotent consumers handle at least once delivery safely, because all these services deliver at least once.
  • Outbox pattern ensures a database change and a message are published together.
  • Combine services: Event Grid to Service Bus for reliable processing, or Event Hubs Capture to a lake.

A worked scenario

An order platform places orders on a Service Bus topic so billing, shipping and email each have a subscription with filters, using sessions to keep each customer's messages in order and the dead letter queue for failures. Warehouse sensors stream events into Event Hubs. When a blob lands in storage, Event Grid triggers a function that validates the file. Consumers are idempotent to cope with duplicates.

What to remember for the exam

  • Service Bus gives ordering with sessions, transactions, duplicate detection, dead lettering and topics. Storage queues give none of these but hold huge backlogs.
  • Event Grid routes discrete events with push delivery and no ordering. Event Hubs streams high volume data with partitions, replay and Kafka support.
  • Ordering in Event Hubs is only within a partition.
  • All the services deliver at least once, so consumers should be idempotent.
  • Service Bus Premium adds zone redundancy and geo disaster recovery pairing.
Exam tip

A message that must be processed is Service Bus. An event that merely announces something is Event Grid. A firehose is Event Hubs.

How the exam asks about this

  • "Messages must be processed in order per customer, with a dead letter queue." Service Bus with sessions.
  • "React when a file is created in storage." Event Grid.
  • "Ingest telemetry from millions of devices and process it later." Event Hubs.
  • "Store more than 80 GB of simple queued work cheaply." Storage queues.

Common mistakes

Using Event Grid for ordered work. It does not guarantee order.

Storage queues when duplicate detection is required.

Assuming exactly once delivery. Design idempotent consumers.

Using Event Hubs as a work queue.

Check yourself

  • Which service provides sessions for ordered processing?

    Azure Service Bus.

  • Which service routes discrete events with push delivery?

    Azure Event Grid.

  • Where is ordering guaranteed in Event Hubs?

    Within a partition.

Topic 3 of 10 in Design infrastructure solutions

Test yourself on Design infrastructure solutions

The full Microsoft AZ-305 question bank has 755 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Microsoft. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.