Event Grid and choosing a messaging service

Microsoft Azure · Advanced · 13 min

Picking the wrong messaging service is a costly architectural mistake; Event Grid fills the reactive-event niche.

Azure Event Grid routes discrete events from sources to handlers with push delivery. Sources include Azure itself (system topics: blob created, resource group changes, Key Vault secret near expiry) and your apps (custom topics or namespace topics). Event subscriptions filter by event type, subject prefix/suffix or advanced filters, and deliver to webhooks, Functions, Service Bus, Storage queues or Event Hubs.

Delivery is at-least-once with exponential retries for up to 24 hours by default; undeliverable events go to a dead-letter blob container if configured. Events are small notifications ("this blob was created"), not the data itself, and the CloudEvents 1.0 schema is recommended. Event Grid namespaces also support pull delivery and an MQTT broker for IoT.

Choosing a service:

  • Event Grid: reactive "something happened" notifications, fan-out, near real-time, no ordering.
  • Service Bus: high-value commands and business messages needing transactions, ordering (sessions), dead-lettering and long retention.
  • Event Hubs: high-throughput streams (telemetry, clickstream), partitioned log with consumer offsets and replay; Kafka-compatible.
  • Queue Storage: simple, cheap, large backlogs of work items.

Many systems combine them: Event Grid notifies that a blob arrived, a function enqueues a Service Bus command, and telemetry flows to Event Hubs.

Example

SA_ID=$(az storage account show -g rg-data -n stordersprod01 --query id -o tsv)
FUNC_ID=$(az functionapp function show -g rg-fn -n fn-orders \
  --function-name on_invoice --query id -o tsv)

# React to new PDFs under invoices/ only, delivered to an Azure Function
az eventgrid event-subscription create --name invoices-to-fn \
  --source-resource-id "$SA_ID" \
  --endpoint-type azurefunction --endpoint "$FUNC_ID" \
  --included-event-types Microsoft.Storage.BlobCreated \
  --subject-begins-with /blobServices/default/containers/invoices/ \
  --subject-ends-with .pdf \
  --event-delivery-schema cloudeventschemav1_0

Remember

  • Event Grid pushes small event notifications to subscribers with filters
  • At-least-once with retries; configure dead-lettering
  • Service Bus for commands, Event Hubs for streams, Event Grid for reactions
  • Prefer the CloudEvents schema

Watch out for

  • Using Event Grid as a work queue for long processing: handlers should acknowledge quickly and hand off heavy work.

Check yourself

  1. You ingest 500,000 telemetry events per second and need to replay the last day. Which service fits?
  2. A function must run whenever a blob is uploaded to a container, with no polling. Which is the most direct fit?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: learn.microsoft.com/en-us/azure/event-grid/overview