A Java service on Kubernetes is slow for the first minute after every deploy. Why, and what helps?
IntermediateScenarioScaling and performance
Answer
Situation read → JVM warm-up: class loading, JIT compilation and empty caches. New pods get full traffic as soon as they pass readiness.
What I'd do →
- Use a
startupProbeso slow startup isn't killed by liveness, and make readiness reflect real readiness. - Warm up before ready: hit key endpoints internally on startup, or pre-load caches, then report ready.
- Give CPU headroom at startup; low CPU limits make JIT painfully slow. Consider no CPU limit, or startup CPU boost tooling.
- Ramp traffic gradually: ALB slow start on target groups.
alb.ingress.kubernetes.io/target-group-attributes: slow_start.duration_seconds=60
- Longer term, consider CDS/AppCDS or GraalVM native image for faster startup.
Why → Readiness answers "can it serve?" not "can it serve fast?". Slow start bridges the gap.
Interview tip → ALB slow start is a concrete, lesser-known setting worth naming.
More on Scaling and performance
Traffic is expected to 10x for a sale next week. How do you prepare the platform?IntermediateThe HPA is configured but pods don't scale even though the app is slow. Why?BeginnerPods are Pending during a traffic spike because the cluster is out of capacity. What do you do now and long term?IntermediateThe database CPU is at 95% and the API is timing out. What's your approach?Intermediate"Too many connections" errors from Postgres after scaling the app out. How do you fix it?IntermediateLatency is fine on average but p99 is terrible. Where do you look?Advanced