External API request performance

Hi Upcase community,

I have been googling and researching and couldn’t find much resources on this topic:

I have an application that calls external service to display their data live, the problem is the the request is slow.

I watched “Improving Perfomance for Real-time requests” but it seemed like it was mainly improving database queries?

What are the best practices for making performance better for Users? I couldn’t figure it out with doing active jobs, delayed jobs since I need to display the data live.

could you trying caching?

I use delayed_job_active_record for background jobs, I am not sure how I can cache the live/recent data to cache and display… any suggestion @gxespino? :grin:

It would be easier to help if you gave a little more detail or an example of when your app needs to fetch and display the external data.

Your scheduled job can use Rails.cache to store the external data using a cache key that is readily available on subsequent requests, such as a database record ID. Specifically the fetch method.

Keep in mind that most cache stores only support some of the methods in the page above. All of them support write, read, and fetch, though.

This article by Brandon Hilkert is an excellent example of using background jobs to cache data and a decent intro to Rails.cache.fetch. I used a similar implementation in an app a few months ago. Check it out and get back here with any questions you may have.