How to dynamically call different target endpoints based on region

In a multi-region Apigee Edge setup, it might be necessary to call a different target endpoint depending on which datacenter is handling the transaction. For example, there already exist multiple backend services, like east.backend.example.com and west.backend.example.com, and it is necessary to call the closest backend service.

This is possible inside the API Proxy itself. There exists a built-in variable called "system.region.name". This can be incorporated into the API Proxy logic to direct the backend call to the appropriate region.

For example you could use it in a Condition for various RouteRules.

<ProxyEndpoint>
   ....
  <RouteRule name='East'>
    <TargetEndpoint>eastBackendTarget</TargetEndpoint>
    <Condition>system.region.name ~~ "us-east-.+"</Condition>
  </RouteRule>
  <RouteRule name='West'>
    <TargetEndpoint>westBackendTarget</TargetEndpoint>
    <Condition>system.region.name ~~ "us-west-.+"</Condition>
  </RouteRule>
  <RouteRule name='Default'>
    <TargetEndpoint>defaultBackendTarget</TargetEndpoint>
  </RouteRule>
</ProxyEndpoint>

Or, you could use the variable to dynamically set the target.url.

A full reference of all built-in variables can be found here:

http://apigee.com/docs/api-services/reference/variables-reference

Comments
adevegowda
Staff

@Dino/@Alex,

Is this applicable to Private Cloud (OPDK) setup where the target servers are setup in multiple data centers ?

Not applicable

im expecting it wont - because these are clearly aws regions right? But if you have multiple datacenters w/ something like topological routing you could do this same thing keyed off some other piece of data in the inbound connection. I havnt had to solve this problem YET - but a simple lookup table would solve this - and im sure that could be hatched into some intricate thing involving KVM or something if someone smarter than me put some thought into it.

mariathanner
New Member

Hi @Alex Toombs, @Dino

to summarize: the first solution works with RouteRules (including conditions) in the Proxy Endpoint, and you have several targetEndpoints (which you can hardcode or also set dynamically via TargetServer (?)

the second option (dynamically set target.url) would be: using assignMessage and KVM extraction policy in the TargetEndpoint-request-flow. Then you only have one TargetEndpoint (?)

But is there any advantage of the latter option (using KVMs)? I think this can also be done with targetServers (which is more intuitve?)

dchiesa1
Staff

The "read it from KVM" option might be nice if you expect to have an expanded set of targets, or a set of targets that you'd like to apply a weighted routing to. For example targetA gets 90% and targetB gets 10% of requests; but 3 hours later I'd like to change those numbers to 70/30.

If I can do that by updating the KVM, it's "lighter weight" than updating a proxy with new targetendpoints and redploying it.

On the other hand the targetendpoint is nice if you like the analytics that you can get to track their performance. It's also more "obvious" to see what's happening when you look at the configuration.

There are pros and cons for each option.

Version history
Last update:
‎04-12-2015 12:25 PM
Updated by: