Stateful Functions is an API that simplifies building distributed stateful applications. It’s based on functions with persistent state that can interact dynamically with strong consistency guarantees. The runtime is built on Apache Flink®.
Stateful Functions Applications
A stateful function is a small piece of logic/code existing in multiple instances that represent entities — similar to actors. Functions are invoked through messages and are:
- Stateful: Functions have embedded, fault-tolerant state, accessed locally like a variable.
- Virtual: Much like FaaS, functions don't reserve resources — inactive functions don't consume CPU/Memory.
Applications are composed of modules of multiple functions that can interact arbitrarily with:
- Exactly-once Semantics: State and messaging go hand-in-hand, providing exactly-once message/state semantics.
- Logical Addressing: Functions message each other by logical addresses. No service discovery needed.
- Dynamic and Cyclic Messaging: Messaging patterns don't need to be pre-defined as dataflows (dynamic) and are also not restricted to DAGs (cyclic).
A Runtime built for Serverless Architectures
The Stateful Functions runtime is designed to provide a set of properties similar to what characterizes serverless functions, but applied to stateful problems.
The runtime is built on Apache Flink, with the following design principles:
- Logical Compute/State Co-location: Messaging, state access/updates and function invocations are managed tightly together. This ensures a high-level of consistency out-of-the-box.
- Physical Compute/State Separation: Functions can be executed remotely, with message and state access provided as part of the invocation request. This way, functions can be managed like stateless processes and support rapid scaling, rolling upgrades and other common operational patterns.
- Language Independence: Function invocations use a simple HTTP/gRPC-based protocol so that Functions can be easily implemented in various languages.
References