Eventarc for event routing in GCP - Time & Space Complexity
When using Eventarc to route events, it is important to understand how the number of events affects processing time.
We want to know how the system handles more events and how the routing time changes.
Analyze the time complexity of the following event routing setup.
// Create an Eventarc trigger
const trigger = eventarc.triggers.create({
name: 'my-trigger',
eventFilters: [{ attribute: 'type', value: 'google.cloud.storage.object.v1.finalized' }],
destination: { cloudRunService: 'my-service', region: 'us-central1' }
});
// Events arrive and are routed to the destination
// Each event is processed individually
This setup routes storage object finalized events to a Cloud Run service.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Routing each incoming event to the destination service.
- How many times: Once per event received.
As the number of events increases, the routing operation happens for each event separately.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 routing operations |
| 100 | 100 routing operations |
| 1000 | 1000 routing operations |
Pattern observation: The number of routing operations grows directly with the number of events.
Time Complexity: O(n)
This means the time to route events grows linearly with the number of events.
[X] Wrong: "Routing multiple events happens all at once, so time stays the same no matter how many events arrive."
[OK] Correct: Each event is routed individually, so more events mean more routing operations and more time.
Understanding how event routing scales helps you design systems that handle growing workloads smoothly.
"What if we batch events before routing? How would the time complexity change?"