You don't simply host the whole site with the CDN, just your content.
I just realized I answered a similar question a while back: What does akamaihd.net do?
Image by WikiMedia
So your site references http://akamai/myfile.ext
. This will request myfile.ext
from akamai
. akamai
can then send an HTTP redirect to the actual content server.
Now, when that last step is cached, great, all future requests will go to the closest content server.
How does that work?
Let's assume this website:
<html>
<body>
<img src="http://cdn/oliver.png" />
</body>
</html>
I request this website from my own webserver. The .html
file is not hosted with cdn
. Neither is the DNS of my webserver.
Initial request
So my browser got that HTML file and now parses it. It finds the referenced image and notes that it is located at http://cdn/oliver.png
. It requests that file.
To do that, it need to find the IP address of cdn
. In our example, that IP address is 10.10.10.10
.
With that IP address, it can connect to the cdn
server and request /oliver.png
.
Geo Location
Now cdn
realizes, "that guy is from Germany!". So instead of sending me my awesome picture that I wanted, it sends me an HTTP redirect saying:
/oliver.png is not here. It's at 10.10.33.33/oliver.png
So my browser will ask 10.10.33.33
(which is hopefully closer to me) for the picture.
Seriously?
I'm not saying this is how ALL CDNs work, but it would be one approach.
You could also implement a DNS daemon that returns different results for a name lookup depending on the location of whoever sent the query.
But I doubt that this is done in practice. But maybe I just can't imagine how to properly set that up. See fluffy's answer for how that could work.
Who runs CDNs?
Most global players have their own content delivery network in a way (or so I would assume). Some providers just offload certain services to larger CDNs (like Microsoft does with MSDN downloads).
And this might somehow touch on your second subject.
Consider this, in the MSDN Microsoft offers product downloads. These downloads are then provided by Akamai. If you can determine the URL of that download, you can just download the product without ever getting in touch with Microsoft.
Is that a security issue? Not really, because what is being downloaded is still protected (by a product key).
But how about other data?
If your data is security relevant, then it isn't CDN material. If you don't want something to be available as widely as possible, don't put it in a CDN.
Say the site is http://somewebsite/file.txt . Say Akamai DNS is being used. Then does the 1st very request from client go to somewebsite or the first very request itself goes to Akamai (because somehow the DNS being used by client knows that Akamai CDN is in use)?
– p2pnode – 2012-05-05T15:46:26.457And perhaps I don't understand HTTP redirect and what they are able to achieve, so my question still remains that how does the client know to use IP address of Akamai edge servers so that Akamai central servers don't have to come into picture at all.. – p2pnode – 2012-05-05T15:48:43.460
@p2pnode: I expanded the answer a bit. Hopefully it includes what you're wondering about. – Der Hochstapler – 2012-05-05T16:02:20.523
1Isnt there a significant performance hit from this? Instead of all the data transfer happening over a single TCP stream, multiple streams are being used, more overhead from the handshaking,etc.. – Akash – 2012-05-05T18:35:21.240
@Akash: Normally, you wouldn't use a CDN for everything, but only individual, large files. So, in practice, this isn't an issue. – Der Hochstapler – 2012-05-05T18:49:26.943