All Products
Search
Document Center

Function Compute:Asynchronous invocation

Last Updated:Apr 17, 2026

For functions with long-running, resource-intensive, or error-prone logic, use asynchronous invocation to improve application responsiveness and reliably handle traffic spikes. When you invoke a function asynchronously, you do not need to wait for a response. Function Compute persists the request in an internal queue for reliable processing. This topic describes the use cases and common features of asynchronous invocation.

Use cases

Example use cases for asynchronous invocation include:

  • Audio and video processing

    When you use Function Compute for audio and video workloads, you often run time-consuming tasks such as encoding, decoding, and transcoding. By invoking these tasks asynchronously, they run in the background without blocking the front end, improving the user experience. If a project is large, you can also split it into multiple tasks for parallel processing, or convert a video into multiple formats by invoking multiple functions asynchronously. This shortens the overall processing time.

  • Data ETL processing

    In an extract, transform, and load (ETL) pipeline, the process of extracting data from a source, transforming it, and loading it into a destination system may involve multiple independent operations, such as database queries, file I/O, or data cleansing. Asynchronous invocation allows these operations to run in parallel, which reduces processing time and improves system performance. For long-running tasks, such as processing large datasets or complex data transformations, asynchronous invocation allows these tasks to run in the background, which improves the user experience by not blocking the front end.

  • Developing web applications

    You can use Function Compute with other cloud services to quickly build web applications. When users submit forms, run search queries, or load content-heavy pages, asynchronous invocation can prevent the page from freezing due to long waits for back-end responses. Users can continue to interact with other parts of the page without experiencing noticeable latency. In high-concurrency scenarios, such as when a large number of users access the application simultaneously, asynchronous invocation can distribute the request load and prevent service overload.

Deferred invocation

You can configure Function Compute to trigger an asynchronous invocation after a specified delay.

Add the HTTP request header x-fc-async-delay to your code. The value must be in seconds and within the range of (0, 3600). Function Compute starts a timer when the execution is triggered and invokes the function after the delay specified by x-fc-async-delay.

Retry policy

The asynchronous invocation mechanism provides built-in error handling and retries. If a step fails, the system can reschedule the task without affecting the overall workflow. When an asynchronous function invocation fails, Function Compute automatically retries the invocation.

Retry mechanism

The following table describes the default retry policy for common errors.

Error type

Server-side behavior

Billed

Solution

Function errors in Function Compute, such as HandledInvocationError and UnhandledInvocationError.

Retried up to 3 times by default, or based on the configured number of retries for the asynchronous invocation.

Yes. You are billed for each invocation. For more information about billing, see Billing Overview.

Troubleshoot your code.

Function concurrency limit exceeded.

The invocation is retried for 5 hours by using binary exponential backoff. After your function execution fails, the system retries after 0.5 seconds. Subsequent retry intervals increase exponentially: 1 second, 2 seconds, 4 seconds, 8 seconds, and so on, for up to 5 hours.

No

By default, the total number of instances for a single Alibaba Cloud account in a single region is 100. The actual value is subject to Quota Center. To request a quota increase, go to Quota Center.

Internal system error.

No

Join the DingTalk user group (ID: 64970014484) for support.

Insufficient Function Compute resources.

No

Configure the retry policy

Function Compute allows you to customize the maximum number of retries and the maximum message lifetime.

  1. Log on to the Function Compute console. In the left-side navigation pane, choose Function Management > Functions.

  2. In the top navigation bar, select a region. On the Functions page, click the target function.

  3. On the function details page, click the Tasks tab, and then click Task Mode to the right of Modify. In the Task Mode panel, set the following parameters. After you complete the configuration, click Deploy.

    Parameter

    Description

    Task Mode

    Specifies whether to enable Task Mode for an asynchronous task. For more information, see Asynchronous tasks.

    Maximum Retries

    The maximum number of retries for an asynchronous invocation. The value must be an integer from 0 to 8.

    By default, Function Compute retries a failed asynchronous invocation 3 times. You can adjust the number of retries based on your business requirements.

    Maximum Message Lifetime

    The maximum lifetime of a message in an asynchronous invocation queue. The value must be an integer from 1 to 604,800. The default value is 86,400. Unit: seconds.

    This duration is calculated from the time the asynchronous invocation is triggered. If the message lifetime exceeds the configured value, the message is discarded. Discarded messages are recorded by the Asynchronous Invocation Events monitoring metric in CloudMonitor. For more information about metrics, see Monitoring metrics.

Result callback

When Function Compute receives an asynchronous invocation request, it persists the request and immediately returns a response without waiting for the request to execute. To retain requests that are discarded after all retries fail, or to notify a downstream service of the asynchronous invocation result, configure the result callback feature. After you configure a destination service, Function Compute automatically calls back the corresponding service based on the execution result when the asynchronous invocation is complete.

How it works

The following figure shows the result callback workflow.

Use cases

  • Save discarded events for subsequent processing

    When an asynchronous request fails and fails all retries based on the configured policy, Function Compute discards the request. If you have configured a failure destination, Function Compute automatically pushes the context information of the failed request to a messaging service such as ApsaraMQ for RocketMQ for subsequent processing. You can also set another function as the destination service. In this case, Function Compute automatically pushes the context information of the failed request to that function to execute your custom error-handling logic.

  • Automatically notify downstream services of execution results

    After a successful execution, if a success destination is configured, the Function Compute system automatically pushes the request's context to the downstream destination service. For example, if you configure Function Compute to automatically decompress a ZIP file uploaded to OSS and want to receive a message notification upon completion, you can configure a result callback destination service for the target function.

Supported destination services

If an asynchronous invocation's result meets the configured conditions, Function Compute pushes the request context and data to the specified destination service. You can configure different destination services for different functions, aliases, and versions. The following destination services are supported for asynchronous invocation:

  • Simple Message Queue (formerly MNS)

  • Function Compute

  • EventBridge

  • ApsaraMQ for RocketMQ

Note
  • You can configure only 4.0 series instances of ApsaraMQ for RocketMQ as a destination service. 5.0 series instances are not supported.

  • For information about the payload limits for destination services, see Function runtime resource limits.

The configuration for asynchronous invocation destinations includes the following:

  • Event content for asynchronous invocation destinations

    When Simple Message Queue (formerly MNS), Function Compute, or ApsaraMQ for RocketMQ is the destination for an asynchronous function invocation, the event content has the following format.

    {
      "timestamp": 1660120276975,
      "requestContext": {
        "requestId": "xxx",
        "functionArn": "acs:fc:{regionid}:{accountid}:functions/xxxx",
           "condition": "FunctionResourceExhausted", 
            "approximateInvokeCount": 3
      },
      "requestPayload": "",
      "responseContext": {
        "statusCode": 200,
        "functionError": ""
      },
      "responsePayload": ""
    }

    Table 1. Parameter descriptions

    Parameter

    Description

    timestamp

    The timestamp of the invocation.

    requestContext

    The request context.

    requestContext.requestId

    The request ID of the asynchronous invocation.

    requestContext.functionArn

    The Alibaba Cloud Resource Name (ARN) of the asynchronously invoked function.

    requestContext.condition

    The error code of the invocation.

    requestContext.approximateInvokeCount

    The number of times the asynchronous invocation was executed. A value greater than 1 indicates that Function Compute has retried the invocation.

    requestPayload

    The original payload of the function request.

    responseContext

    The response context.

    responseContext.statusCode

    The system status code returned by the function invocation. If the status code is not 200, a system error occurred.

    responseContext.functionError

    The error message from the invocation.

    responsePayload

    The original payload returned by the function execution.

    When EventBridge is used as the destination for an asynchronous function invocation, the event is in the following format. For more information, see Event Overview.

    {
        "datacontenttype": "application/json",
        "aliyunaccountid": "143xxxx",
        "data": {
            "requestContext": {
                "condition": "",
                "approximateInvokeCount": 1,
                "requestId": "0fcb7f0c-xxxx",
                "functionArn": "acs:fc:{regionid}:{accountid}:functions/xxxx"
            },
            "requestPayload": "",
            "responsePayload": "",
            "responseContext": {
                "functionError": "",
                "statusCode": 200
            },
            "timestamp": 1660120276975
        },
        "subject": "acs:fc:{regionid}:{accountid}:functions/xxxx",
        "source": "acs:fc",
        "type": "fc:AsyncInvoke:succeeded",
        "aliyunpublishtime": "2021-01-03T09:44:31.233Asia/Shanghai",
        "specversion": "1.0",
        "aliyuneventbusname": "xxxxxxx",
        "id": "ecc4865xxxxxx",
        "time": "2021-01-03T01:44:31Z",
        "aliyunregionid": "cn-shanghai-vpc",
        "aliyunpublishaddr": "199.99.xxx.xxx"
    }
  • Payload limits

    The maximum payload limits for supported destination services are as follows:

    • Simple Message Queue (formerly MNS): 64 KB

    • Function Compute: subject to the limits described in Function runtime resource limits.

    • EventBridge: 64 KB

    • ApsaraMQ for RocketMQ: 4 MB

  • Avoid invocation loops

    When configuring a destination for an asynchronous execution, avoid creating an invocation loop. For example, you configure Function B as the destination for successful invocations of Function A, and Function A as the destination for successful invocations of Function B. In this case, if you asynchronously trigger Function A and it executes successfully, an invocation loop from A to B and then back to A may occur.

Configure a destination service

  1. Log on to the Function Compute console. In the left-side navigation pane, choose Function Management > Functions.

  2. In the top navigation bar, select a region. On the Functions page, click the target function.

  3. On the function details page, click the Tasks tab, and then click Edit to the right of Modify. In the Task destination panel, set the following parameters. After you complete the configuration, click Deploy.

    • Configure a success destination

      Set Invoke Other Services upon Success to Enable, and then configure the destination service for successful executions. The parameters are described as follows:

      Parameter

      Description

      Destination Service

      Function Compute. When you select Function Compute as the destination service, you must configure the following parameters:

      • Function name: Specify the name of the destination function.

      • Version or alias: Specify the alias or version of the function.

      Simple Message Queue (formerly MNS). When you select Simple Message Queue (formerly MNS) as the destination service, you must configure the following parameters:

      • Destination type: Select a destination type. Valid values:

        • Queue:

          The queue model provides a reliable, high-concurrency one-to-one consumption model, where each message in a queue can be consumed by only one consumer.

        • Topic:

          The topic model provides a one-to-many publish-subscribe model that supports message notifications.

      • Queue: Select the name of the Simple Message Queue (formerly MNS) queue. This parameter is required if you set Queue to Queue.

      • Topic: Select the name of the Simple Message Queue (formerly MNS) topic. This parameter is required if you set Topic to Topic.

      ApsaraMQ for RocketMQ. If you select ApsaraMQ for RocketMQ as the destination service, you must configure the following parameters:

      • Instance: Select the destination instance.

      • Topic: Select the destination topic.

      EventBridge. If you select EventBridge as the destination service, you must specify a Custom event bus.

    • Configure a failure destination

      Set Invoke Other Services upon Failure to Enable, and then configure the destination service for failed executions. The parameters are the same as those for a success destination.

Callback failures

Callbacks to a destination service can fail due to insufficient permissions or service unavailability. Function Compute provides relevant metrics and logs that you can use for troubleshooting. The following table describes common errors and the corresponding system behaviors.

Error code

Cause

System behavior

5xx

Throttling or content errors.

The Function Compute system automatically retries with exponential backoff. The initial retry interval is 500 ms, and the maximum retry duration is 30 minutes.

4xx

Missing permissions, invalid request parameters (for example, the destination resource is deleted), or the request body exceeds the destination service limit.

Returns an error and records the error information.

Result callback metrics

If a callback to the destination service fails, Function Compute records the corresponding metrics in the console. You can log on to the Function Compute console. In the left-side navigation pane, choose . Then, in the Function Name list, click the name of the target function to view its metrics.

Metric name

Description

Destination Invocation Errors (FunctionDestinationErrors)

The number of failed attempts to invoke the destination for an asynchronous function invocation. The metric is aggregated by sum per minute or per hour.

Destination Invocation Successes (FunctionDestinationSucceed)

The number of successful attempts to invoke the destination for an asynchronous function invocation. The metric is aggregated by sum per minute or per hour.

For more information about monitoring metrics, see Monitoring Metrics.

FAQ

How to trigger an asynchronous invocation?

You can use one of the following methods to asynchronously invoke a function in Function Compute:

  • Log on to the Function Compute console, find the target function, go to the Test tab, select I want to make the call asynchronously., and then click Test Function.

  • Call the InvokeFunction API and set the x-fc-invocation-type parameter to Async.

  • Use Serverless Devs to configure an asynchronous invocation. Set the invocation-type parameter to Async. For more information, see Invoke a function.

  • Create a trigger that supports asynchronous invocation to asynchronously trigger the function. For more information, see Event-driven invocations.

  • When you use an HTTP trigger or a custom domain for an invocation, set the X-Fc-Invocation-Type request header to Async, as shown in the following example.

    curl -v -H "X-Fc-Invocation-Type: Async" https://example.cn-shenzhen.fcapp.run/$path
    Note
    • Call a Web Function: For example, if you use Flask and want to test a Python function with a route defined as @app.route('/test'), replace $path with test. When you test a Python function with a route defined as @app.route('/'), call the public endpoint of the HTTP trigger directly.

    • Invoke an Event Function: Directly call the public endpoint of the HTTP trigger.

Next steps

To track the status of an asynchronous request at each stage, enable Task Mode. For more information, see Asynchronous tasks.