Spring Boot Architecture for Production
Structuring Spring Boot services, configuration, profiles, Actuator, observability, testing with Testcontainers, packaging and what changed with Spring Boot 3 and 4.
[!VERSION] Spring Boot 3.x requires Java 17+ and Jakarta EE 9+ namespaces (
jakarta.*). Spring Boot 4.0 (released November 2025) is based on Spring Framework 7 with Java 17 as baseline and Jakarta EE 11, further modularized auto-configuration, and JSpecify null-safety annotations. Check the migration guide before upgrading.
Recommended service structure
orders-service/
src/main/java/com/acme/orders/
OrdersApplication.java
api/ controllers, DTOs, exception handlers (RFC 9457 problem details)
application/ use cases, transactions
domain/ aggregates, value objects, domain events
infrastructure/ JPA repositories, Kafka adapters, HTTP clients
src/main/resources/
application.yaml
application-prod.yaml
db/migration/ Flyway scripts
src/test/java/... unit, slice and Testcontainers integration testsProduction essentials
| Concern | Spring Boot feature |
|---|---|
| Health and readiness | Actuator /actuator/health/liveness and /readiness (Kubernetes probes) |
| Metrics | Micrometer → Prometheus/OTLP |
| Tracing | Micrometer Tracing with OpenTelemetry bridge, W3C trace context |
| Config | @ConfigurationProperties with validation; externalized config; secrets from vault/Kubernetes |
| Error responses | ProblemDetail (RFC 9457) |
| Graceful shutdown | server.shutdown=graceful |
| DB migrations | Flyway or Liquibase |
| HTTP clients | RestClient (sync), WebClient (reactive), HTTP interface clients |
| Concurrency | spring.threads.virtual.enabled=true |
server:
shutdown: graceful
management:
endpoints.web.exposure.include: health,info,prometheus
endpoint.health.probes.enabled: true
tracing.sampling.probability: 0.1
spring:
threads.virtual.enabled: true
jpa.open-in-view: false # avoid lazy-loading queries in the web layerDeclarative HTTP client
public interface InventoryClient {
@GetExchange("/stock/{sku}")
Stock stock(@PathVariable String sku);
}
@Configuration
class ClientConfig {
@Bean
InventoryClient inventoryClient(RestClient.Builder builder) {
RestClient rc = builder.baseUrl("http://inventory").build();
return HttpServiceProxyFactory.builderFor(RestClientAdapter.create(rc)).build().createClient(InventoryClient.class);
}
}Testing with Testcontainers
@SpringBootTest
@Testcontainers
class OrderRepositoryIT {
@Container @ServiceConnection
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:17");
@Autowired OrderRepository orders;
@Test void savesAndLoadsOrder() {
var saved = orders.save(TestData.order());
assertThat(orders.findById(saved.getId())).isPresent();
}
}Architect-level considerations
[!ARCHITECT] Provide a company "starter" (parent POM/BOM + auto-configuration) with standard observability, security, error handling, logging format and resilience defaults so every team starts compliant.
[!WARNING]
spring.jpa.open-in-viewdefaults to true and silently triggers queries during view rendering; disable it in APIs.
Interview questions and answers
How do you make a Spring Boot service Kubernetes-ready?
Liveness/readiness probes via Actuator, graceful shutdown, externalized configuration and secrets, structured logs to stdout, metrics/tracing exporters, resource requests and JVM memory percentages, and a small container image (layered jars or buildpacks).
What changed from Spring Boot 2 to 3?
Java 17 baseline, javax → jakarta packages, Micrometer Observation API and tracing (replacing Spring Cloud Sleuth), native image support via AOT processing, and ProblemDetail support.