Schedule a Multi-Step Inference Chain With Limited Parallelism
Last updated: November 29, 2026
Quick Overview
A pipeline of model steps is given as a dependency graph with a duration per step, and at most K steps can run at once. Compute a schedule that starts ready steps with the longest remaining critical path first, and return the makespan and each step's start time, rejecting graphs with cycles.
Baseten
November 29, 20260
0
0 solved
A pipeline of model steps is given as a dependency graph with a duration per step, and at most K steps can run at once. Compute a schedule that starts ready steps with the longest remaining critical path first, and return the makespan and each step's start time, rejecting graphs with cycles.
Baseten Chains lets customers compose steps such as transcription, diarization and summarization into one workflow where independent steps run concurrently. The interviewer checks topological processing, event-driven simulation and a sensible priority rule.
What the Interviewer Expects
- Builds in-degrees and children lists and detects cycles before scheduling
- Computes each step's bottom level (its duration plus the longest downstream path) with memoization
- Uses an event loop with a min-heap of finish times rather than ticking every second
- Releases all steps that finish at the same instant before starting new ones
- Explains why longest-path-first is a heuristic, since optimal scheduling with a cap is NP-hard
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
- Steps need different hardware (GPU vs CPU pools). How do you extend the model to multiple resource types?
- How would you stream partial results from one step into the next instead of waiting for completion?
- A step fails transiently 2% of the time. How do retries change the expected makespan?
- How would you cap fan-out when one step spawns one child per audio chunk?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: durations per step, deps mapping a step to the steps it waits on, and max_parallel. Output: makespan and start times. Raise on cycles. When a slot frees, pick the ready step whose remaini...
High-Level Design
Run Kahn's algorithm once to detect cycles. Compute bottom levels recursively with memoization. Then simulate: a ready max-heap keyed by bottom level, a running min-heap keyed by finish time. Fill fre...