Why/When to have a separate media server for images, mp3s, flvs etc?

(I was just about to submit the answer on stakoverflow when you moved it to ServerFault :-) ).

The basic idea is that you want to have different servers optimized to do one thing very well. I.e. if you have an application server running code / storing state, etc, you want to optimize your hardware for that purpose - i.e. good CPU and lots of memory.

On the other hand, you don't want your server to also use its resources for mundane things like storing files. You can have another (media) server that just has a simpler server that serves static files, and has a huge networking pipe connected to it (since it's likely.

This also allows you to scale better - you can scale your application servers, i.e. the computationally expensive parts, separately from your dumb parts (the parts that serve content). This way, for example, if you have the same number of users who all of a sudden start spending more time on your site and watching longer videos, you can increase the number of media servers, without having to worry about your application servers.

So as far as to give you advice - I'd suggest you take a look at your infrastructure, at your timeframes, and at how much further you expect your site to grow. If you think you'll grow by a factor of 10 or 100, then it might be worth to think about longer term, in which case having dedicated serves will be a good idea. Figure out how difficult it will be to achieve, and whether you can take small steps towards it (i.e. make sure all media is in a separate folder and all your links are programmatic - i.e. easily repointed to another server, etc).


In your case (a youtube clone where you're serving up user-provided content) the most compelling reason may be mitigating's Flash's various cross-domain-security-policy issues. If not using a separate physical server for your media, you should consider serving your media from a separate domain. See these for explanations including how one might exploit this in practice:

  • http://www.jamesward.com/2009/11/08/how-bad-crossdomain-policies-expose-protected-data-to-malicious-applications/
  • http://www.foregroundsecurity.com/MyBlog/flash-origin-policy-issues.html
  • http://code.google.com/p/doctype/wiki/ArticleFlashSecurityPolicyAttack

Here's a relevant tale regarding Facebook and MySpace:

  • http://www.techcrunch.com/2009/11/05/massive-facebook-and-myspace-flash-vulnerability-exposes-user-data/

I am not good at this stuff but i checked it out months ago when i planned out my site (still in development). From what i remember you want to because

  • You can only have 2 connections to a domain. Having a subdomain allows more connections because they are 'different' websites. One connection is for the main page and the other is for XMLHttpRequest

  • Specialized Servers. You can have a server that may hold ALL your media, another that process uploads or handles everything involving a database. By using a different domain you can have it point to a specialized server if you ever wanted to

  • Optimization. You dont need this unless you have many hits. If your site has cookies a browser send it every time it request a page. If you had to load thousands of images in a page or two the browser will send the cookies everytime (if its small it probably wouldnt matter. But some sites have LARGE cookies). Using another domain with no cookies can speed it up.