|
| 1 | +--- |
| 2 | +type: docs |
| 3 | +title: "Default resiliency policies" |
| 4 | +linkTitle: "Default policies" |
| 5 | +weight: 40 |
| 6 | +description: "Learn more about the default resiliency policies for timeouts, retries, and circuit breakers" |
| 7 | +--- |
| 8 | + |
| 9 | +In resiliency, you can set default policies, which have a broad scope. This is done through reserved keywords that let Dapr know when to apply the policy. There are 3 default policy types: |
| 10 | + |
| 11 | +- `DefaultRetryPolicy` |
| 12 | +- `DefaultTimeoutPolicy` |
| 13 | +- `DefaultCircuitBreakerPolicy` |
| 14 | + |
| 15 | +If these policies are defined, they are used for every operation to a service, application, or component. They can also be modified to be more specific through the appending of additional keywords. The specific policies follow the following pattern, `Default%sRetryPolicy`, `Default%sTimeoutPolicy`, and `Default%sCircuitBreakerPolicy`. Where the `%s` is replaced by a target of the policy. |
| 16 | + |
| 17 | +Below is a table of all possible default policy keywords and how they translate into a policy name. |
| 18 | + |
| 19 | +| Keyword | Target Operation | Example Policy Name | |
| 20 | +| -------------------------------- | ---------------------------------------------------- | ----------------------------------------------------------- | |
| 21 | +| `App` | Service invocation. | `DefaultAppRetryPolicy` | |
| 22 | +| `Actor` | Actor invocation. | `DefaultActorTimeoutPolicy` | |
| 23 | +| `Component` | All component operations. | `DefaultComponentCircuitBreakerPolicy` | |
| 24 | +| `ComponentInbound` | All inbound component operations. | `DefaultComponentInboundRetryPolicy` | |
| 25 | +| `ComponentOutbound` | All outbound component operations. | `DefaultComponentOutboundTimeoutPolicy` | |
| 26 | +| `StatestoreComponentOutbound` | All statestore component operations. | `DefaultStatestoreComponentOutboundCircuitBreakerPolicy` | |
| 27 | +| `PubsubComponentOutbound` | All outbound pubusub (publish) component operations. | `DefaultPubsubComponentOutboundRetryPolicy` | |
| 28 | +| `PubsubComponentInbound` | All inbound pubsub (subscribe) component operations. | `DefaultPubsubComponentInboundTimeoutPolicy` | |
| 29 | +| `BindingComponentOutbound` | All outbound binding (invoke) component operations. | `DefaultBindingComponentOutboundCircuitBreakerPolicy` | |
| 30 | +| `BindingComponentInbound` | All inbound binding (read) component operations. | `DefaultBindingComponentInboundRetryPolicy` | |
| 31 | +| `SecretstoreComponentOutbound` | All secretstore component operations. | `DefaultSecretstoreComponentTimeoutPolicy` | |
| 32 | +| `ConfigurationComponentOutbound` | All configuration component operations. | `DefaultConfigurationComponentOutboundCircuitBreakerPolicy` | |
| 33 | +| `LockComponentOutbound` | All lock component operations. | `DefaultLockComponentOutboundRetryPolicy` | |
| 34 | + |
| 35 | +## Policy hierarchy resolution |
| 36 | + |
| 37 | +Default policies are applied if the operation being executed matches the policy type and if there is no more specific policy targeting it. For each target type (app, actor, and component), the policy with the highest priority is a Named Policy, one that targets that construct specifically. |
| 38 | + |
| 39 | +If none exists, the policies are applied from most specific to most broad. |
| 40 | + |
| 41 | +## How default policies and built-in retries work together |
| 42 | + |
| 43 | +In the case of the [built-in retries]({{< ref override-default-retries.md >}}), default policies do not stop the built-in retry policies from running. Both are used together but only under specific circumstances. |
| 44 | + |
| 45 | +For service and actor invocation, the built-in retries deal specifically with issues connecting to the remote sidecar (when needed). As these are important to the stability of the Dapr runtime, they are not disabled **unless** a named policy is specifically referenced for an operation. In some instances, there may be additional retries from both the built-in retry and the default retry policy, but this prevents an overly weak default policy from reducing the sidecar's availability/success rate. |
| 46 | + |
| 47 | +Policy resolution hierarchy for applications, from most specific to most broad: |
| 48 | + |
| 49 | +1. Named Policies in App Targets |
| 50 | +2. Default App Policies / Built-In Service Retries |
| 51 | +3. Default Policies / Built-In Service Retries |
| 52 | + |
| 53 | +Policy resolution hierarchy for actors, from most specific to most broad: |
| 54 | + |
| 55 | +1. Named Policies in Actor Targets |
| 56 | +2. Default Actor Policies / Built-In Actor Retries |
| 57 | +3. Default Policies / Built-In Actor Retries |
| 58 | + |
| 59 | +Policy resolution hierarchy for components, from most specific to most broad: |
| 60 | + |
| 61 | +1. Named Policies in Component Targets |
| 62 | +2. Default Component Type + Component Direction Policies / Built-In Actor Reminder Retries (if applicable) |
| 63 | +3. Default Component Direction Policies / Built-In Actor Reminder Retries (if applicable) |
| 64 | +4. Default Component Policies / Built-In Actor Reminder Retries (if applicable) |
| 65 | +5. Default Policies / Built-In Actor Reminder Retries (if applicable) |
| 66 | + |
| 67 | +As an example, take the following solution consisting of three applications, three components and two actor types: |
| 68 | + |
| 69 | +Applications: |
| 70 | + |
| 71 | +- AppA |
| 72 | +- AppB |
| 73 | +- AppC |
| 74 | + |
| 75 | +Components: |
| 76 | + |
| 77 | +- Redis Pubsub: pubsub |
| 78 | +- Redis statestore: statestore |
| 79 | +- CosmosDB Statestore: actorstore |
| 80 | + |
| 81 | +Actors: |
| 82 | + |
| 83 | +- EventActor |
| 84 | +- SummaryActor |
| 85 | + |
| 86 | +Below is policy that uses both default and named policies as applies these to the targets. |
| 87 | + |
| 88 | +```yaml |
| 89 | +spec: |
| 90 | + policies: |
| 91 | + retries: |
| 92 | + # Global Retry Policy |
| 93 | + DefaultRetryPolicy: |
| 94 | + policy: constant |
| 95 | + duration: 1s |
| 96 | + maxRetries: 3 |
| 97 | + |
| 98 | + # Global Retry Policy for Apps |
| 99 | + DefaultAppRetryPolicy: |
| 100 | + policy: constant |
| 101 | + duration: 100ms |
| 102 | + maxRetries: 5 |
| 103 | + |
| 104 | + # Global Retry Policy for Apps |
| 105 | + DefaultActorRetryPolicy: |
| 106 | + policy: exponential |
| 107 | + maxInterval: 15s |
| 108 | + maxRetries: 10 |
| 109 | + |
| 110 | + # Global Retry Policy for Inbound Component operations |
| 111 | + DefaultComponentInboundRetryPolicy: |
| 112 | + policy: constant |
| 113 | + duration: 5s |
| 114 | + maxRetries: 5 |
| 115 | + |
| 116 | + # Global Retry Policy for Statestores |
| 117 | + DefaultStatestoreComponentOutboundRetryPolicy: |
| 118 | + policy: exponential |
| 119 | + maxInterval: 60s |
| 120 | + maxRetries: -1 |
| 121 | + |
| 122 | + # Named policy |
| 123 | + fastRetries: |
| 124 | + policy: constant |
| 125 | + duration: 10ms |
| 126 | + maxRetries: 3 |
| 127 | + |
| 128 | + # Named policy |
| 129 | + retryForever: |
| 130 | + policy: exponential |
| 131 | + maxInterval: 10s |
| 132 | + maxRetries: -1 |
| 133 | + |
| 134 | + targets: |
| 135 | + apps: |
| 136 | + appA: |
| 137 | + retry: fastRetries |
| 138 | + |
| 139 | + appB: |
| 140 | + retry: retryForever |
| 141 | + |
| 142 | + actors: |
| 143 | + EventActor: |
| 144 | + retry: retryForever |
| 145 | + |
| 146 | + components: |
| 147 | + actorstore: |
| 148 | + retry: fastRetries |
| 149 | +``` |
| 150 | +
|
| 151 | +The table below is a break down of which policies are applied when attempting to call the various targets in this solution. |
| 152 | +
|
| 153 | +| Target | Policy Used | |
| 154 | +| ------------------ | ----------------------------------------------- | |
| 155 | +| AppA | fastRetries | |
| 156 | +| AppB | retryForever | |
| 157 | +| AppC | DefaultAppRetryPolicy / DaprBuiltInActorRetries | |
| 158 | +| pubsub - Publish | DefaultRetryPolicy | |
| 159 | +| pubsub - Subscribe | DefaultComponentInboundRetryPolicy | |
| 160 | +| statestore | DefaultStatestoreComponentOutboundRetryPolicy | |
| 161 | +| actorstore | fastRetries | |
| 162 | +| EventActor | retryForever | |
| 163 | +| SummaryActor | DefaultActorRetryPolicy | |
| 164 | +
|
| 165 | +## Next steps |
| 166 | +
|
| 167 | +[Learn how to override default retry policies.]({{< ref override-default-retries.md >}}) |
| 168 | +
|
| 169 | +## Related links |
| 170 | +
|
| 171 | +Try out one of the Resiliency quickstarts: |
| 172 | +- [Resiliency: Service-to-service]({{< ref resiliency-serviceinvo-quickstart.md >}}) |
| 173 | +- [Resiliency: State Management]({{< ref resiliency-state-quickstart.md >}}) |
0 commit comments