Event Grid for event routing in Azure - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
We want to understand how the time to route events grows as more events are sent through Azure Event Grid.
Specifically, how does the number of events affect the work Event Grid does to deliver them?
Analyze the time complexity of the following event routing sequence.
// Create Event Grid topic
az eventgrid topic create --name mytopic --resource-group mygroup --location eastus
// Send multiple events to the topic
az eventgrid event publish --topic-name mytopic --resource-group mygroup --events '[{"id":"1","eventType":"recordCreated","subject":"/records/1","data":{"value":100},"eventTime":"2024-01-01T00:00:00Z","dataVersion":"1.0"}]'
// Event Grid routes events to subscribers
// Subscribers receive events asynchronously
This sequence creates a topic, sends events, and Event Grid routes them to subscribers.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Sending each event to the Event Grid topic.
- How many times: Once per event sent by the user or system.
- Routing operation: Event Grid delivers each event to all matching subscribers.
- How many times: Once per event per subscriber.
As the number of events increases, the number of send operations grows directly with it.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 sends, 10 routing deliveries per subscriber |
| 100 | 100 sends, 100 routing deliveries per subscriber |
| 1000 | 1000 sends, 1000 routing deliveries per subscriber |
Pattern observation: The work grows linearly with the number of events sent.
Time Complexity: O(n)
This means the time to route events grows directly in proportion to the number of events sent.
[X] Wrong: "Event Grid routes all events instantly regardless of how many are sent."
[OK] Correct: Each event must be processed and delivered, so more events mean more work and time.
Understanding how event routing scales helps you design systems that handle growth smoothly and avoid surprises.
"What if we added more subscribers to the Event Grid topic? How would the time complexity change?"
Practice
Solution
Step 1: Understand Event Grid's role
Event Grid is designed to route events from sources to handlers automatically, enabling reactive applications.Step 2: Compare with other services
Other options describe different Azure services: storage, compute, and identity management, not event routing.Final Answer:
To route events from sources to event handlers automatically -> Option AQuick Check:
Event routing = To route events from sources to event handlers automatically [OK]
- Confusing Event Grid with storage services
- Thinking Event Grid manages virtual machines
- Mixing Event Grid with identity services
mySub for a topic myTopic?Solution
Step 1: Identify correct CLI syntax for event subscription
The command requires the full resource ID for the source topic using --source-resource-id.Step 2: Evaluate options
az eventgrid event-subscription create --name mySub --source-resource-id /subscriptions/.../resourceGroups/.../providers/Microsoft.EventGrid/topics/myTopic uses the full resource ID format, which is required. az eventgrid event-subscription create --name mySub --source-resource-id myTopic lacks full resource ID, C creates a topic not subscription, D uses wrong command.Final Answer:
az eventgrid event-subscription create --name mySub --source-resource-id /subscriptions/.../resourceGroups/.../providers/Microsoft.EventGrid/topics/myTopic -> Option DQuick Check:
Full resource ID needed for subscription creation [OK]
- Using topic creation command instead of subscription
- Omitting full resource ID in source
- Using incorrect command names
{
"destination": {
"endpointType": "WebHook",
"properties": {
"endpointUrl": "https://myapp.com/api/events"
}
},
"filter": {
"subjectBeginsWith": "orders/",
"subjectEndsWith": ".json"
}
}
Which events will be delivered to the webhook endpoint?Solution
Step 1: Understand subject filters in Event Grid
The filter uses subjectBeginsWith and subjectEndsWith to select events whose subject starts with 'orders/' and ends with '.json'.Step 2: Analyze options
All events with subjects starting with 'orders/' and ending with '.json' matches the filter exactly. Only events with subjects exactly 'orders/.json' is too strict (exact match), C ignores filters, D is incorrect because 'contains' is not used.Final Answer:
All events with subjects starting with 'orders/' and ending with '.json' -> Option CQuick Check:
Subject filters = startsWith + endsWith [OK]
- Assuming exact subject match required
- Ignoring subject filters and expecting all events
- Confusing contains with beginsWith or endsWith
Solution
Step 1: Check webhook endpoint accessibility
If the webhook URL is wrong or the endpoint is down, events cannot be delivered.Step 2: Evaluate other options
Topic existence is important but usually checked at creation; storage account is unrelated; a filter matching all events would not block delivery.Final Answer:
The webhook endpoint URL is incorrect or unreachable -> Option BQuick Check:
Endpoint must be reachable for event delivery [OK]
- Assuming storage account is needed for Event Grid
- Ignoring endpoint network issues
- Thinking filters block all events by default
Solution
Step 1: Understand Event Grid subscription scope
Event Grid subscriptions are scoped to a single resource, so each storage account needs its own subscription.Step 2: Evaluate options
Create an Event Grid subscription for each storage account, all pointing to the same Azure Function endpoint correctly creates multiple subscriptions pointing to one function. Create one Event Grid subscription on one storage account and expect it to receive events from all accounts is invalid because one subscription cannot cover multiple accounts. Use Azure Logic Apps to poll each storage account and forward events to the function adds unnecessary polling. Configure the Azure Function to listen directly to all storage accounts without Event Grid is not supported as functions rely on Event Grid for event routing.Final Answer:
Create an Event Grid subscription for each storage account, all pointing to the same Azure Function endpoint -> Option AQuick Check:
One subscription per source resource [OK]
- Assuming one subscription covers multiple sources
- Using polling instead of event-driven routing
- Expecting Azure Function to listen without Event Grid
