Java and Spring Level 1 This level · 84 of 105
Easy java spring

Why is Spring Boot preferred for cloud-native apps?

The 30 second answer

Spring Boot supports many cloud-native practices without making them automatic. I can use the same artifact across environments, externalize configuration, connect to backing services, write logs to standard output and shut down gracefully. It also supports Kubernetes liveness and readiness probes, mounted configuration and secrets, and buildpack-based container images. Native images are another option when startup time matters. Those are practical reasons to choose it, but good deployment design and sensible operational settings still matter.

Could you say this in an interview?

Go through the Twelve-Factor list and show the Spring Boot feature for each:

FactorSpring Boot feature
III. Config in the environmentRelaxed binding: SPRING_DATASOURCE_URL sets spring.datasource.url; spring.config.import=configtree:/etc/secrets/ reads mounted Kubernetes secrets
IV. Backing servicesA database, broker or cache is just a URL and credentials in properties; swap them without code changes
V. Build, release, runOne executable JAR or image; config is applied at run time
VI. Stateless processesNothing forces server state; session data can move to Redis with Spring Session
VII. Port bindingEmbedded server; server.port or SERVER_PORT
IX. DisposabilityGraceful shutdown waits for in-flight requests; startup can be cut with AOT, CDS or native images
X. Dev/prod parityDocker Compose and Testcontainers support start the same databases locally and in tests
XI. Logs as event streamsLogs go to the console by default; structured JSON formats are built in

Kubernetes specifics:

  • Probes. When Spring Boot detects it is running on Kubernetes (it checks for *_SERVICE_HOST and *_SERVICE_PORT environment variables), Actuator adds liveness and readiness health groups. Readiness becomes ACCEPTING_TRAFFIC only after the app is ready, and turns REFUSING_TRAFFIC during shutdown.
livenessProbe:
  httpGet: { path: /actuator/health/liveness, port: 8080 }
readinessProbe:
  httpGet: { path: /actuator/health/readiness, port: 8080 }
  • Images. mvn spring-boot:build-image or gradle bootBuildImage builds an OCI image with Cloud Native Buildpacks.
  • Observability. Micrometer metrics and tracing export to Prometheus or OpenTelemetry.

Editor's note: be honest about limits. Twelve-Factor is a guideline from 2011, not a standard, and Spring Boot does not make an app stateless by itself; you still have to design it that way.

Sources (4)
  1. The Twelve-Factor App12factor.net
  2. Spring Boot reference: Deploying to Kubernetesdocs.spring.io
  3. Spring Boot reference: Kubernetes probesdocs.spring.io
  4. Spring Boot reference: Configuration treesdocs.spring.io
Previous
Next