Matteo Monti
Matteo Monti

Reputation: 8930

Load balancing between peers with DNS and javascript

Let's do a thought experiment (clearly, this is not a real case scenario). Say that:

Now, say that I want to use this swarm to keep online (the static part of) a very popular website (millions and millions of users). What I do is as follows:

I made an actual experiment with a network of a dozen of peers, and worked smoothly. If the peers are close to my current location, loading resources from peers is actually faster than loading from my server. So good.

Now, I would like to think how can I do load balancing among all these servers with DNS. Of course, relying on round robin DNS will be a suicide: I definitely can't have a single domain with millions of A records in it.

So here is my idea, and I wonder if in principle this could work.

In my mind this should work, but I could see some problems. The first that comes to my mind is: will caching DNS servers get angry at me? Say: Google's 4.4.4.4 will receive millions of requests to millions of distinct random subdomains of my domain. Will it eventually block it or stop responding or something?

Are there potentially other problems in doing this? Are there better ways of doing this? Is this completely unfeasible even from a theoretical standpoint?

Upvotes: 3

Views: 344

Answers (1)

Michael B
Michael B

Reputation: 12228

The core concept behind DNS is that for every addressable IP Address you have, you have a corresponding A record. This stands to logic, as every server can only have a single hostname, and DNS is about hostnames.

However, sometimes you don't want the hostname to be the name that people connect to, so instead you would use a CNAME which is the Canonical name (in this case, canonical as in authorative) for the Alias (obviously calling those an Alias might be confused with A records)

So if you are looking at Example.com you might have

fred  IN  A 192.168.0.1
alice IN  A 192.168.0.2 
bob   IN  A 192.168.0.3
www   IN  CNAME bob.example.com
web   IN  CNAME www.example.com

So unless you are actually deploying millions of servers with unique IP Addresses (if this is the case, I am very curious where you got them from and who you are!) If however you have x number of hosts and you want to provide host names for them to be connected to on the fly, then you actually want to be configuring CNAME records.

One of the interesting parts about CNAME records is that you can set up multiple redirects with them so you can layer a hierarchy with them, which you couldn't do with A records.

If you are following the rules of DNS there is no reason that google et al should have any problem with however many names you use.

An excellent place to start understanding the complexities of DNS is the Dragonfly book

Edited to add

If these are machines on the internet then it is perfectly acceptable to give each an A record / hostname (I'm presuming this is what you mean by subdomain)

There is no reason that you couldn't then give each A record a CNAME record.

From the perspective of DNS I see no reason that you couldn't provide load balancing in this way. You would perhaps want a test prior to sending the CNAME record to ensure that the endpoint is online. But the concept of using CNAME records to load balance certainly isn't a new one. i.e. CDNs

Upvotes: 1

Related Questions