CloudWatch Events (EventBridge) in AWS - Time & Space Complexity
We want to understand how the time to process events changes as the number of events grows in CloudWatch Events (EventBridge).
Specifically, how does the system handle more events and rules over time?
Analyze the time complexity of the following EventBridge rule processing.
aws events put-rule --name "MyRule" --event-pattern '{"source": ["aws.ec2"]}'
aws events put-targets --rule "MyRule" --targets '[{"Id":"1","Arn":"arn:aws:lambda:region:account:function:ProcessEvent"}]'
aws events put-events --entries '[{"Source":"aws.ec2","DetailType":"EC2 Instance State-change Notification","Detail":{"state":"running"}}]'
This sequence creates a rule, attaches a target, and sends an event to EventBridge.
Look at what repeats when many events and rules exist.
- Primary operation: Matching incoming events to rules.
- How many times: For each event, EventBridge checks all rules to find matches.
As the number of events or rules grows, EventBridge must check more rules for each event.
| Input Size (n rules) | Approx. Rule Checks per Event |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The number of rule checks grows directly with the number of rules.
Time Complexity: O(n)
This means the time to process each event grows linearly with the number of rules to check.
[X] Wrong: "EventBridge processes events instantly no matter how many rules exist."
[OK] Correct: Each event must be matched against all rules, so more rules mean more work and longer processing time.
Understanding how event routing scales helps you design systems that stay responsive as they grow.
"What if EventBridge used a filtering index to reduce rule checks? How would the time complexity change?"