We've got a Java webapp. It's a simple .war file. We allow customers to sign up for our service and they get their own URL: http://customer_name.ourdomain.com which points at a special instance of our app just for them.

We've got the system up and running on a single server, but now we need to figure out how to distribute it. When the customers sign up they're going to get assigned to a particular server. We can handle that. What I can't figure out is how to get customer_name.ourdomain.com to point to the right box.

Because we let people sign up on their own, we can't manually add CNAME records to a DNS server to map the subdomain to an IP. Plus, I don't know if a DNS server can handle the tens of thousands of customers we hope to have some day.

Is there some way to do this dynamically? I expect we'll be able to store a subdomain/ip mapping in a mysql database somewhere. Is there a DNS server that can use it? Or is there a better load-balancer front-end traffic distributor that we should be using?


Because you have control of the domain I think you have every reason to use DNS for this. Heres a couple options:

  • Run your own DNS Server and write the new A records to the zone file automatically when the user signs up. When the customer signs up via your web interface you call a Shell Script that runs via SSH on your DNS Server to write the entry to the file. Pass in variables for the customer's domain and which server you want them on.

  • Or you can use a DNS Service like www.zerigo.com and automate it via their API.

The script would would like something like:

cat > /etc/DNSSERVER/Zonefile <<-_EOF1_
IN  A   $serverip   $customername.ourdomain.com 

Pass in the variables when you execute the script (which are collected via form on your site upon signup):

./add_a_record.sh <customername>

DNS was specifically designed to handle any number of requests you can throw at it...

  • This looks like the right answer. I'll poke around and see if any of the cloud providers I might use have this sort of service. – Shef Nov 10 '10 at 20:30

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.