AZ-204Chapter 99 of 102Objective 5.3

Event Grid CloudEvents Schema

This chapter covers the CloudEvents schema for Azure Event Grid, a critical topic for the AZ-204 exam under objective 5.3 (Integrate with Event Grid). CloudEvents is a CNCF specification that standardizes event data across cloud services, and Azure Event Grid supports it as an alternative to its native schema. Expect approximately 5-10% of exam questions to touch on Event Grid schemas, including CloudEvents. Understanding the differences between the Event Grid schema and CloudEvents schema, when to use each, and how to configure them is essential.

25 min read
Intermediate
Updated May 31, 2026

CloudEvents is a Universal Envelope

Imagine a global postal system where every letter must be in a standard envelope (CloudEvents). Without this standard, each country (event producer) uses its own envelope shape, size, and addressing format. A sender in the US might use a #10 envelope with a return address on the top left, while a sender in Japan uses a vertical envelope with the address written in a specific order. The recipient (event consumer) must understand every envelope format to read the letter. This is like each Azure service (Blob Storage, Event Hubs, Logic Apps) having its own event format. CloudEvents defines a universal envelope: a fixed set of fields (like 'source', 'type', 'id', 'specversion') that every event must include, plus an optional 'data' field for the payload. The envelope's design is extensible through extension contexts (like 'subject', 'datacontenttype'). When a producer creates an event, it fills in the universal envelope; the consumer only ever needs to parse this standard envelope, regardless of the producer. The envelope also includes a 'specversion' (currently 1.0) so both sides know which version of the standard is in use. This eliminates the need for custom adapters for every pair of services.

How It Actually Works

What is CloudEvents and Why Does It Exist?

CloudEvents is a specification for describing event data in a common way, hosted by the Cloud Native Computing Foundation (CNCF). It aims to provide interoperability across services, platforms, and cloud providers. Before CloudEvents, every event producer defined its own event format. For example, Azure Blob Storage events had a different structure than Azure Event Hubs events, and AWS S3 events were different again. This forced event consumers to write custom logic for each producer. CloudEvents defines a set of required and optional attributes that every event should include, along with an extensibility model. The current stable version is 1.0.

Azure Event Grid natively supports both its own Event Grid schema and the CloudEvents schema. When you create an Event Grid topic or domain, you choose the input schema (the format events are published in) and the output schema (the format delivered to subscribers). The default is the Event Grid schema. CloudEvents schema is an option.

How CloudEvents Works Internally

CloudEvents uses a set of context attributes to describe the event. The required attributes are:

id: A unique identifier for the event (e.g., a UUID).

source: Identifies the context in which an event happened (e.g., a URI like /subscriptions/{sub-id}/resourceGroups/{rg}/providers/Microsoft.Storage/storageAccounts/{account}).

specversion: The version of the CloudEvents specification (e.g., 1.0).

type: Describes the type of event (e.g., Microsoft.Storage.BlobCreated).

Optional attributes include:

datacontenttype: Content type of the data value (e.g., application/json).

dataschema: URI of the schema that the data adheres to.

subject: A subject of the event (e.g., the blob name).

time: Timestamp of when the event occurred.

data: The event payload. This is an optional attribute, but most events include it.

When an event is published to an Event Grid topic configured for CloudEvents input schema, the publisher must format the event as a CloudEvent. The event is then stored internally in the CloudEvents format. When delivered to a subscriber, the event can be delivered as-is (if the output schema is also CloudEvents) or transformed to the Event Grid schema (if output schema is Event Grid schema).

Key Components, Values, Defaults, and Timers

Input Schema: Determines the format of events that can be published to the topic. Options: EventGridSchema (default), CloudEventSchemaV1_0, CustomEventSchema.

Output Schema: Determines the format of events delivered to subscribers. Options: EventGridSchema (default), CloudEventSchemaV1_0. When input is CloudEvents and output is Event Grid schema, the system automatically converts.

Event Time-to-Live (TTL): Default is 1440 minutes (24 hours), configurable from 1 to 1440 minutes. Events expire after TTL and are not delivered.

Retry Policy: Event Grid retries delivery up to 30 times (default) with exponential backoff. The maximum retry interval is 30 minutes.

Event Size: Maximum event size is 1 MB for both schemas.

CloudEvents Attributes: All attributes are case-sensitive. The specversion must be exactly 1.0.

Configuration and Verification Commands

To create an Event Grid topic that accepts CloudEvents schema, use Azure CLI:

az eventgrid topic create \
  --name mytopic \
  --resource-group myrg \
  --location eastus \
  --input-schema cloudeventschemav1_0

To verify the input schema of an existing topic:

az eventgrid topic show \
  --name mytopic \
  --resource-group myrg \
  --query inputSchema

When publishing a CloudEvent, the HTTP request must include the Content-Type header set to application/cloudevents+json and the body must be a JSON object conforming to the CloudEvents spec. Example:

{
    "specversion": "1.0",
    "type": "Microsoft.Storage.BlobCreated",
    "source": "/subscriptions/{sub-id}/resourceGroups/{rg}/providers/Microsoft.Storage/storageAccounts/{account}",
    "id": "9aeb0fdf-c01e-0131-0922-9eb54906e209",
    "time": "2023-11-01T12:00:00Z",
    "subject": "blobServices/default/containers/mycontainer/blobs/myblob.txt",
    "datacontenttype": "application/json",
    "data": {
        "api": "PutBlob",
        "clientRequestId": "some-id",
        "requestId": "some-request-id",
        "eTag": "0x8D...",
        "contentType": "text/plain",
        "contentLength": 100,
        "blobType": "BlockBlob",
        "url": "https://myaccount.blob.core.windows.net/mycontainer/myblob.txt",
        "sequencer": "00000000000000000000000000000000000",
        "storageDiagnostics": {}
    }
}

How CloudEvents Interacts with Related Technologies

Event Grid Domains: Domains also support CloudEvents input schema. You can specify the input schema at the domain level and optionally override for individual topics within the domain.

Event Hubs: Event Hubs can be used as an event source for Event Grid. When using CloudEvents, the Event Hubs namespace publishes events in the CloudEvents format.

Logic Apps: Logic Apps can consume CloudEvents via the Event Grid connector. They can parse the standard attributes.

Azure Functions: Functions can be triggered by Event Grid using CloudEvents. The function receives the event as a CloudEvent object.

Third-party systems: Because CloudEvents is an open standard, any system that understands CloudEvents can publish or subscribe to Azure Event Grid topics configured for CloudEvents.

Important Exam Considerations

The exam may ask you to choose the correct schema for a scenario that requires interoperability with non-Azure systems. CloudEvents is the answer.

Be aware that CloudEvents schema uses source instead of topic (Event Grid schema uses topic).

The specversion attribute must be present and set to 1.0.

The datacontenttype is optional but recommended; if omitted, the data is assumed to be JSON.

CloudEvents does not support batching by default; each event is a single JSON object. However, Event Grid can deliver multiple CloudEvents in a batch if the subscriber supports it (via the application/cloudevents-batch+json content type).

When converting from CloudEvents to Event Grid schema, the source and subject are combined to form the subject in Event Grid schema, and type is mapped directly.

Trap Patterns on the Exam

Trap: Confusing source with topic. In Event Grid schema, topic is the resource path. In CloudEvents, source is similar but not identical. The exam may present a scenario where a developer incorrectly uses topic in a CloudEvent.

Trap: Forgetting the specversion attribute. A CloudEvent without specversion is invalid. The exam might show a JSON missing specversion and ask if it's valid.

Trap: Assuming CloudEvents is only for Azure. CloudEvents is a CNCF standard, not Azure-specific. The exam may test that CloudEvents enables multi-cloud event routing.

Trap: Mixing up input and output schemas. You can have different schemas for input and output. The exam might ask about the effect of setting input schema to CloudEvents and output to Event Grid schema.

Summary of Key Differences

| Attribute | Event Grid Schema | CloudEvents Schema | |-----------|-------------------|-------------------| | Event format | Proprietary JSON | Standardized JSON | | Required attributes | id, eventType, subject, eventTime, data, dataVersion, metadataVersion, topic | id, source, specversion, type | | Interoperability | Azure-only | Multi-cloud, multi-platform | | Extensibility | Limited | Extension contexts | | Batching | Supported natively | Supported via batch content type |

Walk-Through

1

Choose the Schema for Your Topic

When creating an Event Grid topic, you decide the input schema. For CloudEvents, set `--input-schema cloudeventschemav1_0`. This determines the format that publishers must use. If you need to accept events from non-Azure systems or want to standardize across cloud providers, choose CloudEvents. The default is Event Grid schema. The choice is made at creation and cannot be changed later without recreating the topic. The output schema can be set independently, but the default is Event Grid schema. You can change output schema after creation.

2

Publish a CloudEvent to the Topic

Publishers send HTTP POST requests to the topic endpoint with `Content-Type: application/cloudevents+json`. The body must be a valid CloudEvent JSON object containing at least the required attributes: `id`, `source`, `specversion`, and `type`. The `source` attribute is a URI identifying the context (e.g., a resource path). The `id` must be unique per source. The `specversion` must be `1.0`. The `type` describes the event. Optional attributes like `data`, `time`, `subject`, `datacontenttype` can be included. The maximum event size is 1 MB. The publisher must authenticate using a SAS key or managed identity.

3

Event Grid Validates the CloudEvent

Upon receiving the event, Event Grid validates that it conforms to the CloudEvents schema. It checks for required attributes and their types. The `specversion` must be `1.0`; if not, the event is rejected. The `source` must be a valid URI. The `id` must be a non-empty string. If validation fails, the publisher receives a 400 Bad Request. If valid, the event is stored in the topic's internal queue. The TTL starts counting down from the event's `time` (or current time if `time` is absent). The event is then available for delivery to subscribers.

4

Deliver the Event to Subscribers

Event Grid delivers the event to all matching subscriptions. The delivery format depends on the output schema of the topic. If output schema is CloudEvents, the event is sent as-is with `Content-Type: application/cloudevents+json`. If output schema is Event Grid schema, Event Grid transforms the CloudEvent to its native format. The transformation maps `source`+`subject` to `subject`, `type` to `eventType`, `id` to `id`, `time` to `eventTime`, and `data` to `data`. The `topic` attribute is added with the topic's resource path. The subscriber receives the event via webhook, Event Hubs, Queue Storage, or other supported endpoints.

5

Handle Delivery Failures and Retries

If delivery fails (e.g., subscriber returns non-2xx status), Event Grid retries based on the retry policy. By default, it retries up to 30 times with exponential backoff (minimum 10 seconds, maximum 30 minutes). After exhausting retries, the event is either dead-lettered (if configured) or dropped. If the subscriber uses webhook, it must acknowledge the event within 60 seconds by returning 200 OK; otherwise, it's considered a failure. For CloudEvents, the subscriber should expect the CloudEvents format and parse accordingly. The subscriber can also filter events based on CloudEvents attributes like `type` or `source`.

6

Monitor and Troubleshoot

Use Azure Monitor to track metrics like `PublishFailCount`, `DeliverySuccessCount`, `DeadLetteredCount`. For CloudEvents-specific issues, check the `MatchingSchema` metric. Common errors include invalid CloudEvents format (e.g., missing `specversion`), authentication failures, and delivery timeouts. Enable diagnostic logs for the topic to capture publish and delivery events. Use the Event Grid Viewer tool in the portal to inspect recent events. For advanced troubleshooting, use Azure CLI: `az eventgrid topic show --name mytopic --resource-group myrg` to verify schema settings.

What This Looks Like on the Job

Enterprise Scenario 1: Multi-Cloud Event Aggregation

A large enterprise uses Azure for most services but also runs workloads on AWS and GCP. They want to aggregate events from all clouds into a central Azure Event Grid topic for processing. Using CloudEvents schema, each cloud's event producer (e.g., AWS S3, GCP Cloud Storage) publishes events in the standard CloudEvents format. This eliminates the need for custom adapters. The topic is configured with input schema CloudEventSchemaV1_0. The events are then delivered to an Azure Function that normalizes and routes them. In production, they set TTL to 60 minutes to reduce storage costs. They also enable dead-lettering to a Storage Queue for failed deliveries. A common issue is that some third-party libraries produce CloudEvents with incorrect specversion (e.g., 0.3), causing validation failures. They mitigate this by implementing a custom validation layer before publishing.

Enterprise Scenario 2: IoT Device Event Standardization

A manufacturing company uses Azure IoT Hub to collect telemetry from thousands of devices. They want to publish device lifecycle events (device created, device deleted) to Event Grid for downstream processing. By using CloudEvents schema, they ensure that the event format is consistent with other event sources in the enterprise. They create an Event Grid topic with CloudEvents input schema. IoT Hub's built-in Event Grid integration (for device lifecycle events) supports CloudEvents automatically. The events are then consumed by Logic Apps and third-party analytics tools. In production, they handle high throughput (10,000 events/second) by using Event Grid's batching capability: they set the output schema to CloudEvents and deliver batches of up to 10 events using application/cloudevents-batch+json. A common misconfiguration is forgetting to set the output schema to CloudEvents, causing the Logic Apps to receive Event Grid schema (which they don't parse correctly). They also set up alerts on PublishFailCount to detect schema validation errors.

Enterprise Scenario 3: SaaS Integration with Custom Events

A SaaS provider offers a service that runs on Azure and wants to allow customers to subscribe to custom events. They choose CloudEvents to ensure customers can use any cloud or on-premises listener. They create an Event Grid domain with CloudEvents input schema. Customers publish events using the CloudEvents format via the domain's topic endpoints. The domain routes events to customer-specific topics. The SaaS provider uses the source attribute to identify the customer's resource. In production, they enforce a maximum event size of 64 KB to keep latency low. They also use extension contexts like traceparent for distributed tracing. A common problem is that customers include non-standard attributes that are not in the CloudEvents specification; the SaaS provider must ignore them or reject the event. They provide a validation endpoint that customers can test against. The domain's output schema is set to CloudEvents to preserve the format for subscribers.

How AZ-204 Actually Tests This

Exactly What AZ-204 Tests on This Topic

Objective 5.3: Integrate with Event Grid. The exam tests your ability to:

Choose the appropriate event schema (Event Grid vs. CloudEvents) based on requirements.

Configure input and output schemas for topics and domains.

Publish and consume CloudEvents correctly.

Understand the differences in attribute names and structures.

Specific sub-objectives: - 5.3.1: Create an Event Grid topic and subscription. - 5.3.2: Publish events to Event Grid. - 5.3.3: Subscribe to events. - 5.3.4: Handle events.

Common Wrong Answers and Why Candidates Choose Them

1.

Wrong: "CloudEvents schema is required for Azure services." Reality: Azure services can use either schema; the default is Event Grid schema. Candidates confuse CloudEvents as mandatory because it's a standard, but Azure supports both.

2.

Wrong: "CloudEvents uses topic attribute." Reality: CloudEvents uses source; Event Grid schema uses topic. Candidates mix up the two.

3.

Wrong: "You cannot convert between schemas." Reality: Event Grid automatically converts from CloudEvents to Event Grid schema and vice versa when input and output schemas differ.

4.

Wrong: "CloudEvents supports batching by default." Reality: CloudEvents does not define batching, but Event Grid supports batching via application/cloudevents-batch+json. Candidates think batching is inherent.

Specific Numbers, Values, and Terms That Appear Verbatim

specversion must be 1.0.

Content-Type for a single CloudEvent: application/cloudevents+json.

Content-Type for a batch of CloudEvents: application/cloudevents-batch+json.

Maximum event size: 1 MB.

Default TTL: 1440 minutes.

Default retry count: 30.

Required attributes: id, source, specversion, type.

Edge Cases and Exceptions the Exam Loves to Test

Edge case: If you set input schema to CloudEvents but publish an Event Grid schema event, the topic rejects it (400 Bad Request).

Edge case: If you set output schema to CloudEvents but the subscriber expects Event Grid schema, the subscriber may fail to parse. The exam may present a scenario where a developer configures output schema incorrectly.

Exception: When using CloudEvents, the subject attribute is optional but often used. If omitted, the subject in the delivered Event Grid schema (if converted) will be empty.

Exception: The datacontenttype attribute is optional; if missing, the data is assumed to be JSON. The exam may test that you can omit it for JSON payloads.

How to Eliminate Wrong Answers Using the Underlying Mechanism

Understand that CloudEvents is a standard for interoperability. If the scenario involves multiple clouds or non-Azure systems, CloudEvents is likely the answer. If it's purely Azure, Event Grid schema is fine.

Remember the attribute mapping: source (CloudEvents) vs topic (Event Grid). If a question asks about the source attribute, it's CloudEvents.

Know that input schema is set at topic creation and cannot be changed. Output schema can be changed anytime.

When a question describes a failure to publish, check if the event format matches the input schema. If the event is missing specversion, it will fail for CloudEvents.

For delivery failures, check if the output schema matches the subscriber's expectation. If the subscriber expects Event Grid schema but the output is CloudEvents, the subscriber might not parse correctly.

Key Takeaways

CloudEvents is a CNCF standard for event interoperability; Azure Event Grid supports it as an alternative schema.

The required CloudEvents attributes are `id`, `source`, `specversion`, and `type`.

The `specversion` must be exactly `1.0`.

Input schema is set at topic creation and cannot be changed; output schema can be changed anytime.

Maximum event size is 1 MB for both schemas.

Default TTL is 1440 minutes (24 hours); configurable from 1 to 1440 minutes.

Default retry count is 30 with exponential backoff (10s to 30min).

Use `application/cloudevents+json` for single CloudEvent and `application/cloudevents-batch+json` for batch.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Event Grid Schema

Proprietary to Azure; only Azure services understand it natively.

Uses attributes like `eventType`, `subject`, `topic`, `eventTime`, `dataVersion`.

Default schema for Azure Event Grid.

Supports batching natively with `application/json` content type.

Simpler for Azure-only scenarios; no need for `specversion`.

CloudEvents Schema

Open standard (CNCF); interoperable across clouds and platforms.

Uses attributes like `type`, `source`, `specversion`, `id`, `time`.

Must be explicitly configured when creating a topic or domain.

Batching is supported via `application/cloudevents-batch+json` content type.

Required `specversion` attribute ensures version compatibility.

Watch Out for These

Mistake

CloudEvents is an Azure-specific standard.

Correct

CloudEvents is a CNCF specification, not Azure-specific. It is designed for interoperability across cloud providers and platforms. Azure Event Grid supports it, but it is not exclusive to Azure.

Mistake

CloudEvents requires the `data` attribute to be present.

Correct

The `data` attribute is optional in CloudEvents. An event can consist only of context attributes without a payload. However, most events include `data`.

Mistake

You cannot use CloudEvents with Event Grid domains.

Correct

Event Grid domains support CloudEvents schema for both input and output. You can set the input schema at the domain level, and individual topics within the domain can optionally override it.

Mistake

CloudEvents schema and Event Grid schema are identical.

Correct

They have different attribute names and structures. For example, CloudEvents uses `source` and `type`, while Event Grid uses `topic` and `eventType`. The required attributes differ.

Mistake

Once you set the input schema to CloudEvents, you cannot change it.

Correct

You cannot change the input schema after topic creation. However, you can change the output schema at any time. If you need a different input schema, you must create a new topic.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is the difference between Event Grid schema and CloudEvents schema?

Event Grid schema is Azure's proprietary format with attributes like `eventType`, `subject`, `topic`, and `eventTime`. CloudEvents schema is an open standard by CNCF with attributes like `type`, `source`, `specversion`, and `id`. CloudEvents is designed for interoperability across cloud providers, while Event Grid schema is simpler for Azure-only scenarios. Both are supported by Azure Event Grid.

Can I change the input schema of an existing Event Grid topic?

No, the input schema is set when the topic is created and cannot be changed later. If you need a different input schema, you must create a new topic. However, the output schema can be changed at any time.

What happens if I publish an Event Grid schema event to a topic configured for CloudEvents?

The topic will reject the event with a 400 Bad Request because the event does not conform to the CloudEvents schema. The input schema strictly enforces the format.

Does CloudEvents support event batching?

CloudEvents itself does not define a batching mechanism, but Event Grid supports delivering multiple CloudEvents in a batch using the `application/cloudevents-batch+json` content type. The batch is a JSON array of CloudEvents objects.

What is the `specversion` attribute and why is it important?

`specversion` indicates the version of the CloudEvents specification that the event conforms to. It must be set to `1.0` for the current version. It ensures that consumers can correctly interpret the event structure. Missing or incorrect `specversion` causes validation failure.

Can I use CloudEvents with Event Grid domains?

Yes, Event Grid domains support CloudEvents schema. You can set the input schema at the domain level, and individual topics within the domain can optionally override it. The output schema can also be set to CloudEvents.

How do I subscribe to CloudEvents using an Azure Function?

When you create an Event Grid trigger for an Azure Function, the function receives the event as a CloudEvent object if the output schema of the topic is CloudEvents. The function can then access attributes like `data`, `type`, `source` directly. Ensure the function's `host.json` has the correct binding.

Terms Worth Knowing

Ready to put this to the test?

You've just covered Event Grid CloudEvents Schema — now see how well it sticks with free AZ-204 practice questions. Full explanations included, no account needed.

Done with this chapter?