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

Prido's avatar
Level 2

Consuming API directly or saving into Db first

I am creating a betting site that i have to poll for updated data even every 5 seconds interval. So now i want to think of the best way between fetching data from api then save in db then front-end gets data from my db. Or i get the data directly from api to front-end. Which can be the best way.

0 likes
3 replies
laracoft's avatar

@prido

Better to save to DB first.

  1. If you pull direct from API when frontend reloads, you will easily hit the limit of the API (Assuming there is a rate limit)
  2. Frontend can also be slow if your API is slow, resulting in poor user experience
Tray2's avatar

I would most likely fetch the data from the api with a job and then let the frontend get it from an internal api call from the database.

However do you really need to store it in your db if you fetch it from an api?

martinbean's avatar

@prido I know of a large betting site in the UK that would pull in odds, and then save them as a cached JSON file. The reason being, it’s infinitely quicker to read some JSON from memory than it is to query a database and fetch results. Especially if we’re talking about a lot of rows, or a lot of frequently-updated data.

Please or to participate in this conversation.