SkillByAIOpen interactive version →

Lesson 22 / 25

Resilience and Performance

Timeouts, pools, virtual threads.

Fail fast and use resources well

Set timeouts on every outbound HTTP and database call; use retries with backoff only for safe, idempotent operations, and circuit breakers (for example Resilience4j) for flaky dependencies. Size connection pools (HikariCP) deliberately. On Java 21+, enabling virtual threads (spring.threads.virtual.enabled=true) lets blocking request handling scale to many concurrent requests with simple code. Load-test before launch and watch pool and thread metrics.

Resilience settings (sketch)

Not part of the built demo; check the Spring documentation for your version.

spring.threads.virtual.enabled=true
spring.datasource.hikari.maximum-pool-size=20
spring.datasource.hikari.connection-timeout=3000
spring.mvc.async.request-timeout=10s
# outbound HTTP clients: always configure connect and read timeouts

Timeouts everywhere

A single call without a timeout can hold threads and connections until the whole service stalls.

Quick check: What do virtual threads (Java 21+) help with?

  • Removing the need for a database
  • Reducing JSON size
  • Encrypting data
  • Handling many concurrent blocking requests with simple code
Answer

Handling many concurrent blocking requests with simple code — Cheap threads for blocking I/O.