skip to Main Content
Welcome to Gimasys!
Hotline: +84 974 417 099 (HCM) | +84 987 682 505 (HN) gcp@gimasys.com

Cloud Run: what you should know about serverless HTTP containers

Mindful Containers is a fictional company that is creating packaged microservice applications. They need a fully managed compute environment for deploying and scaling serverless containerized microservices. So they are looking at Cloud Run. 

They are excited about Cloud Run because it eliminates configuration, monitoring, and cluster management so they can focus on building features for their applications. 

“Cloud Run is a fully-managed compute environment for deploying and scaling serverless containerized microservices.”

What is CloudRun?
What is CloudRun?

What is CloudRun?

Cloud Run is a server management environment for deployment and development on serverless HTTP containers without worrying about delivery machines,, configure the cluster or autoscaling.

  • No vendor lock-in  – Because Cloud Run takes the containers Standard OCI and Standard Implementation Knative API Serving, you can easily port your applications to on-premises or any other cloud environment. 
  • Fast autoscaling – Microservices deployed in Cloud Run automatically scale based on the number of incoming requests, without you having to configure or manage a Kubernetes Cluster official. Cloud Run scales to zero – meaning no resources are used – if there are no requests.
  • Split traffic – Cloud Run allows you to split traffic between multiple revisions, so you can do a gradual rollout like canary or rollout blue/green.
  • Custom domains – You can set up a custom domain mapping in Cloud Run and it will provide a TLS certificate for your domain. 
  • Automatic redundancy – Cloud Run provides automatic redundancy so you don't have to worry about creating multiple instances for high availability

How to use Cloud Run

With Cloud Run, you code in your favorite language/or use a binary library of your choice. Then push it to Cloud Build to create a container build. With a single command—”gcloud run deploy” —you will change from a container image to a fully managed web application that runs on a TLS certificated domain and  auto-scales as required.

How does Cloud Run work?

The Cloud Run service can be invoked in the following ways:

HTTPS: You can send HTTPS request to enable the service hosted on Cloud Run. Note that all Cloud Run services have a stable HTTPS URL. Some use cases include: 

  • Custom RESTful web API
  • Private microservices
  • HTTP middleware or reverse proxy for your web applications
  • Prepackaged web applications

gRPC: You can use gRPC to connect Cloud Run  services with other services — for example, to provide simple, high-performance communication between internal microservices. gRPC is a good choice when you: 

  • Want to communicate between internal microservices
  • Supports high data loads (gRPC uses protocol buffers, seven times faster than REST calls)
  • Just a simple service definition that you don't want to write in full a full client library
  • Use our  streaming gRPCs in your gRPC server to build more responsive APIs and apps

WebSockets: the WebSockets applications supported on Cloud Run with no additional configuration required. Potential use cases include any application that requires streaming service, such as a chat application.

Trigger from Pub/Sub: You can use  Pub/Sub to push messages to the Cloud Run service endpoint, where the messages are then sent to the containers as HTTP requests. Possible use cases include:

  • Convert data after receiving event when uploading files to the Cloud Storage bucket.
  • Process the activity set log Google Cloud with Cloud Run by exporting them to Pub/Sub
  • Publishing and processing of event Your own customization from Cloud Run services

Running services on a schedule: You can use Cloud Scheduler to secure trigger a Cloud Run service on a schedule . This is similar to using cron job. Possible use cases include:

  • Make regular backups
  • Perform repetitive administrative tasks, such as recreating sitemaps or deleting old data, content, configurations, synchronization, or modifications
  • Create invoices or other documents

Perform asynchronous tasks: You can use Cloud Tasks to securely queue a task to be processed asynchronously by the Cloud Run service. Typical use cases include:

  • Handling requests through unexpected production incidents
  • Smoothing traffic spikes by delaying work that is not user-facing
  • Reducing user response time by delegating slow background operations, such as database updates or batch processing, to be handled by another service, 
  • Limiting the call rate to backend services like databases and third-party APIs

Events from Eventrac: You can trigger Cloud Run with events from 60+ Google Cloud sources. For example:

  • Use our Cloud Storage events (via Cloud Audit Logs) to enable data processing 
  • Use our BigQuery event (via Cloud Audit Logs) to get started  downstream processing in Cloud Run every time a job is done

How is Cloud Run different from Cloud Function?

Cloud Run and Cloud Functions are both fully managed services that run on top of Google Cloud's serverless infrastructure, automatically scaling and handling HTTP requests or events. However, they have some important differences:

  • Cloud Functions allows you to deploy pieces of code (functions) written in a limited set of programming languages, while Cloud Run allows you to deploy container images in the programming language of your choice. 
  • Cloud Run also supports the use of any tool or system library from your application; Cloud Functions does not allow you to use custom executables. 
  • Cloud Run provides request longer standby time up to 60 minutes, while with Cloud Functions, the request timeout can be set as high as 9 minutes
  • Cloud Functions sends only one request at a time for each function instance, while by default Cloud Run is configured to send multiple concurrent requests on each container instance. This is useful to improve latency and reduce costs if you are expecting large numbers. 

Valuation

Cloud Run included a generous free tier and pay per use, which means you pay only while the request is being processed on your container instance. If it's idle and there's no traffic, then you don't pay anything.

Conclusion

After learning about Cloud Run's ease of setup, scalability, and management, the Mindful Containers team is using it to deploy stateless microservices. If you want to learn more, check out document.

Source: Gimasys

Back To Top
0974 417 099