Making your APIs highly available

Emanuelburgess
5 min readFeb 22, 2024

--

Creating reusable APIs require planning and consideration with the customer in mind. Great APIs start with “treating your APIs as products”. This means you start creating APIs with the “end” in mind. In Apigee, proxies allow you to expose your business logic to consumers that you trust. They serve as entry points to application logic and data that sit between your customer and your backend. Proxies also allow you to do things like attach policies. Proxies are made up of 2 different endpoint types:

Proxy endpoint — Defines how customers will access your APIs.

Target endpoints — Defines how customers will interact with your backend applications by decoupling hard coded endpoint URLs from TargetEndpoint configurations.

One of the ways you can deliver a great experience to your customer is by making your API highly available. There may be times where you have separate load balancers pointing to your backend server in order to provide high availability. You can leverage these load balancers to make your backend highly available by using the target endpoint to configure load balancing.

Target servers

In order to set up load balancing within your proxy, you have to first create a target server. Target servers allows you to give each of your backend servers a unique name that is coupled to a host or a server. This unique name can be used to configure “targets” in your target endpoint configuration. In order to create a target server you can log into the Apigee console go to Management > Environments:

Target servers live in environments. In order for your target servers to be available for your proxy they have to be created in the environment that your proxy is deployed to.

Next click on Target Servers > Create target server:

After putting in all of your server information click on create.

After creating your target servers, Next edit your target endpoint configuration by going to proxy > Develop > target endpoint.

Distributing the load

When you configure a load balancer in your proxy by default Apigee will use the round robin algorithm to distribute your traffic which will send traffic to each server in the order listed. You can also choose between:

  • Weighted: Allows you to define what percentage of traffic goes to what server.
Weighted algorithm
  • Least connection: Sends requests to the TargetServer with fewest open HTTP connections.
Least connection algorithm

These algorithms can be declared using the <algorithm> element.

Algorithm declaration

In addition to using algorithms you can also configure routing logic based on failures with tools like MaximumFailures, Retry, and Isfallback options within health checks.

Health Checks

Health checks at the proxy level in Apigee allow you to test connectivity to your target servers (backend). By enabling health monitoring you can set up checks to poll the backend service URLs that you specified in your TargetServer configuration. Health checks add a level of fault tolerance to your APIs and allow you to mask failures. Fault tolerance is achieved by monitoring health check requests for failures. After a specified number of failures the load balancer will take the problem target server out of load balancing rotation. Failures are masked because your API is still available by your load balancer sending traffic to your health target servers. Your API consumer is still able to access your APIs without interruption.

When you enable health monitoring there are 2 types of monitor you can specify:

TCPMonitor: TCPMonitors listen on port 80 which by default polls your target servers every 5 seconds.

HTTPMonitor: HTTPMonitor sends a GET request to your target service. You should use HTTPMonitor health checks when your backend is configured to use HTTP and one-way HTTPS protocols.

Handling Failures

Designing highly available APIs require you to consider how failures should be handled. MaximumFailures in Apigee allow you to specify a set number of unsuccessful connections. Once that number of failures have been reached the load balancer will take that specific target server out of rotation. When MaximumFailures attribute is set to 0, the load balancer won’t take the target server out of rotation. It’s important to specify a number of at least 1 in order to take advantage of fault tolerance to reduce interruptions that your consumer may experience. You can specify the maximum number of failures by using the Max Failures element.

Maxium Failure

You can also leverage the Retry option to have the health check try to establish connectivity after a failure.

Retry option

Using the IsFallback option allows you to set a designated server as the “fall back server” meaning that if all other target servers become unavailable or unhealthy traffic will then be routed to the specified fall back server. You can specify a fallback server by using the Isfallback element.

Enable Fallback

Make your APIs highly available

Configuring target servers in your target endpoint configuration allows you to create great digital experiences for your customers by making your API highly available. APIs that are reliable and easy to use will help increase adoption across your organization and customer base. Want to know more about target servers and the additional features that you can configure to make them more robust checkout this Apigee training.

--

--