The most flexible option is to implement a dynamic upstreams module. That would let you do any logic you need to parse the URL and do a lookup in your KV store for the correct upstream to use. See Extending Caddy — Caddy Documentation to learn how to write plugins for Caddy. Look at Caddy’s source code to see how the existing dynamic upstreams modules are implemented, you can pretty much copy-paste one of those as your starting point.