liveBook · Manning

Resilience

As explained in Quarkus in Action

Fault tolerance is the ability of a system to continue providing acceptable service despite failures in its components or dependencies.

Resilience is a system’s ability to stay responsive when a component or dependency fails. In a distributed application, one failure can otherwise cascade through other services. Isolating services and limiting the impact of failures helps keep requests working, or at least reduces the disruption users experience. section 9.2 section 10.5

Fault-tolerance patterns protect particular operations. Quarkus provides them through the annotation-based MicroProfile Fault Tolerance API and the `quarkus-smallrye-fault-tolerance` extension. The annotations keep recovery rules separate from business logic. section 10.5

Choose a pattern according to what should happen when an operation struggles:

  • Retry a failed operation a limited number of times; use a fallback operation if it still fails. section 10.5
  • Use a bulkhead to limit concurrent invocations, or a circuit breaker to stop attempting an operation after repeated failures. section 10.5
  • Set a timeout to abort an operation that takes too long. section 10.5

Protecting an availability request

Suppose a Reservation service calls an Inventory service to find available cars. Add the SmallRye extension to Reservation, the caller, because its request needs protection when Inventory is unavailable. Annotating the availability method with `@Retry(maxRetries = 25, delay = 1000)` allows repeated attempts one second apart. If those attempts fail, `@Fallback(fallbackMethod = "availabilityFallback")` can return an empty car list instead of propagating an exception. Retry can keep the request waiting for up to 25 seconds when Inventory is down, and the retried method must be idempotent so repeated execution does not cause inconsistent side effects. section 10.5.1

Listing 10.8 Fault tolerance availability fallback
public Uni<Collection<Car>> availabilityFallback(LocalDate startDate,
                                                 LocalDate endDate) {
    return Uni.createFrom().item(List.of());
}

The fallback method returns an empty collection in the same `Uni<Collection<Car>>` shape as the availability result. section 10.5.1

These annotations address failures during an operation; they do not make a failing dependency healthy. The declarative API is the focus here, rather than SmallRye Fault Tolerance’s separate programmatic API. section 10.5 section 10.5.1

How Quarkus in Action covers it

How deep it goes
Defines five fault-tolerance patterns and works through annotated retry and fallback; defers the programmatic API.
Examples
Uses a Reservation-to-Inventory availability request with 25 delayed retries and an empty-list fallback.
What it assumes
Assumes familiarity with Java service methods and REST calls; introduces the fault-tolerance patterns and Quarkus extension before applying annotations.
What you can do after
Apply it via MicroProfile Fault Tolerance annotations to protect a Quarkus service call with retry and fallback.
How it connects
Connects reactive-system responsiveness with retry, fallback, bulkhead, circuit breaker, timeout, and MicroProfile Fault Tolerance.

Also explained in

Compare how 13 books explain resilience →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.