Quick revision
The short answer
On a managed platform the application must fit the platform's contract: listen on the port it is given, usually through a PORT environment variable with server.port=${PORT:8080}, read configuration and secrets from the environment, keep no state in the instance, expose health checks, log to stdout and shut down gracefully on SIGTERM. Spring Boot detects some platforms by itself, such as Kubernetes and Cloud Foundry through spring.main.cloud-platform, and switches on matching features like liveness and readiness health groups.
What to remember
In this answer, we saw that a managed platform runs copies of our application that can appear and disappear at any time, and that the application must follow the platform's contract. It listens on the port it is given with server.port=${PORT:8080}, takes configuration and secrets from the environment, and keeps no state in the instance. Spring Boot detects platforms such as Kubernetes and Cloud Foundry through spring.main.cloud-platform and enables health probe groups there; elsewhere we switch them on ourselves. Health endpoints, structured logs on stdout, graceful shutdown on SIGTERM, and a standard jar or buildpack image complete the picture.
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.
On a managed platform the application must fit the platform's contract: listen on the port it is given, usually through a PORT environment variable with server.port=${PORT:8080}, read configuration and secrets from the environment, keep no state in the instance, expose health checks, log to stdout and shut down gracefully on SIGTERM. Spring Boot detects some platforms by itself, such as Kubernetes and Cloud Foundry through spring.main.cloud-platform, and switches on matching features like liveness and readiness health groups.
Why this question is asked
Managed platforms such as Google Cloud Run, Azure App Service, AWS App Runner and Cloud Foundry promise that we hand over a jar or an image and they run it. In practice, they also expect the application to behave in a certain way: they start and stop instances whenever they like, they route traffic to a port they choose, and they judge health by probing. A service that ignores these rules works in a demo and fails under load. Interviewers ask this to see whether we know that contract and what Spring Boot already does for us. In this answer, we will recap what such a platform does, then go through ports, configuration and statelessness, platform detection, health and logs, graceful shutdown, and packaging.
1A Quick Recap: What a Managed Platform Does
A managed platform, sometimes called a platform as a service, takes our packaged application and runs as many instances of it as traffic requires. It puts a load balancer in front, sends each request to one of the instances, restarts instances that fail their health check, and replaces instances when we deploy a new version or when it needs to move them.
The important word is instance. We do not own a server; we own a template, and the platform makes copies of it. Any copy can be created or destroyed at any moment. Everything else in this answer follows from that.
- Platform starts an instancesets PORT and other env vars
- Spring Boot startsbinds to the given port
- Health check passes?YesInstance receives trafficNoPlatform restarts or replaces it
- Requests are servedlogs go to stdout
- Scale-in or new deployplatform sends SIGTERM
- Graceful shutdownfinish in-flight requests, then exit
6 steps in order. Play them, or step through them one at a time.
Any instance can be created or removed at any time.
2Listen on the Port You Are Given
Many platforms decide which port the container must listen on and tell the application through an environment variable called PORT. Cloud Run and Cloud Foundry do this; on others, such as App Runner, we declare the port in the service settings instead, and on App Service there are platform-specific settings for it, so check the platform's documentation. Spring Boot does not read PORT by itself, so we map it ourselves with a placeholder that has a default for local runs.
Notice the default after the colon. Without it, the application fails to start wherever PORT is missing, which is exactly where developers try it first.
3Configuration From the Environment, and No State in the Instance
Because the platform starts copies of our image, configuration cannot live in files inside it. The platform offers environment variables and usually a secrets service, such as Secret Manager on Google Cloud, Key Vault on Azure or Secrets Manager on AWS, whose values can be exposed as environment variables or read at start-up. Spring Boot's relaxed binding turns SPRING_DATASOURCE_URL into spring.datasource.url without extra code.
Statelessness means no instance holds anything the next request might need. HTTP sessions kept in memory, files written to the local disk and caches that must be consistent all break as soon as there are two instances or one is replaced. We move that state out: sessions to Spring Session with Redis or a database, files to object storage, and shared data to a database or a distributed cache.
4What Spring Boot Detects Automatically
Spring Boot has a notion of the cloud platform it runs on, exposed through the property spring.main.cloud-platform. It detects several platforms from the environment, for example Kubernetes from the KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT variables that every pod receives, and Cloud Foundry from its VCAP_APPLICATION variable. The CloudPlatform enum also has values such as HEROKU, SAP, NOMAD and AZURE_APP_SERVICE; the exact list depends on your version.
Detection matters because Boot switches on platform features. On Kubernetes, Actuator automatically adds the liveness and readiness health groups at /actuator/health/liveness and /actuator/health/readiness, which match the platform's probes. We can also force a value, which is handy for testing locally or for a platform Boot does not recognise.
On platforms Boot does not detect, such as Cloud Run or App Runner, nothing is switched on automatically, so we enable the probe groups ourselves and point the platform's health check at them.
5Health Checks, Logs and Graceful Shutdown
The platform decides whether an instance is healthy by calling an endpoint or opening a TCP connection. Pointing its check at the Actuator health endpoint gives it a real answer: readiness includes things like whether the application has finished starting, while liveness should only fail when the process is truly stuck, because a failed liveness check means a restart.
Logs should go to standard output, one event per line. The platform collects stdout and sends it to its log service, and structured JSON lines let that service filter by fields such as trace id. Since Spring Boot 3.4, logging.structured.format.console can be set to ecs, logstash or gelf without any extra library.
Finally, the platform stops instances by sending SIGTERM, a polite request to exit, and kills them a little later if they are still running. With graceful shutdown, Boot stops accepting new requests, lets the in-flight ones finish, and then exits. server.shutdown=graceful turns it on, and it has been the default for the embedded web servers since Boot 3.4; spring.lifecycle.timeout-per-shutdown-phase, 30 seconds by default, limits how long it waits, and it should be shorter than the platform's grace period.
6Packaging: Executable Jar or Container Image
Platforms differ in what they accept. Cloud Run runs container images, and can also build one from source with buildpacks. App Runner accepts an image or source code for supported runtimes. App Service can run a jar on its Java runtime or a container. Cloud Foundry takes a jar and builds the container itself with a buildpack.
Buildpacks turn source or a jar into an image without a Dockerfile, choosing a JDK and sensible memory settings. Spring Boot supports them directly with mvn spring-boot:build-image or gradle bootBuildImage, which use the Paketo buildpacks. Either way, the executable jar or the image is a standard artifact, so the same build output can move between platforms.
7Follow-up questions
What happens to in-memory sessions when the platform scales instances?
They are lost or split. A session stored in the memory of instance A exists only there. When the platform adds instance B, requests that land on B find no session, so the user appears logged out or loses a cart. When the platform removes A at scale-in or during a deploy, every session it held disappears. Session affinity, where the load balancer tries to send a user back to the same instance, reduces the problem but does not remove it, because affinity is best effort and instances still die. The fix is to keep sessions outside the instance, with Spring Session backed by Redis or a database, or to avoid server sessions altogether and use tokens.
Why should liveness not check the database?
Because a failed liveness check makes the platform restart the instance. If the database is down, every instance would fail liveness and be restarted in a loop, which makes recovery slower and adds load. The database belongs in readiness, if anywhere, so instances stop receiving traffic but stay alive.
How should JVM memory be set on these platforms?
The JVM reads the container's memory limit, so a percentage such as -XX:MaxRAMPercentage=75 sizes the heap relative to the instance and leaves room for metaspace, threads and native memory. Buildpacks calculate these values automatically. A fixed -Xmx copied from a server often exceeds a smaller instance and gets the process killed.
8Conclusion
In this answer, we saw that a managed platform runs copies of our application that can appear and disappear at any time, and that the application must follow the platform's contract. It listens on the port it is given with server.port=${PORT:8080}, takes configuration and secrets from the environment, and keeps no state in the instance. Spring Boot detects platforms such as Kubernetes and Cloud Foundry through spring.main.cloud-platform and enables health probe groups there; elsewhere we switch them on ourselves. Health endpoints, structured logs on stdout, graceful shutdown on SIGTERM, and a standard jar or buildpack image complete the picture.
Open with
I treat a managed platform as something that runs disposable copies of my service, so the app has to follow its contract. First, the port: platforms like Cloud Run and Cloud Foundry pass a PORT variable, so I set server.port=${PORT:8080}, with the default for local runs.
Then, if they want more
Second, configuration comes from environment variables and the platform's secrets service, and the instance holds no state, so sessions go to Spring Session with Redis and files go to object storage. Third, health.
Spring Boot detects some platforms through spring.main.cloud-platform, for example Kubernetes from the service host variables and Cloud Foundry from VCAP_APPLICATION, and on Kubernetes it enables the liveness and readiness groups automatically. On Cloud Run or App Runner nothing is detected, so I enable management.endpoint.health.probes.enabled and point the platform's checks there, keeping the database out of liveness.
Fourth, I log JSON to stdout, which Boot 3.4 supports with structured logging, and I make sure graceful shutdown is on and its timeout is below the platform's grace period, so SIGTERM during a deploy does not cut requests.
Finally, I package as an executable jar or a buildpack image with spring-boot:build-image, depending on what the platform accepts, and I size the heap with MaxRAMPercentage.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 3.4
- 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 "You need to deploy a Spring Boot service to a managed platform such as Google Cloud Run...": https://scrivio-interview-library.netlify.app/spring-boot/packaging-and-deployment/743582a537/