Quick revision
The short answer
The runner blocks the main thread, so Boot reports readiness only after the 2 million rows are loaded, and probes give up first. We can give the pod more time with a startupProbe, or move the loading to a background task and keep readiness down until it finishes, controlling it explicitly through a readiness health indicator or AvailabilityChangeEvent. Better still, load lazily on demand or from a faster snapshot, and question whether warming every row is needed at all.
What to remember
In this answer, we saw that a runner loading 2 million rows blocks the main thread, so Boot reports readiness only after it finishes, and a strict startup or liveness probe kills the pod first. We can give startup more time with a startupProbe, move the load to the background while a readiness health indicator, or AvailabilityChangeEvent later on, keeps the pod out of traffic, load lazily or from a snapshot, and above all question whether warming every row is needed.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The runner blocks the main thread, so Boot reports readiness only after the 2 million rows are loaded, and probes give up first. We can give the pod more time with a startupProbe, or move the loading to a background task and keep readiness down until it finishes, controlling it explicitly through a readiness health indicator or AvailabilityChangeEvent. Better still, load lazily on demand or from a faster snapshot, and question whether warming every row is needed at all.
Why this question is asked
Cache warming at startup is a common way to make the first requests fast, and it works until the data grows. At 2 million rows the warm-up takes minutes, rollouts stall and pods restart in a loop. Interviewers ask this because the answer needs both Spring Boot's startup sequence and Kubernetes probes, and because the best answer often questions the requirement. In this answer, we will see why the pod is killed, then go through the options: tuning probes, loading in the background with explicit readiness, loading lazily or from a snapshot, and deciding whether full warming is needed.
1Why the Pod Is Not Ready in Time
Runners run on the main thread after the context is refreshed and before ApplicationReadyEvent. Boot sets readiness to ACCEPTING_TRAFFIC only after ApplicationReadyEvent, so while the runner reads 2 million rows, say for 4 minutes, /actuator/health/readiness returns 503 with status OUT_OF_SERVICE, because the readiness state is still REFUSING_TRAFFIC. The web server itself is already listening, so the port is open, but the service reports not ready.
Kubernetes has three probes. The readiness probe decides whether a pod gets traffic; failing it does not kill the pod, but a rollout waits and eventually fails its progress deadline. The liveness probe decides whether to restart the container. The startup probe, if present, holds off liveness checks until startup succeeds. Pods are killed when a liveness or startup probe fails too many times. A common cause here is a probe pointed at the overall health or readiness endpoint, or a startup probe with a window shorter than the warm-up.
7 messages in order. Play them, or step through them one at a time.
The probe's patience (150 s) is shorter than the 4 minute warm-up, so the pod restarts and starts warming again.
2Option 1: Give Startup More Time
The quickest fix is to make the startup probe match reality. A startup probe with failureThreshold 60 and periodSeconds 5 allows 5 minutes. While it has not succeeded, Kubernetes does not run the liveness probe, so the pod is not restarted for being slow.
Notice the paths: liveness and readiness are different questions, and only readiness should depend on warm-up. This fix stops the killing, but rollouts are still slow, and every scale-out waits minutes for new pods, so it is a stopgap, not a solution.
3Option 2: Load in the Background and Control Readiness
A better design lets startup finish quickly and loads the rows in the background, while the pod stays not ready until the cache is warm. We must be careful with timing: Boot publishes ACCEPTING_TRAFFIC itself right after ApplicationReadyEvent, so if we only publish REFUSING_TRAFFIC early, Boot overrides it. A reliable way is a health indicator that belongs to the readiness group.
Startup now takes seconds, liveness is healthy at once, and the readiness group stays down until the indicator reports UP. AvailabilityChangeEvent is still the tool for controlling readiness explicitly later in the pod's life, for example publishing ReadinessState.REFUSING_TRAFFIC while a nightly full reload runs and ACCEPTING_TRAFFIC after it. But for the first warm-up, the indicator avoids racing with Boot's own ready event. The loader should handle failures, for example by retrying, and report DOWN on repeated failure so the pod never sits not ready forever without anyone noticing.
4Option 3: Load Lazily or From a Faster Snapshot
Background loading still means every pod reads 2 million rows on every start. Two other designs reduce that work. Lazy loading fills the cache on demand: the first request for a product reads it from the database and later requests hit the cache. A cache library such as Caffeine with a loading function makes this a few lines, and the first requests are a little slower instead of the whole pod being unavailable.
A snapshot makes full loading cheaper: a job writes the cache contents periodically to a compact file in object storage, and pods load that file at startup, which is often ten times faster than querying and mapping rows. A shared cache such as Redis removes per-pod warming entirely, at the price of a network hop per read.
5Option 4: Ask Whether Warming Everything Is Needed
Finally, the most valuable question: why 2 million rows? Often traffic follows a steep curve, and 5 percent of products serve 90 percent of requests. Warming only the hot set, found from access statistics, may take 10 seconds instead of 4 minutes, with the rest loaded lazily.
Sometimes warming was added years ago for a database that was slow then, and the database today answers in 2 milliseconds. Measuring the latency without warming may show that the problem it solved no longer exists. The cheapest startup work is the work we remove.
- Is full warming really needed?YesGo onNoWarm hot set or none, load lazily
- Can data come from a snapshot?YesLoad snapshot at startupNoGo on
- Load in the backgroundreadiness group with warm-up indicator
- Tune startupProbe as a safety netliveness separate from readiness
4 steps in order. Play them, or step through them one at a time.
6Follow-up questions
Why not just increase the readiness probe's initialDelaySeconds?
It hard-codes a guess, and the warm-up time grows with the data. A startup probe or a readiness indicator reacts to the actual state, so it works when the data doubles.
Does the pod receive traffic while the cache loads in the background?
No, as long as readiness is down, the Service does not route to it. Liveness stays up, so Kubernetes does not restart it. That split is exactly what the two probes are for.
What happens to memory with 2 million rows in each pod?
Each pod holds a full copy, so heap size and garbage collection are affected, and the warm-up itself creates a burst of allocation. This is another argument for warming only the hot set or using a shared cache.
7Conclusion
In this answer, we saw that a runner loading 2 million rows blocks the main thread, so Boot reports readiness only after it finishes, and a strict startup or liveness probe kills the pod first. We can give startup more time with a startupProbe, move the load to the background while a readiness health indicator, or AvailabilityChangeEvent later on, keeps the pod out of traffic, load lazily or from a snapshot, and above all question whether warming every row is needed.
Open with
The runner runs on the main thread before ApplicationReadyEvent, so readiness stays REFUSING_TRAFFIC for the whole four minutes, and the pod gets killed because a startup or liveness probe gives up before then, often because the probe points at readiness or overall health.
Then, if they want more
First I would separate the probes: liveness on the liveness endpoint, readiness on readiness, and a startupProbe whose failure threshold times period covers the real startup time. That stops the killing but rollouts and scale-out stay slow.
The real fix is to move the loading to a background task started after the context is up, and keep the pod out of traffic until it is done. I would do that with a health indicator in the readiness group that reports out of service until the cache is warm, because Boot publishes ACCEPTING_TRAFFIC itself after the ready event.
AvailabilityChangeEvent is the way to flip readiness explicitly later, for example during a full reload. Then I would reduce the work: load lazily on demand with something like Caffeine, or load a snapshot file that a job produces. And I would ask whether all 2 million rows need warming, because usually a small hot set covers most traffic.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A runner warms a cache by loading 2 million rows at startup. Kubernetes kills the pod...": https://scrivio-interview-library.netlify.app/spring-boot/boot-startup/6240f9c7de/