Key rotation concepts in Azure - Time & Space Complexity
We want to understand how the time needed to rotate keys grows as we manage more keys in Azure.
How does the number of keys affect the work done during rotation?
Analyze the time complexity of rotating keys in Azure Key Vault.
// Pseudocode for rotating keys
var keys = keyVaultClient.ListKeys();
foreach (var key in keys) {
var newKey = keyVaultClient.CreateKey(key.Name + "-rotated");
keyVaultClient.DisableKey(key.Name);
}
This sequence lists all keys, creates a new rotated key for each, and disables the old key.
Look at what repeats as the number of keys grows.
- Primary operation: Creating a new key and disabling the old key for each existing key.
- How many times: Once per key in the vault.
Each key causes two main actions: create and disable.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 20 |
| 100 | 200 |
| 1000 | 2000 |
Pattern observation: The number of operations grows directly with the number of keys.
Time Complexity: O(n)
This means the time to rotate keys grows in a straight line as you add more keys.
[X] Wrong: "Rotating keys happens instantly no matter how many keys there are."
[OK] Correct: Each key requires separate actions, so more keys mean more work and time.
Understanding how key rotation scales helps you design secure systems that stay efficient as they grow.
"What if we rotated keys in batches instead of one by one? How would the time complexity change?"