
Ask HN: How does a service like CloudFlare work? - jason_slack
So I am curious as to how a service like CloudFlare works?<p>So it seems like:<p>1. You have to change your DNS.<p>2. The traffic intended for your site now funnels through CloudFlare servers<p>3. They then direct the traffic to your hardware/where your site lives.<p>But they advertise things like increasing availability, protection, distributed content, etc.<p>How is this working?
======
paulsutter
You just answered your own question, it works just the way you explained.

Are you asking how is the benefit created? Speed of light latency is a real
issue. A metro area round trip is a few milliseconds, a coast to coast packet
round trip is 75 to 100ms, and across continents can be 400ms. It takes many
many round trips to serve a web page.

If they have servers located all over the globe, those servers can cache all
the static elements on your pages (most of the elements like gifs and CSS) and
serve those very quickly to end users, while only the dynamic components need
to come down the long path from your server

Further, they can tweak window sizes when they fetch the dynamic elements from
your server and therefore use fewer of the slow round trips when fetching
those elements.

~~~
jason_slack
can you explain a bit about caching of the static items around the globe?

So a user in France tries to hit my site they get to CloudFlare.

CloudFlare says here is part of the site to serve.

The dynamic elements then get passed through to my server for what needs to be
displayed.

So do they then have a virtual host type setup for my domain (and all of their
customers) so they then answer on it and run something like Varnish Cache?

~~~
paulsutter
The way it probably works is that they have servers around the world, and
either use a geographic DNS or IP anycast.

So the user in France contacts their nearest server and requsts the url for
the resource. If the file has already been cached there at that server, they
serve it. Otherwise, that server requests it from your origin server, and
serves it that end user in France.

They wouldnt set up any specific virtual host for you. They just have an http
server that receives all the requests, and dispatches internally based on the
domain name in the url.

I get the impression that I'm going into more detail than you want.

What is it that you're concerned about?

~~~
jason_slack
No this is the details I really want. I really like to understand technically
what is going on before I use a service. So far Cloud Flare has not returned
my requests for a "Sales" talk. I am just not going to turn over my NPO stuff
to them without understanding!

Can you explain how they would dispatch the traffic internally without a
Virtual host? a rewrite rule, perhaps?

How do they get my static content? Do they just wget or curl it? Do I provide
it? I assume it has expiration so if I change my CSS users dont get served the
old stuff for very long?

We could e-mail privately if you dont mind too. My e-mail is in my profile.

~~~
paulsutter
I suggest learning about HTTP and DNS first. The easiest starting point might
be to install firebug so that you can see what's really happening between a
browser and a web server.

In short, when the server receives the raw request, the targeted domain name
and path are included in the headers. With that raw request its pretty easy to
do whatever they need.

Honestly, I dont really know what virtual hosts or rewrite rules are. These
sound like specific features of web frameworks rather than anything inherent
about the internet.

Feel free to ask me questions by email. Also don't be afraid to say if you
want to implement something similar. It isn't hard to do.

