0
0
Azurecloud~5 mins

Event Grid subscriptions and filters in Azure - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Event Grid subscriptions and filters
O(n)
Understanding Time Complexity

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.

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

As the number of subscriptions grows, each event must be checked against more filters.

Input Size (subscriptions)Approx. Filter Checks per Event
1010
100100
10001000

Pattern observation: The number of filter checks grows directly with the number of subscriptions.

Final Time Complexity

Time Complexity: O(n)

This means the work to filter events grows linearly with the number of subscriptions.

Common Mistake

[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.

Interview Connect

Understanding how filtering scales helps you design efficient event-driven systems and shows you can think about system behavior as it grows.

Self-Check

"What if filters were combined or shared among subscriptions? How would that change the time complexity?"