Skip to content

Dynamic reconfiguration during running

reisenberger edited this page Feb 21, 2018 · 4 revisions

PolicyRegistry can also be used as a way to introduce dynamic reconfiguration of Polly policies during the running of an application.

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

PolicyRegistry is a common way of enabling that scenario, with policies configured into PolicyRegistry at startup, then extracted at call site.

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 or should be on operations that are mid-running when the configuration is updated.

PolicyRegistry provides a route to 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 raise an event when the underlying configuration source is detected to have changed.

Clone this wiki locally