Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Is caching DB query output possible with Cloud MemoryStore (REDIS)?

I have a python / flask app deployed on Cloud Run that makes connections to Cloud SQL via private IP. Most of the endpoints of the application make DB calls and we are seeing some of the DB queries  underperform with page load times / response times  in the order of 5- 10 seconds. While optimizing the queries is inevitable,  I would like to know if I can further improve performance / response times by caching query output by using REDIS / Cloud Memorystore and if so any sample examples that i can refer to. I understand this is more of an architecture question than GCP and i appreciate any response.

Note:- These are static DB queries so setting up views is one improvement but I am more interested in server side caching that i mentioned above to further improve the response times.

Solved Solved
0 2 781
1 ACCEPTED SOLUTION

Hi @dheerajpanyam

To answer your question, yes, caching database queries is possible with Cloud Memorystore for Redis. Redis can significantly reduce the need for repetitive data fetching. This further improves the speed and responsiveness of your applications in Cloud Run. 

To set up, you can connect your Cloud Run service to a Redis cache using Memorystore. You can also refer to this complete Cloud Run and Redis code samples. Note that Memorystore for Redis does not provide a free tier. See Memorystore pricing for more details.

I hope the above information is helpful.

View solution in original post

2 REPLIES 2

Hi @dheerajpanyam

To answer your question, yes, caching database queries is possible with Cloud Memorystore for Redis. Redis can significantly reduce the need for repetitive data fetching. This further improves the speed and responsiveness of your applications in Cloud Run. 

To set up, you can connect your Cloud Run service to a Redis cache using Memorystore. You can also refer to this complete Cloud Run and Redis code samples. Note that Memorystore for Redis does not provide a free tier. See Memorystore pricing for more details.

I hope the above information is helpful.

Thanks  @ronnelg I will look at the code samples.