Dynamic Load Balancing in Apigee when target servers change for every request

We have a use case where Apigee is calling eureka and finding the target server for the client app using the application name. So the application name can be different every time. Eureka provides us multiple end points for the corresponding service name. As of now if it is a single endpoint we are able to call the target service and get a response.

In case if we get multiple end points , can apigee do the load balancing?

Please consider that the application name which we query to eureka from apigee can be different everytime and eureka returns results based on what services are up at that point of time.

1 2 1,698
2 REPLIES 2

@Anil Sagar

@Dino

Can you please help with this question.

Yes it is possible for you to code logic in Apigee Edge that dynamically selects among the list of servers returned from Eureka.

I suppose that really what you'd like to do is connect with Eureka periodically. Not for every request, but maybe every 10 seconds, or every 60 seconds, or something like that.

Then cache that result.

In the API Proxy, the logic flow would be:

  • check the server list cache (LookupCache) - if empty, then:
    • call to Eureka (ServiceCallout or JS) to get the list of servers
    • use PopulateCache to store the list
    • Do a LookupCache to fill the context variable.
  • Invoke a JS call to dynamically select from the list of servers (contained in the context variable), then set the targetUrl

I built a demonstration of this a while back. The dynamic selection was also "weighted" , so that not all servers got the same proportion of load. You may or may not want that flourish.

You can find the demonstration of this idea on github.

Be aware of the issues when setting the target url. Maybe consult this Q&A.