Simulate Concurrency-Based Autoscaling With a Scale-Down Delay

Last updated: November 29, 2026

Quick Overview

Given per-second samples of in-flight requests for a model deployment, a target concurrency per replica, min and max replicas, and a scale-down delay, return the replica count the autoscaler would hold at each sample. Scale up immediately, but only scale down once the lower demand has lasted for the full delay.

Baseten
Coding & Algorithms
Software Engineer
Baseten
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given per-second samples of in-flight requests for a model deployment, a target concurrency per replica, min and max replicas, and a scale-down delay, return the replica count the autoscaler would hold at each sample. Scale up immediately, but only scale down once the lower demand has lasted for the full delay.

Baseten deployments autoscale on concurrency with settings such as concurrency target, min and max replicas and scale-down delay, and the delay exists because a GPU cold start is expensive. This question checks whether you can turn that policy into exact, efficient code and reason about the sliding window behind it.

What the Interviewer Expects
  • Computes desired replicas as ceil(in_flight / target) clamped to [min, max]
  • Scales up on the same sample that demand rises
  • Scales down only to the highest desired value seen within the trailing delay window
  • Uses a monotonic deque for an O(n) sliding-window maximum instead of rescanning the window
  • Handles min replicas of zero (scale to zero) correctly
Key Topics to Cover
autoscaling
sliding window maximum
monotonic deque
hysteresis
scale to zero
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you add a cap on how many replicas can be added per minute?
  • Replicas take 60 seconds to become ready. How does that change what the autoscaler should count as current capacity?
  • How would you smooth noisy samples without making scale-up sluggish?
  • How does a scheduled minimum (for predictable morning traffic) fit into this loop?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Inputs: sorted samples (t, in_flight), target, min_r, max_r, scale_down_delay in seconds. Output: replica count after each sample. Start at min_r. Scaling up is immediate; scaling down pic...

High-Level Design

The scale-down rule is a sliding-window maximum over desired counts. Keep a deque of (t, desired) with strictly decreasing desired values: pop smaller values from the back when a new sample arrives ...


Submit Your Answer
Markdown supported

Related Questions