# spring-projects/spring-retry architecture

> Architecture diagram of the GitHub repository spring-projects/spring-retry, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/spring-projects/spring-retry
- Repository: https://github.com/spring-projects/spring-retry

## Overview

##### Main Components
- RetryCallback and RecoveryCallback: These encapsulate the business logic to be retried and alternative recovery logic when retries are exhausted.
- RetryContext: Show it as a component that holds retry-specific state (such as retry count and any other custom state data) used by the RetryTemplate.
- BackoffPolicy Implementations: Illustrate the different strategies used to delay between retries (for example, ExponentialBackOffPolicy, FixedBackOffPolicy, UniformRandomBackOffPolicy). Again, group these as a “backoff” layer.
- AOP Integration using the RetryOperationsInterceptor (in conjunction with @Retryable and @Recover annotations): For declarative retry, demonstrate how the interceptor wraps target service methods and delegates to the RetryTemplate.
- Supporting Utilities: Also include auxiliary packages such as “org.springframework.retry.classify” (for classifying exceptions), “org.springframework.retry.support” (for helper classes and fluent configuration builders), and “org.springframework.retry.stats” (for metrics and statistics).
- Infrastructure & Build/CI Components: Optionally include an inset depicting the GitHub Actions workflows, Maven configuration (pom.xml, mvnw, etc.) and file organization, showing that these support the build, test, and release process although they are not part of the runtime system.

##### Relationships and Interactions
– RetryPolicy: where the decision to continue or abort is made.
– BackoffPolicy: that introduces delays between re-executions.
– RetryCallback/RecoveryCallback: showing the business or fallback logic.
- RetryContext being created and updated with every attempt.

##### Architectural Patterns and Design Principles
- Template Method design pattern as used by RetryTemplate.
- Use of Strategy pattern: the interchangeable use of different RetryPolicy and BackoffPolicy implementations.
- How listeners are used as a plug-in mechanism for cross-cutting concerns (e.g., metrics collection, logging, and exception handling).
- Use of AOP for declarative retry support with annotations (@Retryable and @Recover).

##### Relevant Technologies and Frameworks
- That this library is built to integrate with Spring, referencing Spring AOP for proxy-based retry handling.
- Support for Micrometer metrics via the MetricsRetryListener.

##### Specific Elements to be Included
- Clearly labeled components:
– “Client / Service Layer” (where the retry-enabled method is defined; note if using @Retryable)
– “AOP Proxy / RetryOperationsInterceptor” (for declarative usage)
– “RetryTemplate” (core operation execution)
– “RetryPolicy (Simple, Timeout, etc.)”
– “BackoffPolicy (Exponential, Fixed, etc.)”
– “RetryContext” (manages state; show how it is passed among components)
– “RetryCallback & RecoveryCallback”
– “Listeners” (with an example such as MetricsRetryListener)
– Flow of method invocation
– Decision points (retry policy checking conditions)
– Data/exception flow and subsequent backoff delay actions.
- Optionally, a separate section for build and CI details (GitHub Actions workflows, Maven wrapper, etc.) to provide context on how the library is maintained and built.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global nodes
    A["Client / Service Layer"]:::client
    B["AOP Proxy / RetryOperationsInterceptor"]:::aop
    C["RetryTemplate"]:::core
    D["RetryOperations Interface"]:::core
    E["RetryCallback"]:::callback
    F["RecoveryCallback"]:::callback
    G["RetryContext"]:::context

    %% Subgraph: RetryPolicy Implementations
    subgraph "RetryPolicy Implementations"
        P1["SimpleRetryPolicy"]:::policy
        P2["TimeoutRetryPolicy"]:::policy
        P3["ExceptionClassifierRetryPolicy"]:::policy
    end

    %% Subgraph: BackoffPolicy Implementations
    subgraph "BackoffPolicy Implementations"
        BA1["ExponentialBackOffPolicy"]:::backoff
        BA2["FixedBackOffPolicy"]:::backoff
        BA3["UniformRandomBackOffPolicy"]:::backoff
    end

    %% Subgraph: RetryListeners
    subgraph "RetryListeners"
        L1["RetryListener"]:::listener
        L2["MetricsRetryListener"]:::listener
    end

    %% Subgraph: AOP Integration
    subgraph "AOP Integration"
        AOP1["AnnotationAwareRetryOperationsInterceptor"]:::aop
        AOP2["@Retryable"]:::aop
        AOP3["@Recover"]:::aop
        AOP4["@EnableRetry"]:::aop
    end

    %% Subgraph: Supporting Utilities
    subgraph "Supporting Utilities"
        U1["RetryTemplateBuilder"]:::util
        U2["RetryConfiguration"]:::util
    end

    %% Subgraph: Build & CI Components
    subgraph "Build & CI Components"
        CI1["GitHub Actions Workflows"]:::ci
        CI2["Maven Build Files"]:::ci
    end

    %% Relationships
    A -->|"calls-imperative" | C
    A -->|"calls-via-AOP" | B
    B -->|"delegates-to" | C
    C -->|"implements" | D
    C -->|"executes" | E
    C -->|"executes" | F
    C -->|"updates" | G

    %% RetryPolicy connections
    C -->|"applies" | P1
    C -->|"applies" | P2
    C -->|"applies" | P3

    %% BackoffPolicy connections
    C -->|"applies" | BA1
    C -->|"applies" | BA2
    C -->|"applies" | BA3

    %% Listener connections
    C -->|"notifies" | L1
    C -->|"notifies" | L2

    %% AOP Integration connections
    B -->|"uses" | AOP1
    AOP1 -->|"annotatedBy" | AOP2
    AOP1 -->|"annotatedBy" | AOP3
    AOP1 -->|"annotatedBy" | AOP4

    %% Supporting Utilities connections
    C -->|"configuresWith" | U1
    C -->|"uses" | U2

    %% Build/CI connections (contextual)
    U2 -->|"supportedBy" | CI1
    U2 -->|"builtWith" | CI2

    %% Click Events
    click C "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/support/RetryTemplate.java"
    click D "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/RetryOperations.java"
    click E "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/RetryCallback.java"
    click F "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/RecoveryCallback.java"
    click G "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/RetryContext.java"
    click P1 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java"
    click P2 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/policy/TimeoutRetryPolicy.java"
    click P3 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/policy/ExceptionClassifierRetryPolicy.java"
    click BA1 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java"
    click BA2 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/backoff/FixedBackOffPolicy.java"
    click BA3 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/backoff/UniformRandomBackOffPolicy.java"
    click L1 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/listener/RetryListener.java"
    click L2 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/support/MetricsRetryListener.java"
    click AOP1 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java"
    click AOP2 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/annotation/Retryable.java"
    click AOP3 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/annotation/Recover.java"
    click AOP4 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/annotation/EnableRetry.java"
    click U1 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/support/RetryTemplateBuilder.java"
    click U2 "https://github.com/spring-projects/spring-retry/blob/main/src/main/java/org/springframework/retry/annotation/RetryConfiguration.java"
    click CI1 "https://github.com/spring-projects/spring-retry/blob/main/.github/actions/build/action.yml"
    click CI2 "https://github.com/spring-projects/spring-retry/blob/main/pom.xml"

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:2px;
    classDef core fill:#bbf,stroke:#333,stroke-width:2px;
    classDef callback fill:#afa,stroke:#333,stroke-width:2px;
    classDef context fill:#ffdead,stroke:#333,stroke-width:2px;
    classDef policy fill:#fd8,stroke:#333,stroke-width:2px;
    classDef backoff fill:#fdd,stroke:#333,stroke-width:2px;
    classDef listener fill:#cfc,stroke:#333,stroke-width:2px;
    classDef aop fill:#ddf,stroke:#333,stroke-width:2px;
    classDef util fill:#dff,stroke:#333,stroke-width:2px;
    classDef ci fill:#fbb,stroke:#333,stroke-width:2px;
```
