Java tutorial · Intermediate · 15 min

DORA for Java developers: timeouts, Resilience4j, logs and SBOM

DORA has applied since January 2025 to banks, insurers and other financial entities. The regulation talks about ICT risk management, incidents and testing: behind those words are very concrete choices in the code. Here are the ones that come up on every project, with Resilience4j as the toolbox.

Tested source code, free to use: GitHub, Scopas-Team/java-finance-tutorials (Apache 2.0 licence)

What DORA expects, seen from the code

Delegated Regulation (EU) 2024/1774, which specifies the ICT risk management framework, details requirements on development, change management and logging in particular.

1. A timeout on every call

A call without a timeout can block a thread forever, then all the others. It is the most common cause of cascading failures, and the easiest to avoid:

HttpClient client = HttpClient.newBuilder()
    .connectTimeout(Duration.ofSeconds(2))
    .build();

HttpRequest request = HttpRequest.newBuilder(URI.create(scoringUrl + "/score/" + customerId))
    .timeout(Duration.ofSeconds(3))   // response timeout
    .GET()
    .build();

Do the same for JDBC (setQueryTimeout, pool timeouts), messaging clients and cloud provider SDKs. A timeout is chosen with the business: beyond it, is a degraded answer better?

2. Circuit breaker, retries and fallback with Resilience4j

When a service is down, insisting makes things worse. The circuit breaker stops calls once a failure or slowness rate is reached, then restores them gradually. Retries absorb transient errors. The fallback provides a degraded answer.

Plain Java: the resilience4j-all module (circuit breaker, retry and the Decorators API)

CircuitBreaker circuitBreaker = CircuitBreaker.of("scoring", CircuitBreakerConfig.custom()
    .slidingWindowSize(20)                              // over the last 20 calls
    .failureRateThreshold(50)                           // open above 50% failures
    .slowCallDurationThreshold(Duration.ofSeconds(2))
    .slowCallRateThreshold(50)                          // or 50% slow calls
    .waitDurationInOpenState(Duration.ofSeconds(30))
    .build());

Retry retry = Retry.of("scoring", RetryConfig.custom()
    .maxAttempts(3)
    .waitDuration(Duration.ofMillis(200))
    .build());

Supplier<Score> call = Decorators.ofSupplier(() -> scoring.score(customerId))
    .withCircuitBreaker(circuitBreaker)
    .withRetry(retry)
    .withFallback(List.of(CallNotPermittedException.class, UncheckedIOException.class),
                  e -> Score.unavailable())
    .decorate();

Score score = call.get();

The golden rule: only retry idempotent operations. Retrying a score lookup is harmless; retrying a payment order without an idempotency key can duplicate it. And a fallback must be a business decision: does an "unavailable" score send the file to manual review, or block it?

With Spring Boot (resilience4j-spring-boot3 module): application.yml

resilience4j:
  circuitbreaker:
    instances:
      scoring:
        sliding-window-size: 20
        failure-rate-threshold: 50
        slow-call-duration-threshold: 2s
        slow-call-rate-threshold: 50
        wait-duration-in-open-state: 30s
  retry:
    instances:
      scoring:
        max-attempts: 3
        wait-duration: 200ms
@CircuitBreaker(name = "scoring", fallbackMethod = "scoreUnavailable")
@Retry(name = "scoring")
public Score score(String customerId) {
    return scoringClient.score(customerId);
}

private Score scoreUnavailable(String customerId, Throwable cause) {
    return Score.unavailable();
}

3. Making failures visible

A circuit breaker opening is an incident signal. Log its state changes and expose its metrics to monitoring:

circuitBreaker.getEventPublisher().onStateTransition(e ->
    log.warn("circuit breaker {}: {}", e.getCircuitBreakerName(), e.getStateTransition()));

// Micrometer metrics (resilience4j-micrometer module)
TaggedCircuitBreakerMetrics.ofCircuitBreakerRegistry(circuitBreakerRegistry).bindTo(meterRegistry);

To classify an incident against DORA's criteria (clients and transactions affected, duration, critical services), you need structured logs:

4. Testing resilience for real

A unit test checks the configuration; an integration test with a real failure checks the behaviour. Toxiproxy, with Testcontainers, puts a proxy between the application and the service, then injects latency or outages into it:

@Test
void slowScoringTriggersFallback() throws IOException {
    scoringProxy.toxics().latency("slow-scoring", ToxicDirection.DOWNSTREAM, 5_000);

    for (int i = 0; i < 20; i++) {
        assertThat(service.score("C-42")).isEqualTo(Score.unavailable());
    }
    assertThat(circuitBreaker.getState()).isEqualTo(CircuitBreaker.State.OPEN);
}

Add these tests to the continuous integration pipeline: they feed straight into the resilience testing programme DORA requires.

5. Knowing and fixing your dependencies

A software bill of materials (SBOM) lists every component of the application, versions included. It lets you answer "are we exposed to this vulnerability?" in minutes.

build.gradle

plugins {
    id 'org.cyclonedx.bom' version 'X.Y.Z' // latest version on plugins.gradle.org
}
// ./gradlew cyclonedxBom  writes build/reports/bom.json

With Maven, the org.cyclonedx:cyclonedx-maven-plugin plugin (makeAggregateBom goal). Send the SBOM to an analysis tool (OWASP Dependency-Track, or Dependency-Check in the build) and automate upgrades (Renovate, Dependabot). Open-source libraries are not in DORA's register of information, which covers contracts, but they are part of the ICT assets you must manage.

Key points

Where do you stand on DORA?

Our AI Act + DORA review takes stock in a few days at a fixed price; our cybersecurity offer tests your resilience. You can also start with the free DORA self-assessment.

The AI Act + DORA review All tutorials

Worth a look