What is Spring Boot performance optimization?

Why Interviewers Ask This

Advanced questions like this reveal whether a candidate has internalized Spring Boot deeply enough to make architectural decisions. Strong answers demonstrate both breadth and depth of experience.

Answer

Spring Boot performance optimization strategies: 1. Startup time: use Spring Boot's lazy initialization: spring.main.lazy-initialization=true — beans created on first request, not at startup. Reduces startup time by 40-60%. Spring Native (GraalVM): compile to native executable — millisecond startup, lower memory. mvn spring-boot:build-image -Pnative. 2. Database performance: use read-only transactions for queries: @Transactional(readOnly = true) — disables dirty checking, reduces lock scope; use projections to fetch only needed columns; enable second-level cache (EhCache/Redis) with Hibernate: @Cache(usage = CacheConcurrencyStrategy.READ_WRITE); use pagination for large result sets; add connection pool tuning (HikariCP). 3. HTTP layer: enable GZIP compression: server.compression.enabled=true; enable HTTP/2: server.http2.enabled=true; configure server thread pools: server.tomcat.max-threads=200. 4. JVM tuning: JAVA_OPTS="-Xms512m -Xmx2048m -XX:+UseG1GC -XX:MaxGCPauseMillis=200". 5. Cache aggressively: @Cacheable with Redis for frequently-accessed, rarely-changed data; cache-aside pattern with manual TTL management. 6. Async processing: @Async with custom thread pools for I/O-bound operations; CompletableFuture.allOf() for parallel external calls. 7. Avoid N+1 queries: use @EntityGraph or JOIN FETCH: @Query("SELECT o FROM Order o JOIN FETCH o.items WHERE o.userId = :id") List<Order> findWithItems(@Param("id") Long id);. 8. Virtual threads (Java 21 + Spring Boot 3.2): spring.threads.virtual.enabled=true — enables virtual threads for Tomcat, very high concurrency with minimal overhead.

Pro Tip

This topic has Spring Boot-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.