Next.js Discord

Discord Forum

Optimizing API Usage: Implementing Efficient Caching for Stock Data

Unanswered
MatheusDeveloper posted this in #help-forum
Open in Discord
Hi everyone, I need some help with my project. I'm developing an application that uses the MarketStack API to fetch stock data. The issue is that they charge $10 for 10,000 monthly requests, and my app will need significantly more than that.
I've thought of a solution: creating a caching system to store the stock data. The idea is to first check if we already have the data saved before making a new request to the API. If we have it, we use that data. If not, we fetch it from the API, save it, and make it available for subsequent users.
Additionally, I was thinking of updating this data every 15 minutes. Does this seem like a good strategy?
How would you implement this caching system? Do you have other ideas to reduce API calls without compromising data updates? Any suggestions on how to manage this without exceeding the request limit?

2 Replies

I've thought of a solution: creating a caching system to store the stock data. The idea is to first check if we already have the data saved before making a new request to the API. If we have it, we use that data. If not, we fetch it from the API, save it, and make it available for subsequent users.
This makes sense. You'd need your own database to store the stock information - if you go with something like Supabase.com, I believe their free tier has unlimited read requests. And so your app's endpoint will send a request to your backend, you first check if it's in your supabase database, if it is, return that, if not go get it from the MarkeetStack api.
Blanc de Hotot
have you considered redis/kafka?