Optimizing your API performance

Abhishek Dutt
3 min readNov 19, 2021

--

Someway or the other, most of the applications(websites and Android Apps) are using APIs(Application Programming Interface) in the present world.

Introduction

An API allows your application to interact with services from other app or program. There might be some restrictions, but it lets your application access the service’s data without being constrained by the limitations of the services own interfaces.

In layman words, an API works as an intermediary between your application and some other service.

Hence, it is imperative to optimize the API to provide better performance and user experience to your application. In this article I have described Five ways to optimize API performance.

  1. PATCH over PUT

Imagine your are developing an application that fetches seat status of a local bus from the Bus operator’s central database. Now every time someone books a seat, the status has to be updated.

Does that mean fetching all the data from the database each time the status is updated or just fetching the updated data?

Previously I used the PUT request to update the resource. Lately, I started using the PATCH request method, because it only updates the necessary part of the resource whereas PUT updated the entire resource. There might be some exceptions, where PATCH might not be used.

2. Caching Data

Caching the data is still one of the best strategies to reduce the round trips of client requests to the server, thus improving the API performance and latency.

You can implement several endpoints for the frequently used requests. There are several ways to implement it.

For Android apps, you can check out this repository, where I have demonstrated how caching works with Android apps.

3. Rate-Limiting Policies:

There might be a situation, where an user executes a loop, causing many API requests that can actually slow down the overall performance. This situations are inevitable, hence while writing the application, one should always keep in mind such things.

Limit the specific number of requests in the given period of time.

4.Hosting as per the needs

During my tenure of internship, our application faced a surge in traffic. In such a case, no matter how good the endpoints are, if the hosting service can’t keep up with the requests, there is a high likelihood of loosing your users.

Hence, make sure you use a good hosting company, that provides with better CPU instances and database, to make your API requests fast.

5.Compressing Data

The data that is being fetched can be in any form, massive data transactions can make the API slow, eventually lowering the performance of your application.

Compress data whenever need, it will make the transaction faster and improve the overall performance of the API.

There are numerous ways to compress data. Some hosting service provide their own compression methods like :

  1. AWS(Payload Compression) https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-gzip-compression-decompression.html

Conclusion

Optimizing API performance is a crucial thing. If you are developing an application that is expected to make API calls, it is needed that they are done in a neat way, so that it doesn’t messes up the User Experience.

Follow me on Github to explore repositories related to Android Development:

--

--

No responses yet