Scaling and cost boundaries
Scaling adds or removes processing capacity. The safe replica count depends on downstream limits, measured traffic and cost, not only CPU utilization. A first connection upper bound is replicas multiplied by pool size plus reserved connections. Rolling deployments can temporarily run more replicas, so budget for surge. Estimate cost from explicit instance-hours, storage, requests, network transfer and other components. For steady conditions only, average concurrent work is approximately arrival rate times mean time in system. Do not substitute averages for tail latency or burst testing. Set alerts and hard resource bounds separately; budget alerts are not spending caps. Do not scale application replicas indefinitely when the database is the bottleneck, and never present hypothetical prices as current bills. Sources: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/.
Formal Syntax & Structure
Bound replica counts by database capacity (conceptual contract; see example)Working Example
import assert from 'node:assert/strict';function maxReplicas(limit,reserve,pool,surge){return Math.max(0,Math.floor((limit-reserve)/pool)-surge);}assert.equal(maxReplicas(100,20,8,1),9);console.log(maxReplicas(100,20,8,1));