SlideShare a Scribd company logo
1 of 22
Download to read offline
Building stateful apps
using serverless
How far can we go?
I’m Tiru
Hasura is :
- GraphQL on Postgres
- Serverless business logic
- Postgres as event source
I do:
- Product development
- Product management
- Developer advocacy
github.com/hasura/graphql-engine
@Tirumaraiand serverless!
An application
without state is
only contributing to
global warming!
Examples of few simple apps
1. Get an image as input, resize and store it somewhere. That’s state.
2. Register a user, and create a list of Todo items
That’s definitely state.
3. Given a city, retrieve the current weather.
Ah! No state?
Given a city, retrieve the current weather
There is no state, only if you
are NOT Yahoo Weather
What we have done is
delegated state to a
black-box
There are NO useful apps without state. All we can do is delegate, delegate and
delegate!
@Tirumarai
Patterns for delegating state
1) Send full context in event payload
2) Use BaaS aka managed services
3) Run lightweight long running proxies
4) Apply state externally
5) Use fast transactional databases (escape hatch)
@Tirumarai
Pattern #1: Send context with event
Send as much context as possible with an event
Event #1
"id": “42”
Event #2
"user_info": {
"user-id": "1"
},
"op": "UPDATE",
"data": {
"old":{
"id":"42",
"name": "jane"
},
"new": {
"id":"42",
"name": "john doe"
}
}
Obviate the need
for database read
❌ ✅
Example #1: Send context with event
Send email on user creation
"user_info": {
"user-id": "1",
"name": "Jane",
"address": "Ch. S",
},
"login": "Facebook",
"created": "14-02-19"
"utm": {
"source": "twit",
"campaign": "ad"
}
@Tirumarai
Pattern #2: Use BaaS/managed services
Use as much BaaS / managed services as you can afford.
Also known as serviceful serverless
Let someone else deal with state
Identity: Auth0
Media tools: Cloudinary
Search: Algolia
Notifications: Twilio
E.g.
@Tirumarai
Example #2: Use BaaS/managed services
Index items for search
Pattern #3: Run long running proxies
Sometimes, may need to run long running proxies for
managing state.
E.g. Delegate database connections to connection poolers
running on Fargate/managed containers
@Tirumarai
Example #3: Run long running proxies
Running a
GraphQL
service on
serverless
https://medium.com/open-graphql/
scaling-rdbms-for-graphql-backend
s-on-serverless-980ef24af171
Pattern #4 : Apply state externally
Make code stateless and return a final object to be
persisted.
Object is persisted reliably and idempotentically i.e.
definitely persisted and can handle duplicates.
@Tirumarai
Example #4 : Apply state externally
Hasura Event Triggers (pre/post hooks) - v2.0 wip
"objects": [{
"insert_user": {
"name": "john",
"loc": "hamburg"
}
}]
"objects": [{
"insert_user": {
"name": "john",
"loc": "hamburg",
"coord": "53N, 9E",
}
}]
Input Payload Output Payload
Easy unit testing, reliability
Pattern #5 : Use fast transactional databases
Sometimes, databases and transactions are just
unavoidable.
Use fast databases with lightweight process management
for more scale.
@Tirumarai
Example #5 : Use fast transactional
databases
Postgres + pgBouncer
Most NoSQL databases
@Tirumarai
What is stateless then?
A new perspective for serverless
Stateless == Idempotency?
What people usually mean by stateless is idempotency
If we can ensure idempotency, our stateful function seems
like a stateless function!
Managed services should be idempotent for use with
serverless
Caveats
Good enough, but not everything
1) Can’t reuse state
2) Can’t share state (no global variables)
3) Can’t address each other (no DNS names)
Demo time :)
A food delivery app
Thank you!
Tirumarai Selvan
@Tirumarai
hasura.io
github.com/hasura/graphql-engine

More Related Content

What's hot

What's hot (20)

An Intro to Elasticsearch and Kibana
An Intro to Elasticsearch and KibanaAn Intro to Elasticsearch and Kibana
An Intro to Elasticsearch and Kibana
 
Collecting Endpoint Security Logs Through Big Data Technology - Dedi Dwianto
Collecting Endpoint Security Logs Through Big Data Technology - Dedi DwiantoCollecting Endpoint Security Logs Through Big Data Technology - Dedi Dwianto
Collecting Endpoint Security Logs Through Big Data Technology - Dedi Dwianto
 
Building TimePiece
Building TimePieceBuilding TimePiece
Building TimePiece
 
Cloud Conf Varna - Cloud Application with AWS Lambda functions
Cloud Conf Varna - Cloud Application with AWS Lambda functionsCloud Conf Varna - Cloud Application with AWS Lambda functions
Cloud Conf Varna - Cloud Application with AWS Lambda functions
 
Elk - An introduction
Elk - An introductionElk - An introduction
Elk - An introduction
 
Scaling to Infinity - Open Source meets Big Data
Scaling to Infinity - Open Source meets Big DataScaling to Infinity - Open Source meets Big Data
Scaling to Infinity - Open Source meets Big Data
 
Simplified News Analytics in Presidential Election with Google Cloud Platform
Simplified News Analytics in Presidential Election with Google Cloud PlatformSimplified News Analytics in Presidential Election with Google Cloud Platform
Simplified News Analytics in Presidential Election with Google Cloud Platform
 
Distributed Tracing
Distributed TracingDistributed Tracing
Distributed Tracing
 
Reshaping Data Driven Application Development with GraphQL and AppSync
Reshaping Data Driven Application Development with GraphQL and AppSyncReshaping Data Driven Application Development with GraphQL and AppSync
Reshaping Data Driven Application Development with GraphQL and AppSync
 
GitHub Data and Insights
GitHub Data and InsightsGitHub Data and Insights
GitHub Data and Insights
 
Hands on experience in real-time data process with AWS Kinesis, Firehose, S3 ...
Hands on experience in real-time data process with AWS Kinesis, Firehose, S3 ...Hands on experience in real-time data process with AWS Kinesis, Firehose, S3 ...
Hands on experience in real-time data process with AWS Kinesis, Firehose, S3 ...
 
Power BI Streaming Datasets - San Diego BI Users Group
Power BI Streaming Datasets - San Diego BI Users GroupPower BI Streaming Datasets - San Diego BI Users Group
Power BI Streaming Datasets - San Diego BI Users Group
 
Piyali Kamra - Analytics and Data Visualization pipeline backed by AWS Glue &...
Piyali Kamra - Analytics and Data Visualization pipeline backed by AWS Glue &...Piyali Kamra - Analytics and Data Visualization pipeline backed by AWS Glue &...
Piyali Kamra - Analytics and Data Visualization pipeline backed by AWS Glue &...
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
SC7 Webinar 5 13/12/2017 UoA Presentation "Technical aspects of the 3rd secur...
SC7 Webinar 5 13/12/2017 UoA Presentation "Technical aspects of the 3rd secur...SC7 Webinar 5 13/12/2017 UoA Presentation "Technical aspects of the 3rd secur...
SC7 Webinar 5 13/12/2017 UoA Presentation "Technical aspects of the 3rd secur...
 
Distributed Tracing
Distributed TracingDistributed Tracing
Distributed Tracing
 
DE gitConnect
DE gitConnectDE gitConnect
DE gitConnect
 
Graph Computing with Apache TinkerPop
Graph Computing with Apache TinkerPopGraph Computing with Apache TinkerPop
Graph Computing with Apache TinkerPop
 
projects_with_descriptions
projects_with_descriptionsprojects_with_descriptions
projects_with_descriptions
 
Python and H2O with Cliff Click at PyData Dallas 2015
Python and H2O with Cliff Click at PyData Dallas 2015Python and H2O with Cliff Click at PyData Dallas 2015
Python and H2O with Cliff Click at PyData Dallas 2015
 

Similar to Building stateful apps using serverless

OGCE Overview for SciDAC 2009
OGCE Overview for SciDAC 2009OGCE Overview for SciDAC 2009
OGCE Overview for SciDAC 2009
marpierc
 

Similar to Building stateful apps using serverless (20)

Introduction to Apache Airflow
Introduction to Apache AirflowIntroduction to Apache Airflow
Introduction to Apache Airflow
 
Automating Workflows for Analytics Pipelines
Automating Workflows for Analytics PipelinesAutomating Workflows for Analytics Pipelines
Automating Workflows for Analytics Pipelines
 
OGCE Overview for SciDAC 2009
OGCE Overview for SciDAC 2009OGCE Overview for SciDAC 2009
OGCE Overview for SciDAC 2009
 
Salesforce integration questions
Salesforce integration questionsSalesforce integration questions
Salesforce integration questions
 
OGCE Project Overview
OGCE Project OverviewOGCE Project Overview
OGCE Project Overview
 
Distributed Tracing
Distributed TracingDistributed Tracing
Distributed Tracing
 
GDSC Cloud Jam.pptx
GDSC Cloud Jam.pptxGDSC Cloud Jam.pptx
GDSC Cloud Jam.pptx
 
Bronx study jam 2
Bronx study jam 2Bronx study jam 2
Bronx study jam 2
 
Evolution of Monitoring and Prometheus (Dublin 2018)
Evolution of Monitoring and Prometheus (Dublin 2018)Evolution of Monitoring and Prometheus (Dublin 2018)
Evolution of Monitoring and Prometheus (Dublin 2018)
 
System design for Web Application
System design for Web ApplicationSystem design for Web Application
System design for Web Application
 
AWS re:Invent 2016: Automating Workflows for Analytics Pipelines (DEV401)
AWS re:Invent 2016: Automating Workflows for Analytics Pipelines (DEV401)AWS re:Invent 2016: Automating Workflows for Analytics Pipelines (DEV401)
AWS re:Invent 2016: Automating Workflows for Analytics Pipelines (DEV401)
 
Skynet project: Monitor, analyze, scale, and maintain a system in the Cloud
Skynet project: Monitor, analyze, scale, and maintain a system in the CloudSkynet project: Monitor, analyze, scale, and maintain a system in the Cloud
Skynet project: Monitor, analyze, scale, and maintain a system in the Cloud
 
Self-service PR-based Terraform
Self-service PR-based TerraformSelf-service PR-based Terraform
Self-service PR-based Terraform
 
Distributed tracing 101
Distributed tracing 101Distributed tracing 101
Distributed tracing 101
 
Join 2017_Deep Dive_Workflows with Zapier
Join 2017_Deep Dive_Workflows with ZapierJoin 2017_Deep Dive_Workflows with Zapier
Join 2017_Deep Dive_Workflows with Zapier
 
Google Cloud Next '22 Recap: Serverless & Data edition
Google Cloud Next '22 Recap: Serverless & Data editionGoogle Cloud Next '22 Recap: Serverless & Data edition
Google Cloud Next '22 Recap: Serverless & Data edition
 
Flutter Forward EXTENDED - Ashimi0x .pdf
Flutter Forward EXTENDED - Ashimi0x .pdfFlutter Forward EXTENDED - Ashimi0x .pdf
Flutter Forward EXTENDED - Ashimi0x .pdf
 
Lambda architecture for real time big data
Lambda architecture for real time big dataLambda architecture for real time big data
Lambda architecture for real time big data
 
Evolving your api architecture with the strangler pattern
Evolving your api architecture with the strangler patternEvolving your api architecture with the strangler pattern
Evolving your api architecture with the strangler pattern
 
7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task
 

Recently uploaded

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Recently uploaded (20)

WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 

Building stateful apps using serverless

  • 1. Building stateful apps using serverless How far can we go?
  • 2. I’m Tiru Hasura is : - GraphQL on Postgres - Serverless business logic - Postgres as event source I do: - Product development - Product management - Developer advocacy github.com/hasura/graphql-engine @Tirumaraiand serverless!
  • 3. An application without state is only contributing to global warming!
  • 4. Examples of few simple apps 1. Get an image as input, resize and store it somewhere. That’s state. 2. Register a user, and create a list of Todo items That’s definitely state. 3. Given a city, retrieve the current weather. Ah! No state?
  • 5. Given a city, retrieve the current weather There is no state, only if you are NOT Yahoo Weather What we have done is delegated state to a black-box There are NO useful apps without state. All we can do is delegate, delegate and delegate! @Tirumarai
  • 6. Patterns for delegating state 1) Send full context in event payload 2) Use BaaS aka managed services 3) Run lightweight long running proxies 4) Apply state externally 5) Use fast transactional databases (escape hatch) @Tirumarai
  • 7. Pattern #1: Send context with event Send as much context as possible with an event Event #1 "id": “42” Event #2 "user_info": { "user-id": "1" }, "op": "UPDATE", "data": { "old":{ "id":"42", "name": "jane" }, "new": { "id":"42", "name": "john doe" } } Obviate the need for database read ❌ ✅
  • 8. Example #1: Send context with event Send email on user creation "user_info": { "user-id": "1", "name": "Jane", "address": "Ch. S", }, "login": "Facebook", "created": "14-02-19" "utm": { "source": "twit", "campaign": "ad" } @Tirumarai
  • 9. Pattern #2: Use BaaS/managed services Use as much BaaS / managed services as you can afford. Also known as serviceful serverless Let someone else deal with state Identity: Auth0 Media tools: Cloudinary Search: Algolia Notifications: Twilio E.g. @Tirumarai
  • 10. Example #2: Use BaaS/managed services Index items for search
  • 11. Pattern #3: Run long running proxies Sometimes, may need to run long running proxies for managing state. E.g. Delegate database connections to connection poolers running on Fargate/managed containers @Tirumarai
  • 12. Example #3: Run long running proxies Running a GraphQL service on serverless https://medium.com/open-graphql/ scaling-rdbms-for-graphql-backend s-on-serverless-980ef24af171
  • 13. Pattern #4 : Apply state externally Make code stateless and return a final object to be persisted. Object is persisted reliably and idempotentically i.e. definitely persisted and can handle duplicates. @Tirumarai
  • 14. Example #4 : Apply state externally Hasura Event Triggers (pre/post hooks) - v2.0 wip "objects": [{ "insert_user": { "name": "john", "loc": "hamburg" } }] "objects": [{ "insert_user": { "name": "john", "loc": "hamburg", "coord": "53N, 9E", } }] Input Payload Output Payload Easy unit testing, reliability
  • 15. Pattern #5 : Use fast transactional databases Sometimes, databases and transactions are just unavoidable. Use fast databases with lightweight process management for more scale. @Tirumarai
  • 16. Example #5 : Use fast transactional databases Postgres + pgBouncer Most NoSQL databases @Tirumarai
  • 17. What is stateless then? A new perspective for serverless
  • 18. Stateless == Idempotency? What people usually mean by stateless is idempotency If we can ensure idempotency, our stateful function seems like a stateless function! Managed services should be idempotent for use with serverless
  • 20. Good enough, but not everything 1) Can’t reuse state 2) Can’t share state (no global variables) 3) Can’t address each other (no DNS names)
  • 21. Demo time :) A food delivery app