Was this helpful?

Here are a couple of strategies that you can use to control how much traffic flows through your APIs:

  • Control the amount of traffic your API can send or receive, or store a server response so that only a small subset of requests are forwarded to your backend services
  • Throttle the number of requests Apigee forwards to your backend services

Limiting traffic

You can control traffic using one of these methods:

  • By limiting the number of requests an app is permitted to send.
  • By caching a response so that app requests are fulfilled by Apigee rather than your backend services.

The method you use depends on the kind of data you're serving. If you have data that is not refreshed very often, such as weather information, use response caching to store a response (like the temperature) so your backend service doesn't need to return a response for every single app request. However, if you have data that is constantly refreshing, you can use rate limiting to control the total amount of traffic that hits your backend service.

Here are some policies you can use to limit the amount of traffic that hits your backend service.

Redirecting traffic

In addition to controlling the amount of traffic that hits your backend service, you can control when your service is hit. Using RouteRules, you can control how traffic flows to different Target Endpoints. RouteRules are always applied to the Proxy Endpoint. You can add variables to a RoutRule to control when a rule is executed.  As messages are processed by the Proxy Endpoint, the variable is evaluated to determine which Target Enpoint will recieve traffic. For example, you can insert a timestamp variable so that at different times of day, different servers act as the Target Endpoint.

To redirect traffic, apply a condition to the RouteRule of a  Proxy Endpoint. In this example, a condition is added to direct traffic to different endpoints on certain days of the week:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Description>Default Proxy to create flows on an API</Description>
    <FaultRules/>
    <Flows>
        <Flow name="forecast weather">
            <Description>Weather forecast endpoint</Description>
            <Request/>
            <Response/>
            <Condition>(proxy.pathsuffix MatchesPath &quot;forecastrss&quot;) and (request.verb = &quot;GET&quot;)</Condition>
        </Flow>
    </Flows>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <FaultRules/>
                <Name>OAuthV20-1360270147385</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <HTTPProxyConnection>
        <BasePath>/v0/weather1</BasePath>
        <Properties/>
        <VirtualHost>default</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
    </RouteRule>
  <!--this RouteRule sends traffic to a different endpoint depending on the day of the week-->
    <RouteRule name="default">
       <Condition>system.time.dayofweek = 3</Condition>
       <TargetEndpoint>WeeklyOffload</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>