Developing your service

This page describes a few things you need to know to get started in developing a service for Cloud Run.

Code requirements

You must meet the following requirements when you develop a service:

  • The service must listen for requests. You can configure the port on which requests are sent. Inside Cloud Run instances, the value of the PORT environment variable always reflects the port to which requests are sent. Your code should check for the existence of this PORT environment variable and if it is present, should listen on it to maximize portability.
  • The service must be stateless. It cannot rely on a persistent local state.
  • If the service performs background activities outside the scope of request handling it must use the instance-based billing setting in order to have CPU allocated outside of the standard request cycle.
  • If your service uses a network file system, it must use the second generation execution environment.

You can find more details about these constraints in the Container runtime contract.

Programming language support

Cloud Run allows you to write code in the programming language of your choice.

The build and deploy quickstarts provides samples in many popular languages.

Using a web server

You can use a web server to listen on the required port, and to process and route incoming requests. For example, Node.js developers can use Express.js, Python developers can use Flask, Ruby developers can use Sinatra, and so forth.

Containerizing your code

See Containerize your code for details.

What's next