Our APIs are designed to support very high levels of load - at peak periods we are processing many thousands of requests per minute. Our systems are designed to balance load across a large cluster of servers, and we 'AutoScale' our infrastructure to ensure that we are able to continue responding to API requests even at the highest levels of demand.
In order to achieve optimal balancing of the load, our systems will respond with a HTTP '503 - Server Busy ' error message on occasions, when your requests are directed to a particularly busy server in our cluster. This can also occur when we are scaling up our system due to a sudden surge in demand. If you are accessing the API through a web browser, this message may be interpreted to display a 'Service Unavailable' error message,
This behaviour is by design.
If your application receives a '503 - Server Busy' response, you will need to automatically retry your request after a short period of time. Subsequent requests will be sent to a different server in the cluster, and should receive a valid response. You may need to retry up to 5 times at busy periods, however we do not restrict the total number of retries, should your application require a guaranteed response.
We would recommend implementing some sort of 'exponential backoff' algorithm, which will send retries to the API in a managed way, and minimising the amount of retries required. This is a common method of ensuring that web services do not become overloaded. See http://en.wikipedia.org/wiki/Exponential_backoff for more information.
We have included an example implementation of an exponential-backoff implementation below. This is similar to the retry alogrithm we use in our WhiteLabel Deals Finder implementation.
'XmlDocument to store output of API
Dim myXmlData As New XmlDocument
Dim myXmlResult As XmlNode = Nothing
Dim retryGetDeals As Boolean
Dim retryCounter As Integer = 5 '5 retries maximum
Dim retryGetDealsTimeout As Integer = 100 '100ms initial timeout
retryGetDeals = False
'Send request to API - retry on 503 busy failure
myXmlResult = FeedService_V2.GetDeals(APIKey, maxResponseTime, maxResultCount, Brand, DepartureAirport, DestinationAirport, DestinationCountry, DestinationRegion, DestinationResort, DestinationHotel, DepartureDate, HolidayMinNights, HolidayMaxNights, Board, StarRatingMin, StarRatingMax, DaysEitherSide, PassengerCounts_Adults, PassengerCounts_Children, PassengerCounts_ChildAge, PassengerCounts_Infants)
If myXmlResult IsNot Nothing Then
'If we have a valid response, add result to myXmlData
Catch ex As ServerTooBusyException
'The request has failed with a server busy message (503 HTTP response) - retry up to 'retryCounter' times
If retryCounter > 0 Then
'Set flag to retry request
retryGetDeals = True
'We pause thread, retry after a random interval between 1ms and the current value of 'retryGetDealsTimeout'
Thread.Sleep(CInt(Math.Ceiling(Rnd() * retryGetDealsTimeout)))
'Decrement counter and increase retry time exponentially
retryCounter -= 1
retryGetDealsTimeout = retryGetDealsTimeout * 2
Catch ex As Exception
'Another error has occurred - deal with this as required
Loop Until retryGetDeals = False