Building stateful apps
How far can we go?
Hasura is :
- GraphQL on Postgres
- Serverless business logic
- Postgres as event source
- Product development
- Product management
- Developer advocacy
without state is
only contributing to
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
There are NO useful apps without state. All we can do is delegate, delegate and
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)
Pattern #1: Send context with event
Send as much context as possible with an event
"name": "john doe"
Obviate the need
for database read
Example #1: Send context with event
Send email on user creation
"address": "Ch. S",
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
Media tools: Cloudinary
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
E.g. Delegate database connections to connection poolers
running on Fargate/managed containers
Example #3: Run long running proxies
Pattern #4 : Apply state externally
Make code stateless and return a final object to be
Object is persisted reliably and idempotentically i.e.
definitely persisted and can handle duplicates.
Pattern #5 : Use fast transactional databases
Sometimes, databases and transactions are just
Use fast databases with lightweight process management
for more scale.
Example #5 : Use fast transactional
Postgres + pgBouncer
Most NoSQL databases
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