How to Manage Traffic with Cloud Function and Manage Revision

2022/09/122 min read
bookmark this
Responsive image

Table of Contents

  1. Introduction
  2. Prerequisites
  3. How to Achieve This
  4. Manage Traffic
  5. Conclusion

Introduction

If you have used Google Cloud Functions, you'll notice how easy it is to deploy code without worrying about backend managed services, since Google handles that for you so you can focus on development. This blog will focus on how to manage traffic and revisions once you need to deploy different versions.

Prerequisites

In this blog, we'll assume you already have a cloud function deployed on the cloud and everything is working. You are planning to deploy the next version; however, you don't want the current production version to be replaced. Depending on how you have configured things, every time you deploy to Google Cloud, the new deployment might become the latest version automatically.

How to Achieve This

Go to Cloud Run Go to the cloud function, then click Powered by Cloud Run to navigate to Cloud Run, and click EDIT & DEPLOY NEW REVISION.

Uncheck Serve this revision immediately Uncheck this option so that every time you deploy a new cloud function, it won't serve as the latest version immediately.

Manage Traffic

Since you unchecked the above checkbox, the new version won't serve traffic automatically. You have to manually click the Actions on your new version to manually split the traffic.

Conclusion

By unchecking the "Serve this revision immediately" option in Cloud Run, you can deploy new versions of your Cloud Function without automatically replacing the current production version. This gives you full control over traffic splitting between revisions, enabling safer deployments and gradual rollouts.