18

I have a domain set up on my hosting account, which is a shared host.

It has been doing fine, but as the site becomes more popular the response times are getting slower and slower, and sometimes gives 503 error (it's an API, so people are hitting it and need a speedy response time).

It's got to the point now where the shared host is buckling. So I have purchased a VPS which should be able to handle the load.

My question is, instead of directing all traffic to this VPS, is there a way of distributing it between the two?

If I can have 2 A records, how does the browser determine which one it visits first?

2
  • 2
  • yes, but as others have said, it will randomly send traffic to both, and can totally break sessions and other thing that rely on state being maintained on the server. as for which one it visits. bind will return the A records in random order and in most cases the browser just takes the top one. But also if one goes down, is slow. X% (50 in a perfect world) of the requests will go to the down/overloaded server
    – Doon
    Aug 5, 2013 at 14:09

2 Answers 2

27

Yes you can.

It is called round-robin DNS, and the browser just chooses one of them randomly.

It is a well used method of getting cheap load balancing, but if one host goes down, users will still try to access it.

4
  • +1 Thought the browser doesn't (usually) do the choosing, the result is essentially random.
    – Chris S
    Aug 5, 2013 at 14:14
  • ok that makes a lot of sense, thanks a lot for your help. I may need to re-think how I handle this then :) Aug 5, 2013 at 14:31
  • It would be much better if it would happend sequentially not randomly
    – Black
    Jun 2, 2022 at 7:01
  • This happened to me today! I unknowingly registered the same A record twice for different IPs and didn't notice it, and my provider didn't tell me either. I was debugging for like 3 hours until I did a ping check that always yielded an IP I didn't know. At that time I still thought that this way my provider automatically loadbalancing the traffic. But what do you know? Now after 3 hours of debugging I used the site check-host.net/check-ping to realize it is assigning different IPs at random, which made me curious, so I checked my DNS configuration and oh MY GOD! I configured it TWICE! Feb 28 at 23:34
2

To be more precise, you can't add "2 different A-records", but you can always add multiple IP addresses to point to the same domain name under a single record set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.