Cache — A Cost-Effective Way to Consider When You Implement APIs!

Use cache to lower your cost when you use third-party APIs.

Do you want to pay for SaaS service whenever a user requests an API call (think of how many users you will be expected on a daily basis)? The answer is NO!!! Not only it will increase your bill, but also it may slow the product when users have to make API calls.

The solution is simple — cache! Store the response to your database, and check your database before you make the API call, if the result is already stored in the database, then you can just return the result from your database instead of making the API call; but if the result is not yet stored in the database, we can just store the response to the database in order to use when a user needs to get the data next time.

Photo by Tobias Fischer on Unsplash

There are popular caching services like Redis, Memcached, etc.

Below, I am using MongoDB as a database example to store the cache.

At the end of the day, how much you spend is an important factor in the revenue of the product you are building.

Happy coding^^



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Hanwen Zhang

Full-Stack Software Engineer at a Healthcare Tech Company | Document My Coding Journey | Improve My Knowledge | Share Coding Concepts in a Simple Way