Service principals for applications in Azure - Time & Space Complexity
When creating service principals for applications, it's important to understand how the time to complete this task changes as you create more principals.
We want to know how the number of service principals affects the total time and operations needed.
Analyze the time complexity of the following operation sequence.
// Create multiple service principals for applications
for (let i = 0; i < n; i++) {
az ad sp create-for-rbac --name "app-sp-" + i
}
This sequence creates a service principal for each application by running the create command n times.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Creating a service principal via Azure AD API call.
- How many times: Exactly once per application, so n times.
Each new application requires one new service principal creation call, so the total operations grow directly with the number of applications.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The number of operations increases in a straight line as you add more applications.
Time Complexity: O(n)
This means the time and operations needed grow directly in proportion to the number of service principals you create.
[X] Wrong: "Creating multiple service principals happens all at once, so time stays the same no matter how many I create."
[OK] Correct: Each creation is a separate call and takes time, so more principals mean more total time.
Understanding how operations scale with input size shows you can plan and predict cloud tasks well, a useful skill in real projects and interviews.
"What if we created service principals in parallel instead of one after another? How would the time complexity change?"