Subdomain to origin lookup/mapping, how?

For a SaaS product i’m currently building, i’m looking for the best way to map a customers subdomain (or their own cnamed domain) to a specific origin server. I want to have multiple isolated backend clusters to spread load and to deploy them close to the user geographically.

  • The easiest solution would be to create a dns record per customer and point it to the right origin. But as far as i can see the number of records is limited and will not support 10000+ subdomains.

  • Another option would be to run everything on workers and write some javascript that does the lookup using the D1 database and proxy to the origin. But running workers for every single request could become costly in the future.

  • Is there another easier/better option i’m missing here?

The solution should support 10k+ customers/subdomains, 10-20 origins, custom hostnames, and the ability to move a customer to another origin.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.