Event Grid and Event-Driven Architecture
Route events from Azure services and custom publishers using Event Grid, fan them out to multiple subscribers, and compare Event Grid with Event Hubs and Service Bus.
Event Grid and Event-Driven Architecture is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is Event-Driven Architecture?
In an event-driven architecture, components communicate by publishing and subscribing to events rather than calling each other directly. A component (producer) emits an event when something noteworthy happens — a file is uploaded, an order is placed, a device sends a reading. Other components (subscribers) react to events they care about, independently and asynchronously. This decouples producers from consumers, improving scalability, resilience, and maintainability.
What Is Azure Event Grid?
Azure Event Grid is a fully managed event routing service that delivers events from sources (publishers) to handlers (subscribers) using a push model. Event Grid is designed for reactive, discrete events — something changed and you need to react immediately. It guarantees at-least-once delivery with automatic retry, supports filtering so subscribers only receive relevant events, and can route events to Azure Functions, Logic Apps, webhooks, Event Hubs, and Service Bus queues.
Event Grid Topics and Event Subscriptions
Publishers send events to an Event Grid topic. Subscribers create event subscriptions on a topic, specifying an endpoint and optional filter rules. A single topic can have multiple subscriptions — each subscription receives an independent copy of matching events. Azure services such as Blob Storage, Resource Manager, Service Bus, and Azure Container Registry are built-in event sources with system topics that require no additional configuration.
# Create a custom Event Grid topic
az eventgrid topic create \
--name MyEventTopic \
--resource-group MyRG \
--location eastus
# Create a subscription routing to an Azure Function
az eventgrid event-subscription create \
--name myFunctionSub \
--source-resource-id '/subscriptions/.../providers/Microsoft.EventGrid/topics/MyEventTopic' \
--endpoint '/subscriptions/.../providers/Microsoft.Web/sites/myFunctionApp/functions/EventHandler'Event Schema
Events published to Event Grid follow a standard JSON schema with mandatory fields: id (unique identifier), eventType (e.g., Microsoft.Storage.BlobCreated), subject (path to the event resource), eventTime (ISO 8601 timestamp), dataVersion, and data (event-specific payload). Event Grid also supports CloudEvents schema (CNCF standard) for interoperability with other event platforms.
// Event Grid event payload (Event Grid schema)
[
{
'id': 'b781910b-3000-4f19-a4c2-b6b9c4ca7a12',
'eventType': 'Microsoft.Storage.BlobCreated',
'subject': '/blobServices/default/containers/uploads/blobs/photo.jpg',
'eventTime': '2025-01-15T12:30:00.000Z',
'data': {
'api': 'PutBlockList',
'url': 'https://mystorageacct.blob.core.windows.net/uploads/photo.jpg',
'contentType': 'image/jpeg',
'contentLength': 524288
},
'dataVersion': '',
'metadataVersion': '1'
}
]Event Filtering
Event subscriptions support filtering to reduce noise at the subscriber end. You can filter by event type (only receive BlobCreated, not BlobDeleted), subject prefix or suffix (only blobs in a specific container), or advanced filters on any field in the event data using operators like StringContains, NumberGreaterThan, and BoolEquals. Filtering happens server-side, so subscribers only receive events matching their criteria.
# Subscribe to BlobCreated events for .jpg files only
az eventgrid event-subscription create \
--name jpgImageSub \
--source-resource-id '/subscriptions/.../storageAccounts/mystorageaccount' \
--endpoint 'https://myfunction.azurewebsites.net/api/ProcessImage' \
--included-event-types 'Microsoft.Storage.BlobCreated' \
--subject-ends-with '.jpg'Event Grid vs Event Hubs vs Service Bus
Three Azure services handle events and messages — choose based on your scenario. Event Grid is for reactive event routing (low volume, discrete, reactive — e.g., resource change notification). Event Hubs is for high-throughput event streaming (millions of events/second, telemetry, big data pipelines). Service Bus is for enterprise messaging with ordering, deduplication, dead-lettering, and transactions (order processing, financial transactions).
// Decision guide:
// Event Grid — 'Something happened, react to it'
// Azure resource events, webhooks, low-latency fan-out
// Price: per event (cheap for low volume)
// Event Hubs — 'Capture a firehose of streaming data'
// IoT telemetry, log aggregation, real-time analytics
// Price: per throughput unit + capture
// Service Bus — 'Reliable message delivery between services'
// Order processing, workflow steps, dead-letter queues
// Price: per operation + messaging unitsPublishing Custom Events
Publish custom events to an Event Grid topic using a simple HTTP POST request with the topic's access key. Any service or application that can make HTTP requests can publish events. This makes it trivial to emit events from on-premises applications, third-party services, or Azure services that don't have native Event Grid support. Batch up to 1 MB of events per POST for efficiency.
# Get the topic endpoint and key
TOPIC_ENDPOINT=$(az eventgrid topic show --name MyEventTopic --resource-group MyRG --query endpoint -o tsv)
TOPIC_KEY=$(az eventgrid topic key list --name MyEventTopic --resource-group MyRG --query key1 -o tsv)
# Publish a custom event
curl -X POST $TOPIC_ENDPOINT \
-H 'Content-Type: application/json' \
-H "aeg-sas-key: $TOPIC_KEY" \
-d '[{
"id": "event-001",
"eventType": "Contoso.OrderPlaced",
"subject": "/orders/ORD-12345",
"eventTime": "2025-01-15T12:00:00Z",
"data": { "orderId": "ORD-12345", "total": 99.99 },
"dataVersion": "1.0"
}]'Dead Letter and Retry Policies
If an event delivery attempt fails (subscriber returns non-2xx HTTP), Event Grid retries using an exponential backoff with jitter for up to 24 hours (configurable up to 72 hours) with a maximum of 30 retries. After exhausting retries, Event Grid can dead-letter undelivered events to an Azure Blob Storage container for manual investigation. Configure dead-lettering when reliable event delivery is critical and you need to audit or reprocess failed events.
# Configure dead-letter storage and retry for a subscription
az eventgrid event-subscription update \
--name myFunctionSub \
--source-resource-id '/subscriptions/.../topics/MyEventTopic' \
--deadletter-endpoint '/subscriptions/.../storageAccounts/mystg/blobServices/default/containers/deadletter' \
--max-delivery-attempts 30 \
--event-ttl 1440 # 24 hours in minutesAzure Event Hubs Overview
Azure Event Hubs is a distributed data streaming platform capable of receiving and processing millions of events per second. It uses a partitioned consumer model — events are distributed across partitions, and each consumer group reads events independently at its own pace. This enables multiple consumers to process the same stream without coordination. Common use cases include IoT telemetry ingestion, application log aggregation, clickstream analysis, and real-time dashboard data pipelines.
# Create an Event Hubs namespace and hub
az eventhubs namespace create \
--name myEventHubNS \
--resource-group MyRG \
--location eastus \
--sku Standard
az eventhubs eventhub create \
--name telemetry \
--namespace-name myEventHubNS \
--resource-group MyRG \
--partition-count 8 \
--message-retention 3 # Days to retain eventsAzure Service Bus for Reliable Messaging
Azure Service Bus is an enterprise messaging broker providing queues (point-to-point) and topics with subscriptions (publish-subscribe). Unlike Event Grid (fire-and-forget) and Event Hubs (streaming), Service Bus guarantees ordered delivery (FIFO queues), duplicate detection, dead-letter queues for processing failures, message sessions for grouped processing, and transactions — all essential for financial and order processing workflows.
# Create a Service Bus namespace and queue
az servicebus namespace create \
--name myServiceBusNS \
--resource-group MyRG \
--location eastus \
--sku Standard
az servicebus queue create \
--name order-processing \
--namespace-name myServiceBusNS \
--resource-group MyRG \
--enable-dead-lettering-on-message-expiration true \
--max-delivery-count 10 # Move to dead-letter after 10 failed attemptsPractical Event-Driven Pattern: File Processing
A common Azure event-driven pattern: a user uploads a file to Blob Storage, which fires a BlobCreated event to Event Grid. Event Grid routes the event to an Azure Function that processes the file (resizes an image, extracts text, validates data) and writes the result to Azure SQL Database. If processing fails, the event is dead-lettered to a storage container. This entire pipeline requires zero polling and no persistent compute when idle.
// Azure Function: process image on BlobCreated event
module.exports = async function (context, eventGridEvent) {
const blobUrl = eventGridEvent.data.url;
const blobName = eventGridEvent.subject.split('/blobs/').pop();
context.log('Processing image:', blobName);
// Process via Cognitive Services Vision API
const tags = await analyzeImage(blobUrl);
// Write metadata to Cosmos DB via output binding
context.bindings.cosmosOutput = {
id: blobName,
tags,
processedAt: new Date().toISOString()
};
context.log('Processing complete for:', blobName);
};Quick Check
Test your understanding of Microsoft Azure Fundamentals (AZ-900) concepts from this lesson.
Lesson Recap
In this lesson you learned: Azure Event Grid routes discrete events from publishers to subscribers using push delivery with filtering and dead-lettering, the key difference between Event Grid (reactive events), Event Hubs (streaming), and Service Bus (reliable enterprise messaging), and how to build event-driven pipelines by chaining Blob Storage events through Event Grid to Azure Functions. Next up we explore Azure DevOps services.
Frequently asked questions
Is the “Event Grid and Event-Driven Architecture” lesson free?
Yes — the full text of “Event Grid and Event-Driven Architecture” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.
What will I learn in “Event Grid and Event-Driven Architecture”?
Route events from Azure services and custom publishers using Event Grid, fan them out to multiple subscribers, and compare Event Grid with Event Hubs and Service Bus. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cloud & IT Cert Prep?
No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Event Grid and Event-Driven Architecture” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cloud & IT Cert Prep lesson?
Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Azure Functions Triggers and Bindings
- Durable Functions for Stateful Workflows
- Azure Logic Apps
- Event Grid and Event-Driven Architecture