
Table of Contents
By Khimananda Oli | Last reviewed: August 2026
To successfully autoscale a Deno service on Kubernetes, you must combine accurate resource requests with the Horizontal Pod Autoscaler (HPA) and, ideally, custom metrics from the Deno runtime. Default CPU-based scaling often fails for event-driven runtimes like Deno because high concurrency does not always correlate linearly with CPU usage. This guide provides the exact manifests, metric configurations, and tuning parameters needed to make scaling reliable in production.
How do you configure resource limits when you autoscale a Deno service on Kubernetes?
The most common failure mode when teams attempt to autoscale a Deno service on Kubernetes is setting resource requests too low or leaving them undefined entirely. Deno’s V8 isolate model behaves differently than Node.js; it can handle thousands of concurrent connections with minimal CPU, but memory usage scales with active promises and buffered I/O. If your requests are inaccurate, the HPA calculates utilization against a wrong baseline, causing either premature scaling or dangerous under-provisioning.
Setting accurate baselines
Before configuring any autoscaler, profile your Deno service under realistic load. Use k6 or wrk to generate traffic that matches your production pattern, then observe steady-state resource consumption via kubectl top pods. Set your requests to the P95 observed value and limits to 1.5–2x that amount. For a typical REST API handling 500 RPS per pod, I frequently see stable baselines around 150m CPU and 256Mi memory.
resources:
requests:
cpu: "150m"
memory: "256Mi"
limits:
cpu: "300m"
memory: "512Mi" Never set CPU limits equal to requests for Deno services. The runtime benefits from burst capacity during garbage collection and JIT compilation phases. Memory limits, however, should be firm; exceeding them triggers OOM kills, which the HPA interprets as a need for more replicas, creating a costly feedback loop. Always pair resource definitions with a proper secrets management strategy to avoid injecting configuration bloat that inflates baseline memory.
Which metrics should drive HPA when you autoscale a Deno service on Kubernetes?
CPU utilization alone is insufficient for event-driven runtimes. Deno can saturate network I/O or event loop capacity long before CPU hits 80%. To reliably autoscale a Deno service on Kubernetes, you need custom metrics that reflect actual application pressure. The Deno runtime exposes Prometheus-compatible metrics natively via the Deno.metrics() API or through community libraries like deno-prometheus.
Essential custom metrics
- HTTP request rate: Requests per second is the most direct indicator of load for API services.
- Event loop lag: Measures how delayed timer callbacks are; values above 10ms indicate saturation.
- Active connections: Tracks open TCP/WebSocket connections, critical for real-time services.
- Pending promises: A rising count suggests downstream bottlenecks or resource exhaustion.
Expose these on a /metrics endpoint and scrape them with Prometheus. Then configure the Prometheus Adapter to translate them into Kubernetes custom metrics API resources. Your HPA can then target http_requests_per_second directly instead of inferring load from CPU.
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: deno-api-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: deno-api
minReplicas: 2
maxReplicas: 20
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Pods
pods:
metric:
name: http_requests_per_second
target:
type: AverageValue
averageValue: "400" This multi-metric approach ensures scaling responds to actual user demand, not just processor heat. In my experience managing compliance-heavy infrastructure, this precision also helps satisfy SOC 2 monitoring requirements by demonstrating that scaling decisions are based on validated business signals rather than generic system metrics.
How do you prevent flapping when you autoscale a Deno service on Kubernetes?
Flapping—rapid scale-up followed by immediate scale-down—is the enemy of stability. Deno services are particularly susceptible because they recover quickly after load drops, causing the HPA to think the crisis is over. The default stabilization window in Kubernetes 1.30+ is 300 seconds for scale-down, but many teams override this to 60s for "responsiveness," inadvertently creating oscillation.
Tuning stabilization policies
Use the behavior field in your HPA spec to enforce asymmetric scaling policies. Scale-up should be aggressive; scale-down must be conservative. For Deno workloads, I recommend a 5-minute scale-down stabilization with a percentage-based policy that removes at most 10% of pods per interval.
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 10
periodSeconds: 60
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Percent
value: 100
periodSeconds: 15 This configuration allows rapid response to traffic surges while preventing premature contraction. Combine this with well-defined SLIs and SLOs to validate that your scaling behavior actually maintains service quality. If error rates spike during scale-down events, increase the stabilization window regardless of cost concerns. Reliability must precede efficiency.
What are the trade-offs between HPA, KEDA, and VPA when you autoscale a Deno service on Kubernetes?
While standard HPA covers most use cases, alternative scalers offer specialized capabilities. Understanding when to reach beyond built-in tooling prevents architectural debt.
| Scaler | Best For | Deno Considerations | Complexity |
|---|---|---|---|
| HPA (built-in) | CPU/memory + custom metrics | Sufficient for 90% of HTTP APIs | Low |
| KEDA | Event-driven (queues, Kafka, cron) | Ideal for Deno workers consuming async jobs | Medium |
| VPA | Right-sizing resource requests | Use in recommendation mode only; never auto-update Deno pods | Medium |
| Cluster Autoscaler | Node-level capacity | Complements HPA; doesn’t replace pod-level decisions | High |
KEDA excels when your Deno service processes background jobs from RabbitMQ or AWS SQS rather than serving synchronous HTTP. It can scale to zero when queues are empty, which HPA cannot do safely for stateful services. VPA is useful during initial profiling but dangerous in production for Deno; restarting pods to adjust resources causes connection drops and cache cold starts. Always run VPA in Off or Initial update mode for Deno workloads, using its recommendations to manually tune requests during maintenance windows.
How do you verify autoscaling works correctly before production?
Never trust autoscaling configuration that hasn’t been validated under controlled conditions. Create a staging environment that mirrors production topology, then execute a structured validation protocol.
- Baseline test: Run steady load at 50% target utilization for 10 minutes. Confirm replica count remains stable.
- Ramp test: Linearly increase load to 150% of target over 5 minutes. Verify pods scale up proportionally without exceeding maxReplicas.
- Spike test: Instantaneously jump from 30% to 120% load. Measure time-to-scale and check for request errors during transition.
- Recovery test: Drop load to 10% and wait through the stabilization window. Confirm scale-down occurs gradually without flapping.
- Failure test: Kill 50% of pods mid-load. Verify HPA replaces them and maintains throughput within SLO bounds.
Document results with timestamps and metric snapshots. This evidence satisfies audit requirements for change management and demonstrates operational maturity. For teams in Nepal managing mixed on-prem and cloud deployments, this discipline is especially critical; you cannot rely on cloud provider auto-healing when part of your stack runs in local data centers with manual intervention cycles.
Reliable Scaling Requires Measurement
To autoscale a Deno service on Kubernetes effectively, treat scaling as an engineering discipline, not a configuration checkbox. Accurate resource baselines, meaningful custom metrics, conservative stabilization policies, and rigorous validation form the foundation. Skip any one, and you’ll face either runaway costs or 3 AM pages. Start with the HPA configuration shown here, instrument your Deno runtime properly, and test before trusting it with real users. If your team needs help designing observable, compliant scaling architectures, reach out to discuss your specific workload.