0
0
AWScloud~5 mins

Stack drift detection in AWS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Stack drift detection
O(n)
Understanding Time Complexity

Stack drift detection checks if your cloud setup has changed outside your control.

We want to know how the time to detect drift grows as your stack gets bigger.

Scenario Under Consideration

Analyze the time complexity of the following operation sequence.


aws cloudformation detect-stack-drift --stack-name MyStack
aws cloudformation describe-stack-drift-detection-status --stack-drift-detection-id detectionId
aws cloudformation describe-stack-resource-drifts --stack-name MyStack
    

This sequence starts drift detection, checks its status, and then lists resource drifts in the stack.

Identify Repeating Operations

Identify the API calls, resource provisioning, data transfers that repeat.

  • Primary operation: Checking drift status and listing resource drifts for each resource in the stack.
  • How many times: Once to start detection, then once to list all resource drifts (not once per resource).
How Execution Grows With Input

As the number of resources in the stack grows, the number of drift checks grows too.

Input Size (n)Approx. Api Calls/Operations
10About 10 resource drift checks plus detection start and status calls
100About 100 resource drift checks plus detection start and status calls
1000About 1000 resource drift checks plus detection start and status calls

Pattern observation: The number of operations grows roughly in direct proportion to the number of resources.

Final Time Complexity

Time Complexity: O(n)

This means the time to detect drift grows linearly with the number of resources in your stack.

Common Mistake

[X] Wrong: "Drift detection time stays the same no matter how many resources are in the stack."

[OK] Correct: Each resource must be checked, so more resources mean more work and longer time.

Interview Connect

Understanding how drift detection scales helps you design stacks that stay manageable and predictable.

Self-Check

"What if drift detection only checked changed resources instead of all resources? How would the time complexity change?"