Scaling Model Serving on Kubernetes
Split model serving from the Node.js API tier so each scales to its strengths: vertically sized model servers replicated horizontally with predictive scaling, stateless Node behind an HPA, shadow then canary releases for new models.
🌱 A rough idea, planted recently. Expect rough edges — it will grow.
On this page
An AI-backed service usually has two very different workloads: a fleet of API servers doing I/O, and model servers doing heavy inference. Split them so each can scale to its strengths on Kubernetes.
Hybrid scaling for model servers
- Vertically sized model-server instances give high efficiency per replica (big memory, a GPU, a warm model).
- Horizontal replication of those instances provides elasticity and fault tolerance, and makes canary releases possible.
- Model servers are slow to start, so horizontal autoscaling needs pre-warming or predictive scaling, or you’ll shed load during traffic ramps.
The Node.js tier
Node services are typically I/O-bound or lightly CPU-bound, so horizontal scaling is king: identical replicas are easy to add and remove. Keep them stateless and you get autoscaling, rolling updates and failure recovery almost for free.
The Kubernetes mechanisms
- Horizontal Pod Autoscaler: scale pods on metrics.
- Prometheus Adapter: expose custom metrics to the HPA, such as queue depth or inference latency, which are far better signals for model servers than CPU.
- Cluster Autoscaler: add and remove nodes.
- Node pool auto-provisioning: bring GPU pools up on demand.
The data tier
Connection pooling, PostgreSQL, caching layers, and care around synchronisation. In multi-tenant systems, enforce data isolation at the storage level, not just in application code.
Inference runtime
- ONNX Runtime for direct model inference has official Node.js bindings and CUDA GPU acceleration. I’d use it unless the Python ecosystem is a hard requirement.
- WebAssembly sandboxing: modules can’t touch the host filesystem or network unless explicitly granted, which makes it attractive for running third-party code.
Releasing new models
- Shadow (echo) testing: copy real traffic to the new model and compare its answers, without users ever seeing them.
- Canary: then route a small slice of real users to it, watching the metrics that matter (Observability).
It’s the same family of techniques as Blue-Green Deployment, adapted for the fact that a model can be “up” and still wrong.
Security
- Some models expose compute whose abuse generates substantial cost. Authenticate and rate-limit.
- Auth and RBAC, hardening, input validation, resource limits.
- Restrict network exposure with NetworkPolicies.
- Automate dependency scanning in the pipeline.
- #kubernetes
- #model-serving
- #autoscaling
- #nodejs
- #onnx
- #ai-infrastructure
↩ Linked from (1)
- KubernetesSeed
…d. How those fit together for AI workloads, where model servers and API servers scale very differently, is in Scaling Model Serving on Kubernetes.
↪ Links to (3)
Related by topic
- Seed
Agentic System Design Checklist
AI, machine learning - Seed
Contract-Driven Development
Platform engineering - Seed
Smart Parking Multi-Agent System - Case Study
AI, machine learning - Growingcase study
A Resumable CMS Migration Tool
Distributed systems