API Performance Monitoring – An Introduction

3252 VIEWS

· · · ·

The goal of this post is to explain the concept of API performance monitoring, what you should measure, and why it matters. If you are new to the concept of APIs, here is an introduction to APIs. You may also be interested in these tips for building APIs

APIs have become very useful in most SaaS products. There is still a gap, however, when it comes to understanding how they work; particularly for the purpose of monitoring them. Some developers do not realize that APIs fail. And when they fail, users usually blame the application’s poor performance on the product owners rather than the third-party APIs used in the app. The developers also waste a lot of time debugging their app trying to “solve” what was just but a network issue. 

What is an API

Technically, an API stands for ‘application programming interface’. It describes a way of plugging your website into a third-party website to achieve certain functionalities. Commercial platforms expose some parts of their code to developers to integrate with other sites and build functional tools. The exposed code is called an API and it helps in building widgets and applications. Examples of APIs include Facebook, Google’s Open Social, Google Maps, and YouTube.

API Monitoring and Why It Is Important

You might question why you need API monitoring. After all, you have built your application, API, or whatever service, and it is up and running. Everything seems easy at this point. But, it doesn’t always stay like that. Sometimes the network gets affected and the server goes down. The customers start calling and giving bad reviews about your service due to the huge lag times. Some customers unsubscribe to your service while you are busy spending long hours debugging an issue that was just but a network error. This could be avoided if you were monitoring your APIs. 

API monitoring is the process of observing the performance of an API by checking the uptime and acting in case of any 500 error responses. Dedicated API monitoring allows you to verify how your internal and third-party APIs are working. If a given API has an issue, it tells you what it is. This enables it to be easily resolved by your team. 

Most developers and companies who use third-party APIs rely on the API providers to update them on the API status, which is mostly done manually. This creates a challenge because of the lag time involved. By the time status pages are refreshing and updated, your application might have collapsed already. This is why you need to monitor the real-time performance of your APIs directly in your application. 

When it comes to API monitoring, the first step is always to determine which metrics to monitor.  This requires that you understand how the API works. For example: its consumption in terms of the number of API calls it makes, the rate at which it makes the calls, and the nature of the API endpoints.

Consider these metrics when monitoring APIs or web services: latency, response time, availability, failure rate, and status codes.

API Metrics to Monitor

Latency

Latency is the amount of time an API infrastructure takes to respond to an API call. It is usually measured from the moment a request arrives at the API gateway to when the first byte of a response returns to the client. To measure the latency of an API, you have to keep track of the timestamps of send requests and responses using the web service. To monitor latency using Postman, do a comparison of the ‘response time’ variable within the test scripts as shown below. 

tests['Response latency is acceptable'] = responseTime < 1000;
Response Time

Response time is defined as the amount of time a system takes to ‘attend to’ the request sent, once it has received it. It is the computation time between the instant an API is invoked and the instant the API returns the computation results. Delays in API responses result in slow application performance. This can be measured by comparatively estimating the latency of different web services. 

Availability

You may define the availability of an API as either downtime or uptime. The uptime of an API determines its overall performance. Businesses usually prefer APIs whose uptime is higher during business hours, ensuring customers can maximize their services. 

Status Codes

APIs use status codes as part of their response messages. This provides granular details about how a particular API endpoint call is performed. There are different interpretations for different status codes. For instance, status 200 OK means a successful API call. To measure this metric, you need to compare the status codes of the same API using an internal HTTP error logging system, to ascertain true status error codes.  When using Postman, you can use the code below to monitor any web service’s status code.

tests['Request resulted in 200 OK'] = responseCode.code === 200;
Failure Rate

This metric focuses on the rate at which a third-party API or web service request fails. It helps in establishing the cause of the failure by reporting on the cause of the failure; which is sometimes caused by the API downtime, network-related issues, or API rate limits. Monitoring API failure rate helps you to decide on multiple API providers and to build resilient internal resources to validate such error scenarios.

API Performance Monitoring using Postman 

Postman uses monitors to test a collection of API endpoints and web services. You can do test runs as frequently as every 5 minutes. Before running an API test suite, you need to understand how the API works and the kind of response you expect. The code below shows a sample test suite when dealing with complex objects and arrays as environment variables. 

// set the value

postman.setEnvironmentVariable('complexObj', JSON.stringify(myComplexObjOrArray, null, 2)); //Fetch the value

var foo;

try {

    foo = JSON.parse(postman.getEnvironmentVariable('complexObj'));

}

catch (e) {

    console.error(e);

    foo = { __parseError: true };

}

if (foo.__parseError) {

    // handle parse errors here

}

 

Please Note:

There are a lot of API monitoring tools available either freely or on paid packages. Always understand the nature of your APIs and the metrics offered for different tools before choosing one. 

Conclusion

Any business that relies on a third-party API needs to monitor it. The business should constantly review the performance of the API because when the third-party API fails or has slow performance, the customers blame the business; they do not care about the API provider. Users are likely to perceive this as a product failure, which is detrimental to the brand. 


Faith Kilonzi is a full-stack software engineer, technical writer, and a DevOps enthusiast, with a passion for problem-solving through implementation of high-quality software products. She holds a bachelor’s degree in Computer Science from Ashesi University. She has experience working in academia, fin-tech, healthcare, research, technology, and consultancy industries in both Kenya, Ghana, and in the USA. Driven by intellectual curiosity, she combines her passion for teaching, technology, and research to create technical digital content.


Discussion

Click on a tab to select how you'd like to leave your comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Menu
Skip to toolbar