2

I want to provide new subdomains based on user request. I realized that there are two ways to do it:

  1. Using API of the DNS provider to register new CNAME records that point to pages within the website
  2. Making a wildcard *.example.com CNAME record that points to let's say example.com/subrouter which determines the domain it is being called from and returns related documents (Or mass virtual hosts on apache).

Using method 1 feels a lot more natural as I'm adhering to the original design. But method 2 is flexible and gets the job done.

Server management is not my primary field so hopefully someone will clear this up for me. Is there any reason to chose one method over the other, lets say for performance or scalability or security? Which method is preferred by the pros?

1

This type of functionality is usually handled with a DNS wildcard record.

  1. It is easier to implement.
  2. It won't hit any limits on the number of subdomains you can create.

If you use an API you have to set up the DNS and program your web server to respond to that subdomain. If you use a wildcard you only need to program your web server to respond to the subdomain and return a 404 error for all unknown subdomains.

Most DNS servers can handle tens of thousands of subdomain records. However, I wouldn't necessarily trust that your DNS provider has tested their API with even close to that many records. If there is the possibility that your service could become very popular, why take the risk of hitting limits or introducing performance problems with your DNS provider?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.