Tirumarai Selvan, Product Lead at Hasura, published this guide which explores the different ways to deal with application state when writing business logic in serverless functions. Author uses Postgres as the database when talking about these different approaches, and often use Hasura as one of the glue solutions between your serverless functions and your Postgres database.
Serverless platforms do not allow the developer to write code that holds any long-term state.
The article discusses dfour apporaches, which can be carried forward to your favourite database solution:
- Approach #1: Connect to Postgres directly from your serverless function
- Approach #2: Use BaaS APIs from your serverless function
- Approach #3: Trigger serverless functions on Postgres events with rich event payloads
- Approach #4: Combine approaches above and use Postgres to orchestrate a workflow with the serverless functions driving state transitions
You will also get UML diagrams explaining each approach. Using some of the patterns described here, developers can extract the most amount of value in writing business logic in serverless functions. Very interesting read!
[Read More]