3 Great Options for Persistent Storage with Cloud Run

Grant Timmerman
Google Cloud - Community
2 min readJan 13, 2020
Cloud Run with Cloud Storage, Cloud Firestore, and Cloud SQL

Cloud Run is a managed compute platform that automatically scales your stateless containers. Cloud Run is serverless: it abstracts away all infrastructure management, so you can focus on what matters most — building great applications.

However, most applications are stateful. As a developer, how can you permanently store images, database records, and other pieces of data?

In this article, we’ll discuss 3 example ways in which you can store data on Google Cloud Platform with Cloud Run.

Storage with Google Cloud

There are a variety of ways to store data on Google Cloud, depending on your application’s needs. In this imaginary application, let’s create a e-commerce shoe store. Here are three storage options we’ll use for storing different kinds of data:

Cloud Storage

For storing files/objects such as images and video, or archival backups, Google Cloud Storage is an excellent option for this type of data. Here’s an example code snippet in Node that can be used with Cloud Run:

Uploading a file to Google Cloud Storage

Cloud Firestore

For storing unstructured data, or creating a flexible, NoSQL, cloud database, Cloud Firestore is a great solution for mobile, web, and server development. In this sample, we want to store flexible JSON objects for shoe data:

Adding a doc/JSON record to Firestore

Cloud SQL

For storing structured data in a RDBMS, such as MySQL, PostgreSQL, and SQL Server, Cloud SQL can connect to a nice interface for storing and querying your data. Here created a customer table where we can use familiar SQL to create powerful queries:

Reading from a Cloud SQL table

Note: See Connecting to Cloud SQL from Cloud Run (fully managed) for full documentation on how to connect and use these services together.

Those are 3 storage options for storing data in GCP. Other products include Cloud Filestore, Cloud Storage for Firebase, and Cloud Memorystore among other databases.

Other Tips

Sometimes your data storage could use more configuration. Here are two tips:

  • Cloud Run’s “Max Instances” feature can limit the number of instances handling running your service. This, in turn, can rate limit the number of requests to your storage service. Read more 🔗.
  • Cloud Tasks with rate limits per queue can be placed in front of a Cloud Run service to smooth out rapid or jerky requests. Read more 🔗.

References

Thanks for reading. If you are looking for more reading about storing data with GCP, are some links:

--

--