backend_dyn -- create and delete backends at runtime

Provides functions to create and delete backends at runtime. This means that backends can be created at any time while Varnish is running without reloading VCL, and that backends created by the VMOD can also be deleted by the VMOD at runtime.

Backends created by the VMOD are the same as backends defined by static declarations with the backend keyword, and they have the same configuration parameters with the same default values. Once created, a backend can be added to a director or assigned as a value of req.backend_hint or bereq.backend. Backends created by the VMOD are accessed by the finder method by_name, using the name string assigned at creation.

Once deleted, a backend is no longer in use by Varnish — it is not selected by any director to which it may have been added, and is no longer returned by by_name.


import backend_dyn;
import directors;

probe p { .url = "/"; }

sub vcl_init {
# Backends can be created at VCL initialization.
 # The required parameters set a backend name and its host.
 # create() returns false if backend creation was unsuccessful.
 if (!backend_dyn.create(name="be1", host="")) {

 # Dynamic backends may be added to directors.
 # by_name() returns the backend created with the given name.
 new rr = directors.round_robin();

 # Backend creation supports all of the optional configuration
 # parameters available to static backend declarations; these
 # have the same default values as for a static declaration if
 # left unspecified.
 if (!backend_dyn.create(name="be1", host="",
  port="8080", probe=p,
  connect_timeout=1s, first_byte_timeout=2s,
  max_connections=100)) {

 # Backends can also be deleted at VCL initialization.
 # delete() returns false if backend deletion was unsuccessful.
 # A deleted backend is no longer selected by any director to
 # which it was previously added.
 if (!backend_dyn.delete(backend_dyn.by_name("be1"))) {

sub vcl_recv {
# Backends can be created and deleted in any VCL subroutine.
if (req.method == "PUT") {
if (!backend_dyn.create(name="be2", host="")) {
if (req.method == "DELETE") {
if (!backend_dyn.delete(backend_dyn.by_name("be2"))) {
set req.backend_hint = backend_dyn.by_name("be2");

sub vcl_backend_fetch {
set bereq.backend = backend_dyn.by_name("be2");

In development
Varnish version supported: 
Commercial support: