Java Packaging and containers
Turning a build into something that runs, and the JVM settings that only matter once it runs in a container.
3 concepts · 9 interview questions
What this topic covers
Every concept in packaging and containers, and the questions each one gets asked as. Where a question links, it has a full write-up.
Jars, fat jars and layers
A Spring Boot jar embeds its dependencies and a launcher. How it is layered decides how much of a container image has to be rebuilt on each deploy.
- What is inside an executable Spring Boot jar?
- Why layer a Docker image, and what goes in which layer?
- What is a distroless or slim base image, and what do you lose?
The JVM inside a container
A container memory limit is not the JVM's heap limit. The JVM reads the cgroup limit and sizes itself as a fraction of it, and the rest is off-heap.
- Your container is OOM-killed but the heap looks fine. Why?
- How does the JVM decide its heap size in a container?
- Which GC would you pick for a small container?
Startup time
Startup matters for autoscaling and for serverless. Class loading, component scanning and JIT warm-up dominate the first seconds.
- Why is the first request after a deploy slow?
- How would you cut a Spring Boot application's startup time?
- What is a native image, and what does it give up?