Your best option is to make the client do absolutely nothing with server failure. This is not the responsibility of the client, and it should never be. Server technologies such as proxies and load balancers are best suited for troubleshooting server failures.
The most common approach is to abandon the “one primary server” way of thinking and create a cluster of servers, each of which can handle any of your REST requests. If your REST requests have no status (and they should be) and can be redirected to any arbitrary server in the cluster, then the server failure can be processed using the load balancer in front of the cluster.
If the load balancer detects that the server is dead, it simply pulls it out of rotation. This model also helps in scalability, because you can scale your server REST level by simply increasing the number of servers in this layer and automatically registering them with a load balancer.
You can also use DNS to isolate the client from server failure. Just change the DNS record point to the currently active server and change it when the primary server goes down. However, the TTL must be very low to allow this technique to work at any reasonable time. It is better to use DNS for a complete data center failure, rather than from a node, but this is an option, although rather crude.
source share