This is not the End: Rethinking Serverless Function Termination

Kalev Alpernas, Aurojit Panda, Mooly SagivarXiv 2022 · OpenReview

Abstract

Elastic scaling is a central benefit of serverless platforms, requiring resources to scale up and down in response to workloads. However, current platforms incorrectly assume that application processing is complete the moment a response is generated. This paper identifies that such platforms do not account for pending asynchronous I/O operations, leading to data inconsistency and "broken promises." We propose an extension to serverless semantics that decouples response generation from termination, demonstrating its efficacy through an implementation in OpenWhisk.

Introduction

Serverless computing, or Functions-as-a-Service (FaaS), promised a world where developers focus solely on code while the platform handles scaling and resource management. However, a fundamental mismatch exists between how these platforms manage resource termination and how modern asynchronous programming languages (like Node.js or Python) actually work. As revealed by Alpernas, Panda, and Sagiv, the aggressive scale-down strategies of platforms like AWS Lambda or OpenWhisk can lead to silent failures in asynchronous tasks.

The Problem: Early Termination and Asynchronous I/O

The core issue is that current serverless platforms couple function termination with the act of sending a response to the user. In a traditional server environment, a background task (like a database write) can continue after a response is sent. In serverless, the platform often "freezes" or terminates the execution environment immediately after the response.

This leads to two critical safety issues:

  1. Broken Promises: Asynchronous tasks intended to run in the background are killed before completion.
  2. Cross-Event Interference: If a container is reused, a "zombie" task from a previous request might resume during a subsequent request, potentially corrupting data with stale information.

Methodology: Mapping the Execution Flow

To address this, the authors developed a mathematical model using small-step operational semantics to define function behavior. A key tool in their analysis is the Promise Graph, which maps the causal relationships between asynchronous operations.

Figure 1: A promise graph illustrating the divergence between the path to a response (p18) and background tasks (p13, p14).

As shown in Figure 1, an application might initiate multiple paths. One path leads to producing a response ($p_{18}$), while another handles a background database write ($p_{13}$). If the platform terminates the function upon reaching $p_{18}$, the write operation at $p_{13}$ may never complete or may be interrupted, leading to the "broken promise" scenario.

The researchers modified the OpenWhisk platform to test their proposed solution. They introduced a new await HTTP API and a global end() function, allowing developers to explicitly signal when all background work is truly finished, independent of when the response was sent.

Key Results and Evaluation

The authors evaluated their approach using qualitative analysis of real-world developer issues on Stack Overflow and performance benchmarks on a modified OpenWhisk instance.

  • Safety Guaranteed: The proposed semantics were proven to eliminate both broken promises and cross-event interference.
  • Low Performance Overhead: The cost of this added safety is minimal. Benchmarks showed an overhead of only 8ms for warm starts and 25ms for cold starts.
  • Improved Reliability: By decoupling response from termination, developers can reliably use standard libraries and perform "fire-and-forget" tasks (like logging or secondary writes) without fear of data loss.

Conclusion and Future Work

Current serverless platforms prioritize resource efficiency at the expense of correctness for asynchronous applications. By decoupling response generation from termination, platforms can support modern programming patterns safely. While the current proposal requires manual signaling via end(), future work could leverage static analysis to automate this process, further reducing developer burden while maintaining the integrity of serverless executions.

Summary updated

Abstract

Elastic scaling is one of the central benefits provided by serverless platforms, and requires that they scale resource up and down in response to changing workloads. Serverless platforms scale-down resources by terminating previously launched instances (which are containers or processes). The serverless programming model ensures that terminating instances is safe assuming all application code running on the instance has either completed or timed out. Safety thus depends on the serverless platform's correctly determining that application processing is complete. In this paper, we start with the observation that current serverless platforms do not account for pending asynchronous I/O operations when determining whether application processing is complete. These platforms are thus unsafe when executing programs that use asynchronous I/O, and incorrectly deciding that application processing has terminated can result in data inconsistency when these platforms are used. We show that the reason for this problem is that current serverless semantics couple termination and response generation in serverless applications. We address this problem by proposing an extension to current semantics that decouples response generation and termination, and demonstrate the efficacy and benefits of our proposal by extending OpenWhisk, an open source serverless platform.
BibTeX
@misc{alpernas2022this,
  author = {Kalev Alpernas and Aurojit Panda and Mooly Sagiv},
  title = {{This is not the End: Rethinking Serverless Function Termination}},
  year = {2022},
  eprint = {2211.02330},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2211.02330},
}
Figure