← All Exercises

Size Replicas for Peak Traffic with Headroom

basicjavascript~20min

Background

Capacity reviews fail when headroom is expressed as a percentage but forgotten in the arithmetic. Making the formula explicit keeps the plan reproducible.

Problem

Given current throughput, a peak multiplier, per-replica throughput and a headroom target, compute peak load and the number of replicas needed.

Input

JSON object: { currentRps, peakMultiplier, perInstanceRps, headroomPercent }

Output

JSON object: { peakRps, instances }

Sample tests

Sample 1

Input: {"currentRps":200,"peakMultiplier":3,"perInstanceRps":100,"headroomPercent":20}
Expected: {"peakRps":600,"instances":8}

Sample 2

Input: {"currentRps":50,"peakMultiplier":2,"perInstanceRps":100,"headroomPercent":0}
Expected: {"peakRps":100,"instances":1}

Your solution

Learning objective

Size a fleet from explicit inputs instead of intuition.