Event Grid subscriptions and filters in Azure - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When using Event Grid subscriptions with filters, it's important to understand how the number of events and filters affects processing time.
We want to know how the system's work grows as more events and filters are involved.
Analyze the time complexity of filtering events for multiple subscriptions.
// Create multiple Event Grid subscriptions with filters
for (int i = 0; i < subscriptionCount; i++) {
var filter = new EventSubscriptionFilter() {
SubjectBeginsWith = $"device/{i}/",
IsSubjectCaseSensitive = false
};
await eventGridClient.EventSubscriptions.CreateOrUpdateAsync(
resourceGroupName,
topicName,
$"sub{i}",
new EventSubscription() { Filter = filter, Destination = destination }
);
}
// Events are published to the topic and filtered per subscription
This code creates many subscriptions, each with a filter that matches events starting with a specific prefix.
Look at what repeats as input grows:
- Primary operation: Filtering each incoming event against all subscription filters.
- How many times: For each event, the system checks all subscriptions' filters to decide delivery.
As the number of subscriptions grows, each event must be checked against more filters.
| Input Size (subscriptions) | Approx. Filter Checks per Event |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The number of filter checks grows directly with the number of subscriptions.
Time Complexity: O(n)
This means the work to filter events grows linearly with the number of subscriptions.
[X] Wrong: "Adding more subscriptions won't affect event processing time much."
[OK] Correct: Each event must be checked against every subscription's filter, so more subscriptions mean more checks and longer processing.
Understanding how filtering scales helps you design efficient event-driven systems and shows you can think about system behavior as it grows.
"What if filters were combined or shared among subscriptions? How would that change the time complexity?"
Practice
Solution
Step 1: Understand Event Grid subscriptions
Subscriptions let you receive events from Azure services.Step 2: Role of filters in subscriptions
Filters help select only the events you want, based on event type or subject.Final Answer:
To receive only specific events based on criteria like event type or subject -> Option AQuick Check:
Filters select events = B [OK]
- Thinking filters increase event volume
- Believing filters block all events
- Assuming filters modify event data
Solution
Step 1: Identify subject prefix filter syntax
The correct property to filter by subject prefix is "subjectBeginsWith".Step 2: Match the correct JSON snippet
"filter": { "subjectBeginsWith": "/blobServices/default/containers/images" } uses "subjectBeginsWith" with the correct path prefix.Final Answer:
"filter": { "subjectBeginsWith": "/blobServices/default/containers/images" } -> Option AQuick Check:
Prefix filter uses subjectBeginsWith = A [OK]
- Confusing subjectEndsWith with subjectBeginsWith
- Using eventType instead of subject filter
- Using subjectContains which is not valid
{ "subjectBeginsWith": "/devices/", "subjectEndsWith": "/temperature" }Which event subject will be delivered to the subscriber?
Solution
Step 1: Understand filter conditions
The event subject must start with "/devices/" and end with "/temperature".Step 2: Check each option
/devices/device123/temperature matches both start and end. Others fail one condition.Final Answer:
/devices/device123/temperature -> Option CQuick Check:
Subject starts with /devices/ and ends with /temperature = A [OK]
- Ignoring subjectEndsWith condition
- Confusing similar paths
- Assuming partial matches are enough
{ "subjectBeginsWith": "/orders/", "subjectEndsWith": "/completed" }But no events are received even though events exist. What is the likely issue?
Solution
Step 1: Check filter syntax and support
The JSON syntax is valid and Event Grid supports subject filters.Step 2: Consider case sensitivity and subscription status
Subject filters are case-sensitive; if event subjects differ in case, no match occurs. Subscription being disabled would stop all events, but question implies filter issue.Final Answer:
The subject filter is case-sensitive and event subjects differ in case -> Option DQuick Check:
Subject filters are case-sensitive = D [OK]
- Assuming filters ignore case
- Blaming JSON syntax without checking
- Ignoring subscription status
Microsoft.Storage.BlobCreated where the blob is in the container named images. Which filter configuration achieves this?Solution
Step 1: Filter by event type
The event type must be exactly "Microsoft.Storage.BlobCreated" to get blob creation events.Step 2: Filter by subject prefix for container
The subject prefix for blobs in the "images" container is "/blobServices/default/containers/images/".Step 3: Combine filters correctly
{ "eventType": "Microsoft.Storage.BlobCreated", "subjectBeginsWith": "/blobServices/default/containers/images/" } combines both eventType and subjectBeginsWith correctly.Final Answer:
{ "eventType": "Microsoft.Storage.BlobCreated", "subjectBeginsWith": "/blobServices/default/containers/images/" } -> Option BQuick Check:
Event type and subject prefix filter combined = C [OK]
- Using wrong event type
- Using subjectEndsWith instead of subjectBeginsWith
- Omitting container path in subject filter
