I've been wondering for a while; how does websites like facebook code to be able to have multiple servers? 

How can the code take in account that several servers will be running the same code and gain from adding more?

Or does the webserver perhaps deal with this regardless of the code?