---
title: "Best Practices for Building Reliable APIs - API7.ai"
description: "This article discusses best practices for designing reliable APIs by introducing you to a special reverse proxy - API Gateway"
url: "https://api7.ai/blog/best-practices-for-building-reliable-apis-with-api-gateways"
---

[Blog](https://api7.ai/blog)

[Products](https://api7.ai/category/products)[Technology](https://api7.ai/category/technology)[Ecosystem](https://api7.ai/category/ecosystem)[Case Study](https://api7.ai/category/usercase)[Team & Community](https://api7.ai/category/community)

Search

⌘ + K

[Blog](https://api7.ai/blog)

Technology

# Best Practices for Building Reliable APIs

[![Navendu Pottekkat](https://avatars.githubusercontent.com/u/49474499?v=4)](https://github.com/pottekkat)

[Navendu Pottekkat](https://github.com/pottekkat)

August 18, 2022

[Technology](https://api7.ai/category/technology)

As your APIs scale, the need for making them reliable and robust increases.

This article discusses the best practices for building reliable APIs by introducing a special kind of reverse proxies called API gateways.

We will look into:

1. Problems with traditional API designs
2. What API gateways are
3. How API gateways improve APIs and
4. Patterns and examples using API gateways

But first, what are "reliable" APIs?

## What Makes an API Reliable?

As a service provider, you might have service-level agreements (SLAs) with your customers, usually quoted in uptime—the amount of time the service is guaranteed to be online and operational.

Uptime is a myopic view of reliability. To understand what it means to be reliable, you have to look at the factors that affect uptime. Once you understand these factors, you will be in a better position to build reliable services.

Let's look at these factors and the questions they pose:

1. **Latency**: How fast does your API respond to requests?
2. **Security**: Who can access your API? Is it secure?
3. **Downtime Frequency**: How frequently is your API down?
4. **Consistency**: Are your API endpoints constant? Do consumers need to change their code often?
5. **Monitoring and Reporting** Can you observe issues and failures in your API? Are you reporting them to your consumers?

![network error/api.png](https://static.api7.ai/2022/blog/0819/2022-08-19-084123.png?imageMogr2/format/webp)

As organizations move to cloud-native architectures, it becomes difficult for the development teams to account for these factors on each of their services. And as these systems scale, it would be much easier to delegate these responsibilities to a single, separate system. *Say hello to API gateways!*

## API Gateway, the Unified Entrypoint

An [API gateway](https://api7.ai/blog/apisix-vs-kong-3-0) acts as a middleman between your clients and your APIs. It will accept all [traffic](https://api7.ai/blog/traffic-split-in-apache-apisix-ingress-controller) (API calls) like reverse proxies, forwards the request to the required services in your backend, and returns the needed results.

![network error/api gateway.png](https://static.api7.ai/2022/blog/0819/2022-08-19-101223.png?imageMogr2/format/webp)

An API gateway can be the central point that handles all the [authentication](https://api7.ai/blog/api-gateway-authentication), security, traffic control, and monitoring concerns, leaving the API developers to focus on business needs and making it easier to improve reliability.

![network error/api gateway reliability.png](https://static.api7.ai/2022/blog/0819/2022-08-19-093336.png?imageMogr2/format/webp)

There are a lot of [open source and managed API gateway offerings](https://geekflare.com/api-gateway/) available. In this article, I will be using [Apache APISIX](https://apisix.apache.org/).

The following section will describe some of the best practices to make your APIs reliable using API gateways.

## Reliability Best Practices with API Gateways

We will focus more on the pattern underneath than the actual implementation, as it can vary based on your [API gateway](https://api7.ai/learning-center/api-gateway-guide/what-is-an-api-gateway) choice.

I will divide these patterns into three categories:

1. Authentication and security
2. Monitoring and observability
3. Version control and zero downtime

We will look into each category in detail below.

### Authentication and Security

#### User Authentication

Authenticated requests with API gateways secure client-API interactions. After a client authenticates, your API gateway can use the obtained client details for fine-grained control.

![network error/user authentication.png](https://static.api7.ai/2022/blog/0819/2022-08-19-093420.png?imageMogr2/format/webp)

APISIX handles authentication directly through plugins like [key-auth](https://apisix.apache.org/docs/apisix/plugins/key-auth/) and [jwt-auth](https://apisix.apache.org/docs/apisix/plugins/jwt-auth/). APISIX also supports OAuth authentication and role-based access control systems like wolf through plugins like [openid-connect](https://apisix.apache.org/docs/apisix/plugins/openid-connect/) and [wolf-rbac](https://apisix.apache.org/docs/apisix/plugins/wolf-rbac/), respectively.

#### Rate Limiting

Intentional (DoS attacks) and unintentional (clients making too many requests) traffic spikes to your APIs can bring them down like a house of cards. Setting up [rate limiting](https://api7.ai/blog/rate-limiting-in-api-management) will improve the reliability of your systems in handling such scenarios.

You can set up rate limiting on your API gateway, and if the number of requests increases above a threshold, the API gateway could either delay or reject the exceeding requests.

![network error/rate limiting.png](https://static.api7.ai/2022/blog/0819/2022-08-19-093445.png?imageMogr2/format/webp)

With APISIX, you can use any of the three plugins to configure rate limits based on number of requests, number of concurrent requests per client, and count ([limit-req](https://apisix.apache.org/docs/apisix/next/plugins/limit-req/), [limit-conn](https://apisix.apache.org/docs/apisix/next/plugins/limit-conn/), [limit-count](https://apisix.apache.org/docs/apisix/next/plugins/limit-count/)).

### Monitoring and Observability

Your API's reliability and your monitoring setup go hand in hand. And you can monitor your reliability metrics by setting up monitoring on your API gateway.

![network error/monitoring and observability.png](https://static.api7.ai/2022/blog/0819/2022-08-19-093513.png?imageMogr2/format/webp)

[API logs](https://api7.ai/blog/apache-apisix-google-cloud) and traces provide detailed information about an API call. This information will help you know when your API has failed or has an error as soon as possible. Silent fails lead to unfixed errors which can cause problems in the future.

With some configuration, you will also be able to predict and anticipate traffic for the future, helping you scale reliably.

APISIX has plugins that integrate with logging ([Apache SkyWalking](https://apisix.apache.org/docs/apisix/next/plugins/skywalking-logger/), [RocketMQ](https://apisix.apache.org/docs/apisix/next/plugins/rocketmq-logger/)), metrics ([Prometheus](https://apisix.apache.org/docs/apisix/next/plugins/prometheus/), [Datadog](https://apisix.apache.org/docs/apisix/next/plugins/datadog/)), and tracing ([OpenTelemetry](https://apisix.apache.org/docs/apisix/next/plugins/opentelemetry/), [Zipkin](https://apisix.apache.org/docs/apisix/next/plugins/zipkin/)) platforms/specifications. You can read more on [API Observability with APISIX Plugins](https://apisix.apache.org/blog/2022/04/17/api-observability/).

### Version Control and Zero Downtime

#### Canary Release

When switching to new versions of your APIs, you must ensure that you don't drop your traffic. Clients should still be able to make requests to your API and get back the correct response.

With an [API gateway](https://api7.ai/blog/api-gateway-deployment-patterns), you can setup canary releases. This will ensure that your API remains functional during the transition, and you can also roll back to the older version if there are any issues.

Initially, the API gateway will route all traffic to your API's old version.

![network error/old version.png](https://static.api7.ai/2022/blog/0819/2022-08-19-093542.png?imageMogr2/format/webp)

When you have a new version, you can configure the API gateway to route some of your traffic to this new version. You can keep increasing the percentage of traffic to your new service and check if everything is working as expected.

![network error/canary release.png](https://static.api7.ai/2022/blog/0819/2022-08-19-093559.png?imageMogr2/format/webp)

Finally, you can route all traffic to your new API.

![network error/new API](https://static.api7.ai/2022/blog/0819/2022-08-19-100732.png?imageMogr2/format/webp)

APISIX uses the [traffic-split](https://apisix.apache.org/docs/apisix/next/plugins/traffic-split/) plugin that lets you control the traffic to your services. You can use it to set up canary releases or your custom release configuration.

#### Circuit Breaking

When one of your upstream services is unavailable or is experiencing high latency, it needs to be cut off from your system. Otherwise, the client will keep retrying the request, leading to resource exhaustion. This failure can creep into other services in your system and bring them down.

Like how electrical circuit breakers isolate faulty components from a circuit, API gateways have a circuit breaker feature that disconnects faulty services, keeping the system healthy. Traffic to these services are rerouted or delayed until the service becomes healthy.

![network error/circuit breaking.png](https://static.api7.ai/2022/blog/0819/2022-08-19-093714.png?imageMogr2/format/webp)

APISIX comes with an [api-breaker](https://apisix.apache.org/docs/apisix/next/plugins/api-breaker/) plugin that implements this pattern.

#### Redirects

As you update your APIs, their endpoints might undergo some change. Traditionally, this would mean that the client application should send requests to the `/new-api-endpoint` instead of the `/old-api-endpoint`, meaning your consumers must manually change each call to this API endpoint.

If unanticipated, this can break client applications.

With an API gateway, you can provide an abstraction layer and redirect requests to the `/new-api-endpoint` without having the clients change their requests. With proper redirect status codes and messages, you can gradually depreciate the `/old-api-endpoint` without your consumers experiencing any downtime.

![network error/redirect.png](https://static.api7.ai/2022/blog/0819/2022-08-19-093729.png?imageMogr2/format/webp)

With APISIX, you can use the [redirect](https://apisix.apache.org/docs/apisix/next/plugins/redirect/) plugin to configure redirects.

## Conclusion

When reliability becomes a primary concern, it is evident that API gateways are necessary as more organizations split their monoliths into [microservices](https://api7.ai/blog/what-are-microservices) and move to cloud-native architectures.

However, this does not mean API gateways are for everyone. Depending on your API's size and usage, an API gateway might be overkill, and you can get away with using a reverse proxy with basic routing and load balancing capabilities.

The use cases mentioned here only scratch the surface of an API gateway's capabilities. You can learn more about API gateways and Apache APISIX at [apisix.apache.org](https://apisix.apache.org/).

Tags:

[API Gateway Concept](https://api7.ai/tags/api-gateway-concept)

[APISIX Basics](https://api7.ai/tags/apisix-basics)

Share article link

Share

Related Posts

[![API Gateway vs Kubernetes Gateway vs Service Mesh](https://static.api7.ai/uploads/2023/06/07/KS3wtoLx_cover.png)](https://api7.ai/blog/gateway-and-mesh)

## [API Gateway vs Kubernetes Gateway vs Service Mesh](https://api7.ai/blog/gateway-and-mesh)

[![Top 10 API Management Trends for 2023](https://static.api7.ai/uploads/2023/04/12/PtHsoEJS_top-10-trends.png)](https://api7.ai/blog/10-api-management-trends-2023)

## [Top 10 API Management Trends for 2023](https://api7.ai/blog/10-api-management-trends-2023)

Table of Contents

- [What Makes an API Reliable?](#what-makes-an-api-reliable)

- [API Gateway, the Unified Entrypoint](#api-gateway-the-unified-entrypoint)

- [Reliability Best Practices with API Gateways](#reliability-best-practices-with-api-gateways)

  - [Authentication and Security](#authentication-and-security)
  - [Monitoring and Observability](#monitoring-and-observability)
  - [Version Control and Zero Downtime](#version-control-and-zero-downtime)

- [Conclusion](#conclusion)

## Related Posts

[![How API Gateways Fit into API Management](https://static.api7.ai/uploads/2024/12/25/zQTHfZGV_api-gateway-vs-api-management.jpg)](https://api7.ai/blog/api-gateway-and-api-management-comparison)

Technology

September 1, 2023

#### [How API Gateways Fit into API Management](https://api7.ai/blog/api-gateway-and-api-management-comparison)

Learn how the API gateway runtime fits into API management across lifecycle workflows, developer portals, governance, analytics, security, and operations.

[API Gateway Concept](https://api7.ai/tags/api-gateway-concept)

[API Management](https://api7.ai/tags/api-management)

[APISIX Basics](https://api7.ai/tags/apisix-basics)

[![Sticky Sessions with Apache APISIX: Session Affinity Guide](https://static.api7.ai/uploads/2023/07/28/d33oDxuF_Sticky-Sessions.png)](https://api7.ai/blog/sticky-sessions-theory)

Technology

July 27, 2023

#### [Sticky Sessions with Apache APISIX: Session Affinity Guide](https://api7.ai/blog/sticky-sessions-theory)

Learn when sticky sessions help, their availability and scaling trade-offs, and how to configure cookie-based session affinity with Apache APISIX.

[APISIX Basics](https://api7.ai/tags/apisix-basics)

[API Gateway Concept](https://api7.ai/tags/api-gateway-concept)

[Sticky Sessions](https://api7.ai/tags/sticky-sessions)

[![Custom Plugin Development For APISIX With Lua And ChatGPT](https://static.api7.ai/uploads/2024/12/25/MssMP69w_custom-plugin-development.png)](https://api7.ai/blog/plugin-development-with-lua-and-chatgpt)

Technology

June 12, 2023

#### [Custom Plugin Development For APISIX With Lua And ChatGPT](https://api7.ai/blog/plugin-development-with-lua-and-chatgpt)

This article will guide you through the process of developing a new custom plugin called file-proxy for APISIX using Lua and ChatGPT.

[API Gateway Concept](https://api7.ai/tags/api-gateway-concept)

[APISIX Basics](https://api7.ai/tags/apisix-basics)

[Plugin](https://api7.ai/tags/plugin)
