Skip to content

Dynamic reconfiguration during running

martincostello edited this page Sep 28, 2023 · 4 revisions

Dynamic reconfiguration during running

ℹ️ This documentation describes the previous Polly v7 API. If you are using the new v8 API, please refer to pollydocs.org.

A typical pattern with Polly is to configure policies once at startup, then apply those policies around the application where needed.

PolicyRegistry commonly enables this scenario. Policies can be configured centrally, once, at startup, and placed into an instance of PolicyRegistry. That instance of PolicyRegistry can then supplied to call sites by dependency injection.

Using PolicyRegistry for dynamic reconfiguration during running

A natural extension of this pattern is to use a PolicyRegistry for dynamic reconfiguration during running.

In some applications, it can be useful to have the ability to reconfigure policies dynamically without the disturbance of restarting the process to pick up new configuration. For example, you may want to tweak circuit-breaking thresholds to be more or less sensitive according to conditions in production.

Polly policies however were intentionally designed so that a policy's configuration is immutable: this avoids pitfalls which could arise with mutable configuration such as how to update the configuration atomically; and what the effect might be or should be on operations that are mid-running when configuration is updated.

Using PolicyRegistry enables dynamic reconfiguration in that you can simply replace the policy in the registry with a new one, when the underlying configuration source is detected to have changed. Next time the call site pulls the policy from the registry, it will pull the newly configured version.

This works particularly well with configuration sources which can notify when the underlying configuration source has changed. This can be by raising an event, providing an Observable, or via an Http endpoint which is called when changes occur.

Clone this wiki locally