This document discusses using the vmod_kvstore module in Varnish to efficiently route requests for a content delivery network (CDN) with a million virtual hosts (vhosts).
The traditional approach of using if/else statements in VCL does not scale well for this use case. vmod_kvstore allows storing the mapping of host headers to backends in an in-memory hash table for O(1) lookups. This avoids recompiling the large VCL and improves reload performance. Benchmarking showed vmod_kvstore could route requests for 20,000 vhosts much faster than traditional VCL. The key-value store also enables features like caching time overrides and alias mappings per vhost.