Minimum Deployment Waves to Roll Out Dependent Microservices
Last updated: November 29, 2026
Quick Overview
You must roll out n microservices where some depend on others being live first; in each wave you may deploy any number of services whose dependencies are already live. Return the minimum number of waves, or -1 if the dependencies form a cycle.
Amazon
November 29, 20260
0
0 solved
You must roll out n microservices where some depend on others being live first; in each wave you may deploy any number of services whose dependencies are already live. Return the minimum number of waves, or -1 if the dependencies form a cycle.
Amazon teams ship through staged pipelines, and this question frames topological sort as rollout planning. The interviewer looks for level-by-level Kahn's algorithm, a clean cycle check, and an explanation of why the number of BFS levels equals the longest dependency chain.
What the Interviewer Expects
- Model services as nodes and dependencies as directed edges
- Use Kahn's algorithm processing one full frontier per wave
- Detect cycles by counting processed nodes
- Explain why wave count equals the longest path length in nodes
- O(n + m) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if each wave can deploy at most k services?
- How do you output the actual services in each wave?
- How would you handle a service that fails in wave 2 and must roll back its dependents?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
n services labeled 0..n-1 and pairs (u, v) meaning u must be live before v. Unlimited parallelism within a wave. Return the fewest waves, or -1 when no order exists. Services with no dependencies go...
High-Level Design
Kahn's algorithm naturally peels the DAG in layers. Start with every zero in-degree service: that is wave 1. Deploying them lowers in-degrees; anything reaching zero becomes eligible for the next wave...