Skip to content

Azure Event Grid

What Azure Event Grid Is

Azure Event Grid is a fully managed publish-subscribe service for routing discrete events. A publisher announces that something happened; one or more subscribers receive that fact and react independently. The publisher does not call each subscriber directly and does not need to know which subscribers exist.

Event Grid is a strong fit for reactive integration: a blob was created, a resource changed state, a deployment completed, a business event occurred, or a partner application emitted a notification. It is not a general-purpose work queue and not a high-volume event-streaming platform. Use it to distribute events—facts about something that has already happened—not commands asking one specific worker to do work.

Azure supports two Event Grid tiers:

  • Event Grid Basic provides system topics, custom topics, partner topics, domains, and push delivery to Azure services and webhooks. It is the familiar model for Azure resource events such as Blob Storage notifications.
  • Event Grid Standard uses namespaces and namespace topics. It adds CloudEvents HTTP publication, HTTP pull delivery, push delivery, and an MQTT broker for device and application messaging. Capabilities and supported push destinations differ by tier and continue to evolve, so verify the current matrix for the selected tier before committing an architecture. Choose the right Event Grid tier

The core value is decoupling. An application that publishes orders.created.v1 can gain fraud screening, analytics, notifications, and fulfilment subscribers without a new dependency or deployment in the ordering application.


Event Grid Terminology

Term Meaning
Event An immutable notification that a state change or business fact occurred. It includes metadata and a data payload.
Publisher An Azure service, custom application, or partner that emits events.
Source The resource or application that produced the event, for example a Storage account or an order service.
Topic An endpoint or logical channel that receives events. The type depends on the Event Grid tier and source.
System topic A topic representing events emitted by an Azure resource, such as a Storage account.
Custom topic A Basic-tier topic to which an application publishes its own events.
Namespace topic A Standard-tier topic inside an Event Grid namespace; it accepts CloudEvents and supports pull or push delivery patterns.
Event subscription A routing rule from a topic/source to a handler or consumer, with filters and delivery policy.
Event handler The destination that receives pushed events, such as an Azure Function, Event Hubs, Service Bus, Storage Queue, or webhook, depending on tier and event source.
Dead-letter destination A Blob Storage container configured to receive events Event Grid could not deliver.
CloudEvents An open event-envelope specification. Event Grid supports CloudEvents 1.0 for interoperable HTTP eventing.

For the full current service vocabulary and delivery models, see the Azure Event Grid overview.


The Core Architecture

flowchart LR
    Storage[Azure Blob Storage] -->|BlobCreated| EG[Azure Event Grid]
    App[Order service] -->|orders.created.v1| EG
    EG -->|filtered subscription| Function[Azure Function]
    EG -->|filtered subscription| Webhook[Partner webhook]
    EG -->|filtered subscription| Queue[Azure Service Bus]
    Function --> DB[(Azure Cosmos DB or Azure SQL)]
    EG -->|delivery failure| DLQ[Blob Storage dead-letter container]
    Function --> Monitor[Application Insights]

An event subscription is configuration, not application code. It can filter by event type, subject prefix/suffix, or advanced attributes, then deliver only the relevant events to a handler. This lets a storage account publish all of its events while one subscriber sees only PDFs created under invoices/ and another sees only deleted blobs.

Event Grid is intentionally asynchronous. A publisher receives acknowledgement that Event Grid accepted the event, not that every subscriber has completed its work. Subscribers must make their own processing idempotent because delivery is at least once.


When to Use Event Grid

Use Event Grid when these statements are true:

  • A producer needs to announce a discrete occurrence, not synchronously request a result.
  • Several current or future consumers may react independently.
  • The producer should be decoupled from subscriber availability and identity.
  • Filtering and fan-out are useful.
  • Near-real-time notification is valuable, but the payload is an event rather than a large retained data stream.
  • The receiving service can tolerate at-least-once, out-of-order delivery and handles duplicates safely.

Common Azure scenarios include:

  • Start document processing when a Blob Storage object is created.
  • Notify a function when a Cosmos DB, Azure Resource Manager, or partner event occurs.
  • Fan out order.shipped to a notification service, analytics pipeline, and customer portal projection.
  • Route Azure resource lifecycle events to operations automation.
  • In Standard namespaces, consume custom CloudEvents by HTTP pull when a consumer needs control over when it receives work.

Do not use Event Grid as the sole mechanism for a high-value command requiring a named worker, ordered processing, long-term broker retention, or transactional receive semantics. Route the notification to Azure Service Bus or Event Hubs when those are the actual requirements.


Event Grid Compared with Service Bus and Event Hubs

Service Primary purpose Data model Choose it when
Azure Event Grid Reactive event routing and fan-out Discrete event notifications Something happened and interested systems should react.
Azure Service Bus Enterprise messaging and work distribution Commands and high-value messages A named worker must reliably process work; queues, sessions, dead-lettering, and transactional messaging matter.
Azure Event Hubs High-throughput telemetry and stream ingestion Partitioned, retained event stream Many producers write large-volume, ordered-by-partition data that multiple consumers read at their own pace.
flowchart TD
    Start[What are you moving?] --> Command{Ask one logical worker\nto do business work?}
    Command -->|Yes| SB[Azure Service Bus]
    Command -->|No| Stream{High-volume telemetry or\na retained ordered stream?}
    Stream -->|Yes| EH[Azure Event Hubs]
    Stream -->|No| Event{A discrete fact that\nmultiple systems may react to?}
    Event -->|Yes| EG[Azure Event Grid]
    Event -->|No| Review[Review synchronous API or workload design]

These services often work together. For example, Event Grid can announce that a file arrived, an Azure Function can validate it, and the Function can place a durable command on Service Bus. An e-commerce system might use Service Bus for fulfilment commands, Event Hubs for clickstream telemetry, and Event Grid for the order.shipped notification. Azure messaging-service comparison


Event Shape and Contracts

An event should describe an immutable fact in the past tense, such as orders.created.v1 or com.contoso.invoice.approved.v1. It should not be an imperative command such as process-invoice-now.

CloudEvents provides standard envelope fields, including:

Field Purpose
id Unique event identifier used for deduplication and tracing.
source URI-like identifier for the producing system or resource.
type Versioned event type.
subject Fine-grained resource or aggregate identity, useful for filtering.
time When the event occurred.
datacontenttype Payload format, commonly application/json.
data Domain-specific event payload.

Example CloudEvent:

{
  "specversion": "1.0",
  "id": "b5ea6bfe-4897-43ec-94ea-bc1668c975b8",
  "source": "/services/orders",
  "type": "com.contoso.orders.shipped.v1",
  "subject": "orders/ORD-1042",
  "time": "2026-11-23T12:00:00Z",
  "datacontenttype": "application/json",
  "data": {
    "orderId": "ORD-1042",
    "trackingNumber": "ZX-48290"
  }
}

Keep events small and self-contained enough for the intended subscriber. For large documents, publish a stable identifier or protected storage reference rather than embedding the document. Treat event schemas as public contracts: version them deliberately, add fields compatibly, and do not expose secrets or unnecessary personal data.


Publishing Custom Events from .NET

For a custom topic, the Azure SDK can publish EventGridEvent records. The following example constructs an event with a stable ID and a versioned type. In production, do this after the related state change is durable—usually through the Transactional Outbox pattern rather than a direct database-plus-Event-Grid dual write.

using Azure;
using Azure.Identity;
using Azure.Messaging.EventGrid;

public sealed class OrderEventPublisher(EventGridPublisherClient client)
{
    public Task PublishShippedAsync(
        OrderShippedV1 order,
        CancellationToken cancellationToken)
    {
        var cloudEvent = new CloudEvent(
            "/services/orders",
            "com.contoso.orders.shipped.v1",
            order)
        {
            Id = order.EventId.ToString(),
            Subject = $"orders/{order.OrderId}",
            Time = DateTimeOffset.UtcNow
        };

        return client.SendEventAsync(cloudEvent, cancellationToken);
    }
}

public sealed record OrderShippedV1(
    Guid EventId,
    string OrderId,
    string TrackingNumber);

Register a single EventGridPublisherClient with the endpoint and the authentication method supported by the chosen topic type. Prefer Microsoft Entra ID and managed identity where the service supports it; use a key only where that is the available authentication model, and keep it in Key Vault. Separately authorize publishers and subscribers with least-privilege Azure RBAC roles.

The producer reliability rule

Do not do this in a request handler:

commit order to database
publish OrderShipped directly to Event Grid

If the process fails between those operations, the order change commits but no subscriber is notified. Instead, commit an outbox event in the same transaction as the order change; a relay publishes it to Event Grid after commit. See Transactional Outbox Pattern for the detailed implementation.


Consuming Events in Azure Functions

Azure Functions is a common Event Grid handler. The function must assume an event can be delivered more than once and must not depend on delivery order. Persist the event ID, use a business-level uniqueness constraint, or employ the Transactional Inbox pattern before applying irreversible effects.

using Azure.Messaging;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

public sealed class BlobCreatedHandler(ILogger<BlobCreatedHandler> logger)
{
    [Function(nameof(BlobCreatedHandler))]
    public async Task Run(
        [EventGridTrigger] CloudEvent cloudEvent,
        CancellationToken cancellationToken)
    {
        if (await WasProcessedAsync(cloudEvent.Id, cancellationToken))
        {
            return;
        }

        await ProcessBlobAsync(cloudEvent.Data, cancellationToken);
        await RecordProcessedAsync(cloudEvent.Id, cancellationToken);

        logger.LogInformation(
            "Processed Event Grid event {EventId} of type {EventType}",
            cloudEvent.Id,
            cloudEvent.Type);
    }

    private static Task<bool> WasProcessedAsync(string eventId, CancellationToken cancellationToken) =>
        Task.FromResult(false);

    private static Task ProcessBlobAsync(BinaryData data, CancellationToken cancellationToken) =>
        Task.CompletedTask;

    private static Task RecordProcessedAsync(string eventId, CancellationToken cancellationToken) =>
        Task.CompletedTask;
}

The abbreviated persistence methods are intentionally placeholders. A production handler should use a database transaction that records the event ID and business state together; checking then recording separately has a race condition. The Transactional Inbox Pattern shows that implementation in detail.

When handlers need lengthy or ordered business processing, use Event Grid to notify an ingress component and have that component write a command to Service Bus. This separates lightweight event routing from durable work processing and lets the worker manage lock duration, retries, and dead-letter queues.


Filtering and Fan-Out

Filtering at the Event Grid subscription is an efficiency and boundary tool, not a correctness or security control. It reduces unnecessary delivery and helps consumers receive only relevant events.

flowchart LR
    Topic[Storage system topic] --> F1{eventType = BlobCreated\nsubject starts invoices/}
    Topic --> F2{eventType = BlobDeleted}
    F1 --> Invoice[Invoice processing Function]
    F2 --> Audit[Audit webhook]

Use filters to express stable routing criteria:

  • Event type, such as Microsoft.Storage.BlobCreated.
  • Subject prefix/suffix, such as a container path or .pdf suffix.
  • Advanced filters on supported event properties and payload fields.

Avoid encoding consumer-specific routing rules into an event type. orders.created.v1 should remain a stable business fact; individual subscriptions decide whether they care. Creating separate topics for unrelated business domains can improve isolation, access control, lifecycle management, and blast-radius containment.


Delivery, Retry, and Dead-Lettering

Event Grid push delivery is at least once. A subscriber acknowledges delivery with a successful response; failures can result in retries, and a subscriber can receive duplicates. Event Grid does not guarantee delivery order.

For Event Grid Basic push subscriptions, the default retry policy is up to 30 delivery attempts over 24 hours, with exponential backoff. Both the maximum attempts and event time-to-live can be configured; delivery stops when the first configured limit is reached. The exact retry schedule is not a contract for business timing, so subscribers should remain available and recoverable without relying on a specific retry moment. Event Grid delivery and retry

Configure a Blob Storage dead-letter destination for events that cannot be delivered. Without dead-lettering, certain undeliverable events can be dropped after Event Grid exhausts its policy. A dead-letter container is not a substitute for monitoring: alert on new dead-letter blobs, inspect the error and delivery context, correct the underlying issue, and replay only through a controlled procedure.

Concern Practical design response
Duplicate delivery Make every handler idempotent using id plus a durable business/inbox record.
Out-of-order events Include version/sequence data when order matters; avoid logic that assumes arrival order.
Slow handler Return quickly; delegate lengthy work to Service Bus, Durable Functions, or another worker.
Permanent invalid event Validate schema and dead-letter with diagnostics; do not endlessly retry.
Handler outage Let Event Grid retry, monitor delivery failures, and scale/recover the handler.
Payload too large Publish a storage reference and access it with managed identity.

Security and Networking

Treat Event Grid as an integration boundary:

  1. Use Microsoft Entra ID and managed identities for service-to-service authentication where supported by the selected Event Grid feature and destination.
  2. Grant only publisher or subscriber roles that each workload needs. Keep application domains in separate topics, resource groups, or subscriptions when isolation matters.
  3. Validate webhook authentication and subscription-validation handshakes; do not accept arbitrary event posts merely because they resemble an Event Grid payload.
  4. Use private endpoints, firewall controls, and network design appropriate to the tier and destination. Test DNS and delivery paths, not merely resource deployment.
  5. Store the few unavoidable secrets in Key Vault and rotate them; never place credentials inside event payloads.
  6. Protect event data with least disclosure. Event subscriptions can fan out data quickly, so classify payloads before publishing.

Event Grid is a routing service, not an authorization decision engine for the business operation described by an event. Each handler must authorize its own downstream actions.


Observability and Operations

Use Azure Monitor metrics and diagnostic settings on Event Grid, and propagate correlation identifiers into application telemetry. At a minimum, monitor publish failures, delivery failures, retry counts, dead-letter activity, handler response codes, and end-to-end event age.

For custom events, make the CloudEvents id the primary cross-service diagnostic key. Log the event type, subject, source, correlation ID, subscription/consumer name, and outcome—without copying sensitive payloads into logs.

An operations runbook should answer:

  • Which subscription failed, and is the failure transient, configuration-related, or a consumer defect?
  • Are events accumulating in retry or dead-letter storage?
  • Does a dead-lettered event remain valid, and should it be replayed with the same event ID?
  • Will replay be safe because all consumers are idempotent?
  • Did the publisher reliably create the event, or is the problem before Event Grid? For state-changing business events, check the producer's transactional outbox.

Advantages and Disadvantages

Advantages

  • Decouples publishers from subscribers and supports natural fan-out.
  • Integrates deeply with Azure services and supports custom application events.
  • Provides filtering so consumers receive relevant events rather than every notification.
  • Scales as a managed service and supports push and, in Standard namespaces, pull consumption patterns.
  • Supports CloudEvents for portable, structured custom-event contracts.

Disadvantages and constraints

  • At-least-once, asynchronous delivery requires idempotent consumers.
  • Delivery order is not guaranteed.
  • Event Grid is not a replacement for a durable command queue, a workflow engine, or a retained telemetry stream.
  • Retry and dead-letter policies require explicit configuration and operational ownership.
  • The Basic and Standard namespace feature models differ; architecture and deployment choices must be made against the correct tier.
  • A producer still needs an outbox or equivalent reliability design when it changes local state and publishes a custom event.

Practical Design Checklist

Before approving an Event Grid design, confirm:

  • Is this an event (a fact) rather than a command or a stream?
  • Which Event Grid tier and topic type match the required delivery model and destination?
  • What is the stable event ID, versioned type, source, subject, and schema ownership?
  • Which subscriptions are needed today, and how will new subscribers be authorized and added later?
  • Are all handlers idempotent and safe with duplicates and out-of-order delivery?
  • Is the publisher using a transactional outbox when it changes business state and emits the event?
  • What are the retry and dead-letter settings, and who owns inspection and replay?
  • Does the subscriber need only a quick reaction, or should it enqueue durable work to Service Bus?
  • Which RBAC roles, managed identities, private endpoints, and data-classification controls apply?
  • Which metrics, traces, and alerts prove that an event reached its business outcome?

Interview-Ready Summary

Azure Event Grid is Azure's managed event-routing service for reacting to discrete facts such as a blob being created or an order being shipped. Publishers emit events to topics or Azure resource sources; event subscriptions filter and fan out delivery to handlers. It provides at-least-once, asynchronous delivery, so subscribers must be idempotent and must not assume ordering.

Choose Event Grid for reactive notification and fan-out. Choose Service Bus for durable commands and work queues, and Event Hubs for high-throughput event streams. For custom state-changing events, use a Transactional Outbox in the publisher, an inbox/idempotency strategy in consumers, dead-lettering and monitoring for delivery failures, and managed identity/RBAC for security.


Further Reading