Loadbalancing and failover in code

I have HTTPS based webservices (not REST, rather old code). I am generating Java client stubs using Axis & using that to call the webservices. There are around 20 different APIs on the webservice.

I have 2 servers hosting the webservices (identical – 2 servers are being used for redundancy) and data is synced between the 2 servers – so that same API called either server produces the same result).

I do not have hardware or software load balancers or clusters.

So I am planning to implement the failover & loadbalancing in code (the failover is important, it’s OK even if I don’t do load balancing).

I was planning to do this in code
i.e if I get a connect exception, I will trap the exception and do the same Webservice call on the other server.

I was wondering if there are any known design patterns for this or any pitfalls I should be aware of.

When I first read your description i wasn’t sure where you planned to handle the exception, but after re-reading I am going to assume you are handling the failover in the client library. There are some JMS libraries that do something like this, so it isn’t an unreasonable method. However, I would consider the following:

  • is each client going to have a preferred server, and only swap if that server goes down?
  • once a client picks a server that is working, will it ever switch?
  • if you pick a server that works, do you stick to it?

Basically, depending on how you answer these questions I could see all of the clients getting stuck on one server if the other has small hiccup. In which case, you basically have fail-over but not load balancing.

If you swap servers randomly every request, then you have a performance problem if one server goes down.

The other big issue i can see is that if you hard code the server list into the client library then it is hard to change. It would be better to load the list from somewhere, or not at all, which is why load balancers are nice, in that they hide that list from the client completely. Assuming you want to keep the entire implementation in the client, i would make sure to make the list configurable from outside the library. As i mentioned, some JMS providers take a comma separated list of URLs for the server. You might try something like that, or take an array of URLs, or even a JSON configuration or similar.

So not totally an answer but some things to think about.

I am also assuming that you are talking about effectively calling the API from the client and not about the 2 servers you have.
You cannot do a load balancing at the client side, because you would never know the load on each of the server, if you even look at connection time out or turn around time, you are not aware it is because of the load or because of network failures. Best is to alternatively call each servers, if at all you would like to do so.

For failover, the above suggestion holds well, where in you can inject the urls from outside.
Whenever there is a connection failure, you may not need to re-try every time. instead you can also have a ping service, which pings the server every configured time and updates a common location about the status of the server and thus would help you to create and connect to the server which is available. Else you would end up making a wrong connection every time from your actual working code.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Loadbalancing and failover in code

I have HTTPS based webservices (not REST, rather old code). I am generating Java client stubs using Axis & using that to call the webservices. There are around 20 different APIs on the webservice.

I have 2 servers hosting the webservices (identical – 2 servers are being used for redundancy) and data is synced between the 2 servers – so that same API called either server produces the same result).

I do not have hardware or software load balancers or clusters.

So I am planning to implement the failover & loadbalancing in code (the failover is important, it’s OK even if I don’t do load balancing).

I was planning to do this in code
i.e if I get a connect exception, I will trap the exception and do the same Webservice call on the other server.

I was wondering if there are any known design patterns for this or any pitfalls I should be aware of.

When I first read your description i wasn’t sure where you planned to handle the exception, but after re-reading I am going to assume you are handling the failover in the client library. There are some JMS libraries that do something like this, so it isn’t an unreasonable method. However, I would consider the following:

  • is each client going to have a preferred server, and only swap if that server goes down?
  • once a client picks a server that is working, will it ever switch?
  • if you pick a server that works, do you stick to it?

Basically, depending on how you answer these questions I could see all of the clients getting stuck on one server if the other has small hiccup. In which case, you basically have fail-over but not load balancing.

If you swap servers randomly every request, then you have a performance problem if one server goes down.

The other big issue i can see is that if you hard code the server list into the client library then it is hard to change. It would be better to load the list from somewhere, or not at all, which is why load balancers are nice, in that they hide that list from the client completely. Assuming you want to keep the entire implementation in the client, i would make sure to make the list configurable from outside the library. As i mentioned, some JMS providers take a comma separated list of URLs for the server. You might try something like that, or take an array of URLs, or even a JSON configuration or similar.

So not totally an answer but some things to think about.

I am also assuming that you are talking about effectively calling the API from the client and not about the 2 servers you have.
You cannot do a load balancing at the client side, because you would never know the load on each of the server, if you even look at connection time out or turn around time, you are not aware it is because of the load or because of network failures. Best is to alternatively call each servers, if at all you would like to do so.

For failover, the above suggestion holds well, where in you can inject the urls from outside.
Whenever there is a connection failure, you may not need to re-try every time. instead you can also have a ping service, which pings the server every configured time and updates a common location about the status of the server and thus would help you to create and connect to the server which is available. Else you would end up making a wrong connection every time from your actual working code.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật