← All Exercises
Deadline Budget Propagation
basicjavascript
Background
Distributed systems propagate deadlines so a request that already missed its budget fails fast instead of queuing behind work whose result will be discarded anyway.
Problem
A pipeline starts with budgetMs of total deadline. Stages run in order, each consuming its costMs. Track the remaining budget entering each stage and at the end. Output the entering budget per stage, the final remaining budget (possibly negative), and whether the deadline was exceeded.
Input
A JSON object {"budgetMs": number, "stages": [{"name": string, "costMs": number}]}.Output
A JSON object {"stageBudgets": number[], "remainingMs": number, "exceeded": boolean}.Sample tests
Sample 1
Input: {"budgetMs":1000,"stages":[{"name":"auth","costMs":120},{"name":"db","costMs":300},{"name":"render","costMs":450}]}Expected: {"stageBudgets":[1000,880,580],"remainingMs":130,"exceeded":false}Sample 2
Input: {"budgetMs":500,"stages":[{"name":"fetch","costMs":300},{"name":"transform","costMs":250}]}Expected: {"stageBudgets":[500,200],"remainingMs":-50,"exceeded":true}Your solution
Learning objective
Model deadline propagation, per-stage budget visibility, and fail-fast budget checks.