This is a simple demo project, to show how you might set up Prisma Pulse with Inngest and NextJS, to run real-time, durable workflows with your serverless app.
This demo repo accompanies the blog article: Build real-time, durable workflows with Pulse and Inngest
To successfully run the project, you will need the following:
- An Inngest account
- The connection string of a Pulse-ready database (if you don't have one yet, you can configure your database following the instructions in our docs or use a Railway template)
- A Pulse API key which you can get by enabling Pulse in a project in your Prisma Data Platform account (learn more in the docs)
If you would like to deploy the project live, you will also need:
Pulse streams change events from your Postgres database and submit events to Inngest to trigger workflows and jobs.
NextJS is used in this demo app to be able to run the Inngest workflows, and also to provide a helpful UI for adding records to the database.
Follow the steps below to get both set up and running.
- Go into the
pulse
directory, and install dependencies:npm install
- Rename the
.env.example
file to.env
and set up your environment variables:DATABASE_URL
is the connection string to your databasePULSE_API_KEY
is found in your Prisma Data Platform account. See the Pulse documentation for help in getting your API key.INNGEST_EVENT_KEY
andINNGEST_SIGNING_KEY
are used to authenticate the service to Inngest in order to submit events. You hopefully set this up in an earlier step.
- The Prisma schema file in this project contains a single
User
model. You can map this model to the database and create the correspondingUser
table using the following command:npx prisma migrate dev --name init
- Generate the Prisma client:
npx prisma generate
- Run the Pulse service:
yarn build && yarn start
- Step into the
nextjs
directory, and install dependencies:npm install
- Rename the
.env.example
file to.env
and set up your environment variables:DATABASE_URL
is the connection string to your database
- Generate the Prisma client:
npx prisma generate
- Run the NextJS service locally:
npm run dev
- In a separate tab, run the Inngest service locally:
npx inngest-cli@latest dev
- Open the Inngest DevServer at https://localhost:8288
- Open a browser and navigate to https://localhost:3000
You can run this complete demo app by setting up all services and then adding a user to the database. Pulse will detect the database change and submit the event to Inngest, which will, in turn, run a demo workflow.
- Make sure all services are running (see instructions above for running each service)
- NextJS service
- Inngest service
- Pulse service
- Open https://localhost:3000 in your browser - you should see a simple UI with a form
- Enter a user name and email address, then click the button
- Watch your terminal logs to observe the events. Prisma Pulse will detect the database change that was applied by NextJS, and submit an event to Inngest. Inngest will pick up the event, and initiate a workflow to onboard the new user. The code will not send real emails, but will simply demonstrate the functionality of the workflow.
- Add this project to a new GitHub repo (you can use the same one as earlier)
- Set up a new project and deploy live with Railway (you can test for free with a Hobby account)
- Don’t forget to include the
DATABASE_URL
,PULSE_API_KEY
,INNGEST_SIGNING_KEY
andINNGEST_EVENT_KEY
environment variables
- Don’t forget to include the
- Add this project to a new GitHub repo
- Set up a new project and deploy live with Vercel (you can test for free with a Hobby account)
- Don’t forget to include your
DATABASE_URL
- Don’t forget to include your
- Sync your Vercel App with the Inngest Vercel Integration
- Create and save an Inngest Event Key and Signing Key to use in the next step (setting up Pulse)
- After deploying all services live (according to above instructions), browse to the URL given to your deployment by Vercel. It should look something like
your-app.vercel.app
- Add a user by entering a name and email address, then click the button
- Take a look at the Vercel runtime logs and the Railway logs to observe the events as they are executed
Some helpful links in case you need help: