

# Restart Strategies

Flink supports different restart strategies which control how the jobs are restarted in case of a failure. The cluster can be started with a default restart strategy which is always used when no job specific restart strategy has been defined. In case that the job is submitted with a restart strategy, this strategy overrides the cluster’s default setting.

## Overview

The default restart strategy is set via Flink’s configuration file `flink-conf.yaml`. The configuration parameter _restart-strategy_ defines which strategy is taken. If checkpointing is not enabled, the “no restart” strategy is used. If checkpointing is activated and the restart strategy has not been configured, the fixed-delay strategy is used with `Integer.MAX_VALUE` restart attempts. See the following list of available restart strategies to learn what values are supported.

Each restart strategy comes with its own set of parameters which control its behaviour. These values are also set in the configuration file. The description of each restart strategy contains more information about the respective configuration values.

| Restart Strategy | Value for restart-strategy |
| --- | --- |
| Fixed delay | fixed-delay |
| Failure rate | failure-rate |
| No restart | none |

Apart from defining a default restart strategy, it is possible to define for each Flink job a specific restart strategy. This restart strategy is set programmatically by calling the `setRestartStrategy` method on the `ExecutionEnvironment`. Note that this also works for the `StreamExecutionEnvironment`.

The following example shows how we can set a fixed delay restart strategy for our job. In case of a failure the system tries to restart the job 3 times and waits 10 seconds in-between successive restart attempts.



```
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setRestartStrategy(RestartStrategies.fixedDelayRestart(
  3, // number of restart attempts
  Time.of(10, TimeUnit.SECONDS) // delay
));
```





```
val env = ExecutionEnvironment.getExecutionEnvironment()
env.setRestartStrategy(RestartStrategies.fixedDelayRestart(
  3, // number of restart attempts
  Time.of(10, TimeUnit.SECONDS) // delay ))
```



## Restart Strategies

The following sections describe restart strategy specific configuration options.

### Fixed Delay Restart Strategy

The fixed delay restart strategy attempts a given number of times to restart the job. If the maximum number of attempts is exceeded, the job eventually fails. In-between two consecutive restart attempts, the restart strategy waits a fixed amount of time.

This strategy is enabled as default by setting the following configuration parameter in `flink-conf.yaml`.



```
restart-strategy: fixed-delay
```



| Configuration Parameter | Description | Default Value |
| --- | --- | --- |
| `restart-strategy.fixed-delay.attempts` | The number of times that Flink retries the execution before the job is declared as failed. | 1, or `Integer.MAX_VALUE` if activated by checkpointing |
| `restart-strategy.fixed-delay.delay` | Delaying the retry means that after a failed execution, the re-execution does not start immediately, but only after a certain delay. Delaying the retries can be helpful when the program interacts with external systems where for example connections or pending transactions should reach a timeout before re-execution is attempted. | `akka.ask.timeout`, or 10s if activated by checkpointing |

For example:



```
restart-strategy.fixed-delay.attempts: 3
restart-strategy.fixed-delay.delay: 10 s
```



The fixed delay restart strategy can also be set programmatically:



```
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setRestartStrategy(RestartStrategies.fixedDelayRestart(
  3, // number of restart attempts
  Time.of(10, TimeUnit.SECONDS) // delay
));
```





```
val env = ExecutionEnvironment.getExecutionEnvironment()
env.setRestartStrategy(RestartStrategies.fixedDelayRestart(
  3, // number of restart attempts
  Time.of(10, TimeUnit.SECONDS) // delay ))
```



### Failure Rate Restart Strategy

The failure rate restart strategy restarts job after failure, but when `failure rate` (failures per time interval) is exceeded, the job eventually fails. In-between two consecutive restart attempts, the restart strategy waits a fixed amount of time.

This strategy is enabled as default by setting the following configuration parameter in `flink-conf.yaml`.



```
restart-strategy: failure-rate
```



| Configuration Parameter | Description | Default Value |
| --- | --- | --- |
| &lt;it&gt;restart-strategy.failure-rate.max-failures-per-interval&lt;/it&gt; | Maximum number of restarts in given time interval before failing a job | 1 |
| &lt;it&gt;restart-strategy.failure-rate.failure-rate-interval&lt;/it&gt; | Time interval for measuring failure rate. | 1 minute |
| &lt;it&gt;restart-strategy.failure-rate.delay&lt;/it&gt; | Delay between two consecutive restart attempts | &lt;it&gt;akka.ask.timeout&lt;/it&gt; |



```
restart-strategy.failure-rate.max-failures-per-interval: 3
restart-strategy.failure-rate.failure-rate-interval: 5 min
restart-strategy.failure-rate.delay: 10 s
```



The failure rate restart strategy can also be set programmatically:



```
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setRestartStrategy(RestartStrategies.failureRateRestart(
  3, // max failures per interval
  Time.of(5, TimeUnit.MINUTES), //time interval for measuring failure rate
  Time.of(10, TimeUnit.SECONDS) // delay
));
```





```
val env = ExecutionEnvironment.getExecutionEnvironment()
env.setRestartStrategy(RestartStrategies.failureRateRestart(
  3, // max failures per unit
  Time.of(5, TimeUnit.MINUTES), //time interval for measuring failure rate
  Time.of(10, TimeUnit.SECONDS) // delay ))
```



### No Restart Strategy

The job fails directly and no restart is attempted.



```
restart-strategy: none
```



The no restart strategy can also be set programmatically:



```
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setRestartStrategy(RestartStrategies.noRestart());
```





```
val env = ExecutionEnvironment.getExecutionEnvironment()
env.setRestartStrategy(RestartStrategies.noRestart())
```



### Fallback Restart Strategy

The cluster defined restart strategy is used. This helpful for streaming programs which enable checkpointing. Per default, a fixed delay restart strategy is chosen if there is no other restart strategy defined.

