Cloud Run integrates very well with other GCP services like Cloud Build and Artifact Registry. Its pricing model is very simple. The user pays for the time their code is running, rounding down to 100ms.
Cloud Run uses a Docker image as its smallest unit of deployment, which simplifies the developer experience. It also scales indefinitely depending on the number of requests received, which makes it a reliable solution.
Additionally, developers can use any programming language they want since Cloud Run works with Docker containers instead of language runtimes.
When to use Cloud Run
Cloud Run is a good solution for serverless applications written in pretty much any language.
It leverages the flexibility of Docker containers while incorporating some really interesting features like automatic application scaling. This makes it a good option for running microservices, as long as the user doesn’t need node allocation and networking features.
Cloud Run is also a good option for organizations that could benefit from the pricing flexibility of serverless applications.
How we implemented it
For this solution we have used a terraform project that declares the following resources:
A VPC with a subnet for connecting Redis and CloudRun
A Redis instance to store data
A CloudRun service that runs the application
The project contains a simple Counter Application consuming a Redis Memory Store.
Here is the Terraform block declaring the Redis instance.
Copy to Clipboard
Here we declare the connector that will be used to allow the application to access the Redis instance.
Copy to Clipboard
In the CloudRun Service we set parameters like region, image, and the application environment variables among other details.