How to re-route to 2nd Target URL if Primary Target URL is unavailable

Hello

 

Assuming we have 2 target URLs, the API should fetch data from the first URL, and if the first URL Target endpoint is unavailable, then this should be identified in the response and the call should be made to 2nd URL / Proxy and the response from 2nd URL/Proxy should be attached .to the response.

 

Is this possible, if possible can I get an example, or can you let me know how I can achieve that.

 

Thanks

John

Solved Solved
0 7 291
1 ACCEPTED SOLUTION

You could follow the suggestions given to use conditional service callout or by using the Load Balancer approach and take the server out of rotation.

Additionally, the fact that the server returns a 404 doesn't make sense as what happens if the request is genuinely asking for an object that doesn't exist? It will still go to the secondary server and get another 404. In my opinion it should return a 503 unless it's timing out. and if it timing out, i think the load balancer approach is best to take the server out of circulation to avoid extended response times.

View solution in original post

7 REPLIES 7

This is possible by use of service callouts to send a request to the backend and having the policies be conditional.

With that said, this is on a path to be an anti-pattern of an implementation. 

In what circumstances would you want to try the second url? Is this based on an error response? or a timeout? If it's based on timeout, how long is the timeout, as Apigee also have its own timeout configuration. If this is just a random, intermittent scenario you should probably address the issue with your backend services first.

A slightly better approach could be to use the HTTPTargetConnection LoadBalancer, it has configurations for fallback, and maxfailures to remove a server from the list of available targets eg if your primary backend is unavailable for an extended period of time.

https://docs.apigee.com/api-platform/deploy/load-balancing-across-backend-servers#settingloadbalance...

Hello dknezic

 

Thank you for your response.

This is not a load balancing or timeout scenario.

We have 2 dbs, one replication DB ( does not have DR) and orignal backend DB.

The replication DB is used for analytical purposes.

The data is primarlarly fetched from replication DB. However if there is a 404 resource not found, then the data is to be fetched from the Orignal Application Backend DB. Both DBs are in different enviorments and hold the same data.

I want to design a proxy with the endpoint pointing to Replication DB Service. 

However if the response is 404, then this should be identified and the 2nd URL for the backend DB service should be invoked and the response from the 2nd service be included into the orignal proxy response.

Kindly share your thoughts

Thanks

John

Just to clarify, why do you fallback to the "original DB" if both already hold the same data? 

dknezic, the replication DB does not have disaster recovery, and if there is maintainence it wont be available and then the data fetch shoud be from the backend DB

hi dknezic, it this a achievable problem in apigee? or we use microservices?

You could follow the suggestions given to use conditional service callout or by using the Load Balancer approach and take the server out of rotation.

Additionally, the fact that the server returns a 404 doesn't make sense as what happens if the request is genuinely asking for an object that doesn't exist? It will still go to the secondary server and get another 404. In my opinion it should return a 503 unless it's timing out. and if it timing out, i think the load balancer approach is best to take the server out of circulation to avoid extended response times.

Thank you dknezic