graphql-engine/event-triggers.md

107 lines
4.8 KiB
Markdown
Raw Normal View History

# Event triggers on Postgres
2018-09-09 09:34:40 +03:00
Trigger webhooks on database events using Hasura GraphQL Engine's event triggers.
![Event triggers demo](assets/event-triggers.gif)
## Highlights
* **Build reactive & async apps/features**: Trigger asynchronous serverless or cloud functions to reduce infrastructure costs and simplify DevOps for developers.
2018-10-16 09:38:27 +03:00
* **Atomic & Reliable**: Using native Postgres triggers, every relevant action on the database is captured as an event. Even if Hasura is down or being updated, events will be captured and delivered as soon as possible with an *atleast-once* guarantee. You can even configure delivery policies like `max_retries` and `retry_interval`.
* **Scalable**: The event-triggers system is horizontally scalable - if you need to handle more events, just throw more resources at it!
* **Works with existing, live databases**: Point it to an existing Postgres database to instantly listen to changes in your data and invoke webhooks.
* **Ready for observability & monitoring]**: Generated events are automatically instrumented with an event-id and structured logs emitted by Hasura make it easy for you to use your favourite tools to run an event-driven backend in production ([watch](https://youtu.be/WOPA52r3bzU) an overview using [Honeycomb](https://honeycomb.io/)).
## Quickstart:
### One-click deployment on Heroku
The fastest way to try event triggers out is via Heroku.
1. Click on the following button to deploy GraphQL Engine on Heroku with the free Postgres add-on:
[![Deploy to Heroku](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/hasura/graphql-engine-heroku)
2. Open the Hasura console
Visit `https://<app-name>.herokuapp.com` (*replace \<app-name\> with your app name*) to open the admin console.
3. Configure your first event trigger and webhook
2018-10-16 09:38:27 +03:00
Create a table, configure the database update you want to use as a trigger and instantly invoke a webhook by adding a new row in your table. Follow this [simple guide](https://docs.hasura.io/1.0/graphql/manual/getting-started/first-event-trigger.html).
### Other deployment methods
For Docker-based deployment and advanced configuration options, see [deployment guides](https://docs.hasura.io/1.0/graphql/manual/getting-started/index.html).
2018-09-09 09:34:40 +03:00
### Demo (*30 seconds*)
2018-09-09 09:34:40 +03:00
[![Create an event-trigger and webhook in 60 seconds](https://img.youtube.com/vi/EaTUVWnDCvA/0.jpg)](https://www.youtube.com/watch?v=EaTUVWnDCvA)
[Create an event-trigger and webhook in 60 seconds](https://youtu.be/EaTUVWnDCvA)
### Serverless boilerplates
Use one of the [serverless trigger
2020-01-05 14:36:54 +03:00
boilerplates](community/boilerplates/event-triggers) to deploy a webhook
that can capture database events.
Serverless/cloud-function platforms covered by boilerplates:
2020-01-05 14:36:54 +03:00
* [AWS Lambda](community/boilerplates/event-triggers/aws-lambda)
* [Google Cloud Functions](community/boilerplates/event-triggers/google-cloud-functions)
* [Azure Functions](community/boilerplates/event-triggers/azure-functions)
* [Zeit Now](community/boilerplates/event-triggers/zeit-now)
## Architecture
![Event triggers architecture](assets/event-triggers-arch.png)
## Demos & Tutorials: Building reactive & async apps/features
### Notifications
Trigger push notifications and emails based on database events. Try the demo and tutorial below to see how browser push notifications are triggered when the user inserts some data:
* [Watch demo](https://www.youtube.com/watch?v=nuSHkzE2-zo)
2018-11-27 13:31:56 +03:00
* [Try it out](https://serverless-push.demo.hasura.app/)
2019-10-30 05:51:42 +03:00
* [Tutorial](community/sample-apps/serverless-push)
<!--
### Async business logic
Convert complex, long-running business logic to be event-driven, asynchronous and resilient to failure. Try this demo and tutorial below to see how an image processing job is run asynchronously to convert an image to a black-and-white version:
* [Watch demo](https://some-youtube-demo.com) (*10:00 mins*)
* [Try it out](https://some-link/)
* [Tutorial](https://some-other-link)
-->
### Data transformation (ETL)
Transform and load data into external data-stores. Check out this demo and tutorial below to see how Postgres data is transformed to build and populate an Algolia index:
* [Watch demo](https://youtu.be/kWVEBWdEVAA)
2018-11-27 13:31:56 +03:00
* [Try it out](https://serverless-etl.demo.hasura.app/)
2019-10-30 05:51:42 +03:00
* [Tutorial](community/sample-apps/serverless-etl)
2018-09-07 16:11:01 +03:00
### Building reactive UX for your async backend with realtime GraphQL
Propagate event-driven and asynchronous information to UI clients easily with GraphQL subscriptions & live-queries.
![Reactive apps architecture](assets/reactive-apps-arch.png)
**Watch**: [Building a reactive app with an async backend](https://youtu.be/kTSOxRrtCeI) (*04:15 mins*)
## Translations
This document is available in the following translations:
- [French :fr:](translations/event-triggers.french.md)