This topic describes the background information and scenarios in which asynchronous invocations can be used. This topic also describes how to defer the invocation of a function.

Background information

When Function Compute receives an asynchronous invocation request, the system returns a response immediately after the request is persisted instead of waiting for the request to be completed before returning a response. Function Compute ensures that the request is executed at least once. To obtain the results of the asynchronous invocation, you can configure destinations for the asynchronous invocation. For more information, see Result callback. To obtain the status of the asynchronous request at each phase, you can enable the task mode. For more information, see Overview.


If your function contains logic that is time-consuming, resource-consuming, or error-prone, you can use asynchronous invocations to allow your programs to respond to traffic spikes more quickly and reliably. Examples:
  • In a user registration system, a new user sends a registration request. After the registration is successful, the system sends email notifications to the user. The action of sending an email can be separated from the registration process and executed asynchronously.
  • When you upload a file, actions such as format conversion and import and export can be separated from the data upload process and executed asynchronously.
Note HTTP functions can be invoked synchronously or asynchronously. For more information, see Call API operations over HTTP.

Deferred invocation of a function

In some scenarios, after you submit an asynchronous invocation request, you may want Function Compute to defer the invocation. In this case, you can use the Function Compute API or SDK to defer the invocation.

Add the HTTP request header x-fc-async-delay to the code. Valid values: (0,3600). Unit: seconds. Function Compute invokes the function after the period specified by x-fc-async-delay elapses.

The following code provides an example on how to use Function Compute SDK for Go to defer a function invocation:
package main

import (
func main() {
        The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using the AccessKey pair to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. 
        We recommend that you do not save the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources under your account may be compromised. 
        In this example, the AccessKey pair is saved to the environment variables for authentication. 
        Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables in your local environment before you run the sample code. 
        The ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are automatically configured after you configure the execution permissions in the runtime of Function Compute. 
    fcClient, err := fc.NewClient(fmt.Sprintf("", os.Getenv("ACCOUNT_ID")),
        "2016-08-15", os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
    if err != nil {

    // invoke function with delay
    invokeInput := fc.NewInvokeFunctionInput({ServiceName}, {FunctionName}).WithPayload({payload})
    invokeInput = invokeInput.WithAsyncInvocation().WithHeader("x-fc-async-delay", "200")
    _, err := FCClient.InvokeFunction(invokeInput)
    if err != nil {
Important Invocations that are deferred by using the preceding method may be not accurate in some scenarios. If you need a more accurate deferred invocation, use a time trigger. For more information, see Create a trigger. Valid values:

Common features

See the following topics to learn about common features of asynchronous invocations: