This document describes best practices for designing, implementing, testing, and deploying Cloud Run functions.
Correctness
This section describes general best practices for designing and implementing Cloud Run functions.
Write idempotent functions
Your functions should produce the same result even if they are called multiple times. This lets you retry an invocation if the previous invocation fails part way through your code. For more information, see retrying event-driven functions.
Ensure HTTP functions send an HTTP response
If your function is HTTP-triggered, remember to send an HTTP response, as shown below. Failing to do so can result in your function executing until timeout. If this occurs, you will be charged for the entire timeout time. Timeouts may also cause unpredictable behavior or cold starts on subsequent invocations, resulting in unpredictable behavior or additional latency.