Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eggplantSword's avatar

Using an api with a small amount of requests per minute

I'm working on a page that uses an api to check product stock and prices, my client wants this info to be in real time from the api the problem is that the api only allows 150 requests per minute and per product it would be two separate calls one for the stock and one for the price. At 10 products per page that's 20 requests per page per user, so around 7 - 8 people looking at the products page is the limit before the api stops working.

My question is what can I do to go around this issue? Is there a way to somehow have the data be somewhat "in real time" (every minute maybe) without making so many requests to the api. What would you recommend?

0 likes
9 replies
talel's avatar

Yes, cache the results and set expiration of 60 seconds.

theProfit's avatar

I would recomend to give them a TTL so when you request $product->stock() the stock model will look at updated_at if this is older then lets say 5 minutes trigger a update an process it. Else fetch the status from local DB.

Snapey's avatar

it depends how many items there are compared to how many a user might look at at once

Say there are 1000 items, it would be too heavy to update all of them frequently. However in such a situation, you could update the ones that are currently being viewed.

What you definitely want to do is to cache the result so that it makes no difference if there are 2 or 20 people looking at the same records.

Wrap the api call in a cache and give it a lifetime of 60 seconds. When you go to the API, if the cache has expired then make the call. If the data is in the cache then happy days, just return it.

eggplantSword's avatar

There are around 6500 - 7000 total products in the store. I'll definitely research using a cache like you're suggesting.

gavinj2006's avatar

I don't know man, if the limitation is that the api only allows 150 requests per minute, then it seems that the client is asking for something with an intrinsic limit to have no limit.

Whilst I don't know why the API has that specific limit, it seems that your client is asking for something that cannot be provided due to a limit you can't control.

In situations like this I guess expectation management is your friend.

eggplantSword's avatar

Yea, that's why I'm asking here for a solution or suggestion since the api limit is so low

Please or to participate in this conversation.