Skip to content

Commit

Permalink
Add sequence diagrams to dynamic hedging
Browse files Browse the repository at this point in the history
  • Loading branch information
peter.csala committed Oct 19, 2023
1 parent c8dbe1a commit e54623c
Showing 1 changed file with 97 additions and 1 deletion.
98 changes: 97 additions & 1 deletion docs/strategies/hedging.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ sequenceDiagram
H->>+HUC: Invokes (R1)
HUC-->>HUC: Processes R1
HUC->>-H: Fails
HUC->>-H: Fails (R1)
H->>+HUC: Invokes (R2)
HUC-->>HUC: Processes R2
Expand Down Expand Up @@ -337,6 +337,102 @@ With this configuration, the hedging strategy:
- Initiates a maximum of `4` executions. This includes initial action and an additional 3 attempts.
- Allows the first two executions to proceed in parallel, while the third and fourth executions follow the fallback mode.

#### Dynamic: happy path sequence diagram

The hedging strategy triggers and switches between modes due to the usage of `DelayGenerator`. It succeeds because the last request succeeds.

```mermaid
sequenceDiagram
actor C as Caller
participant P as Pipeline
participant H as Hedging
participant DG as DelayGenerator
participant HUC as HedgedUserCallback
C->>P: Calls ExecuteAsync
P->>H: Calls ExecuteCore
activate H
Note over H: Parallel mode
par
H -> DG: Gets delay
H->>HUC: Invokes (R1)
activate HUC
and
H -> DG: Gets delay
H->>+HUC: Invokes (R2)
end
HUC-->>HUC: Processes R1
HUC-->>HUC: Processes R2
HUC->>-H: Fails (R2)
HUC->>-H: Fails (R1)
Note over H: Fallback mode
H -> DG: Gets delay
H->>+HUC: Invokes (R3)
HUC-->>HUC: Processes R3
HUC->>-H: Fails (R3)
H -> DG: Gets delay
H->>+HUC: Invokes (R4)
HUC-->>HUC: Processes R4
HUC->>-H: Returns result (R4)
deactivate H
H->>P: Returns result (R4)
P->>C: Returns result (R4)
```

#### Dynamic: unhappy path sequence diagram

The hedging strategy triggers and switches between modes due to the usage of `DelayGenerator`. It fails because all requests fail.

```mermaid
sequenceDiagram
actor C as Caller
participant P as Pipeline
participant H as Hedging
participant DG as DelayGenerator
participant HUC as HedgedUserCallback
C->>P: Calls ExecuteAsync
P->>H: Calls ExecuteCore
activate H
Note over H: Parallel mode
par
H -> DG: Gets delay
H->>HUC: Invokes (R1)
activate HUC
and
H -> DG: Gets delay
H->>+HUC: Invokes (R2)
end
HUC-->>HUC: Processes R1
HUC-->>HUC: Processes R2
HUC->>-H: Fails (R2)
HUC->>-H: Fails (R1)
Note over H: Fallback mode
H -> DG: Gets delay
H->>+HUC: Invokes (R3)
HUC-->>HUC: Processes R3
HUC->>-H: Fails (R3)
H -> DG: Gets delay
H->>+HUC: Invokes (R4)
HUC-->>HUC: Processes R4
HUC->>-H: Fails (R4)
deactivate H
H->>P: Propagates failure (R3)
P->>C: Propagates failure (R3)
```

## Action generator

The hedging options include an `ActionGenerator` property, allowing you to customize the actions executed during hedging. By default, the `ActionGenerator` returns the original callback passed to the strategy. The original callback also includes any logic introduced by subsequent resilience strategies. For more advanced scenarios, the `ActionGenerator` can be used to return entirely new hedged actions, as demonstrated in the example below:
Expand Down

0 comments on commit e54623c

Please sign in to comment.