Using Serverless Functions for stateless applications is straightforward. Not all Functions as a Service (FaaS) providers offer out of the box support for stateful applications. Using FaaS without understanding the requirements for deploying stateful applications may end up being expensive and operationally prohibitive. Even though early use cases for Functions as a Service like AWS Lambda were stateless, newer offerings from other cloud providers have made it easy for users to deploy stateful applications. As more enterprise customers adopt FaaS, we are seeing increased number of stateful applications deployed to FaaS.
In the first generation of FaaS platforms, due to the ephemeral nature of the platforms and short lived nature of the serverless functions, a push towards using FaaS only for stateless applications gained traction. More importantly, early FaaS platforms required developers to understand the operations if they had to use any kind of data store. But, the trend is slowly changing with a rethink on how data store is bundled with compute. As these newer generations of FaaS offerings mature, we can expect to see more stateful applications deployed on FaaS.
Building Stateful Applications with Serverless
A Stateful application saves data about each client session and uses that data the next time the client makes a request whereas Stateless app is an application program that does not save client data generated in one session for use in the next session with that client
Many business applications we use today are stateful applications. While some of these applications can be re-architected as stateless applications, we cannot entirely get rid of stateful applications. As organizations start using data centric applications, there is a clear expectation to support stateful workloads in Serverless platforms.
Depending on whether the database service comes bundled with the FaaS or not, Stateful applications can use the database either directly or through the API provided by Backend as a Service (BaaS) which abstracts away the complexity that comes with managing the database and making it scale with the Serverless Functions. S3 style API to write objects are file is an example. Many developers use S3 along with AWS Lambda to store objects that are processed by AWS Lambda. Zoho Catalyst users use GraphQL or ZCQL, Zoho Catalyst’s own Query Language, to handle data from the relational database service that comes bundled with Zoho Catalyst.
As Serverless platforms mature, you can expect to see support for more tooling support to handle state and make it easy to deploy stateful applications. With Serverless platforms becoming an useful candidate for running machine learning and artificial intelligence workloads, we can expect to see support for big data tools.
Considerations for Stateful Applications
If you are going to use the composition of functions (output of one function feeding as an input to another) as a way to handle state, then your “stateful” application will become complex too fast. If you are going to use a persistent storage to handle state, make sure the database service is integrated with the FaaS offering so that developers are not responsible for handling the scaling needs of the database. In the absence of such an integrated offering, using BaaS could help mitigate the overhead with handling the scaling.
The events in the relational database can also be used as the trigger for executing the functions in FaaS. Developers can also combine FaaS with relational databases in workflows in lieu of complex applications. However, developers are responsible for ensuring resiliency in the case of building such workflow to build complex applications.
While stateless workloads are still the prevalent use cases in FaaS platforms, newer platforms make it easy to deploy stateful applications by providing a more integrated offering that makes it easy to store sessions and state in the application. As more data centric workloads move to FaaS, expect to see support for big data and other data intensive workloads.