Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pulse ga changes #5692

Merged
merged 45 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2ac0fb3
feat: add pulse error reference
ankur-arch Mar 1, 2024
f26e1ab
enhance: change to known limitations and enhance reasoning for databa…
ankur-arch Mar 1, 2024
07638af
feat: add section on replication slots
ankur-arch Mar 1, 2024
3042ef5
feat: add replication slot submission image
ankur-arch Mar 1, 2024
d03ac94
feat: add faq for pulse regarding throughput
ankur-arch Mar 1, 2024
526af16
fix: fix indentation
ankur-arch Mar 1, 2024
82e349c
fix: update pulse information regarding ssl and support
ankur-arch Mar 1, 2024
8ccec06
fix: fix indentation and prune content
ankur-arch Mar 4, 2024
930a02d
feat: add database providers
ankur-arch Mar 4, 2024
f888135
fix: broken link (#5684)
ankur-arch Feb 28, 2024
f2349af
update docs about relation joins to include mysql (#5686)
nikolasburk Feb 28, 2024
740fe11
Update documentation related to the latest AWS Lambda runtime nodejs2…
jharrell Feb 29, 2024
d17a858
feat: add example projects
ankur-arch Mar 4, 2024
6b5d12e
Merge branch 'main' into pulse-ga
ankur-arch Mar 4, 2024
8c36485
Optimised images with calibre/image-actions
github-actions[bot] Mar 4, 2024
9adc4d9
fix: indentation and add examples
ankur-arch Mar 4, 2024
a623550
fix: add indendation, clear references of slack and update product na…
ankur-arch Mar 4, 2024
db5bc1c
fix: correct spelling for unreachability
ankur-arch Mar 4, 2024
48a05fe
fix: remove grammatical errors
ankur-arch Mar 4, 2024
7b9c87f
fix: remove limitation
ankur-arch Mar 4, 2024
e5325ec
Merge branch 'main' into pulse-ga
ankur-arch Mar 6, 2024
40b7bf8
feat: add replication slot and neon docs
ankur-arch Mar 7, 2024
608c9b8
Optimised images with calibre/image-actions
github-actions[bot] Mar 7, 2024
be73ea3
fix: fix word
ankur-arch Mar 7, 2024
9666b6b
feat: remove early access
ankur-arch Mar 7, 2024
c689373
feat: add additional section on pulse
ankur-arch Mar 8, 2024
1cfa5aa
enhance: fix indentation
ankur-arch Mar 8, 2024
32249c1
Update content/400-pulse/100-what-is-pulse.mdx
ankur-arch Mar 10, 2024
413f433
Update content/400-pulse/100-what-is-pulse.mdx
ankur-arch Mar 10, 2024
aa4cf9e
Update content/400-pulse/100-what-is-pulse.mdx
ankur-arch Mar 10, 2024
ba19219
Update content/400-pulse/100-what-is-pulse.mdx
ankur-arch Mar 10, 2024
4530e53
enhance: getting started definition of Pulse
ankur-arch Mar 10, 2024
5a17ae0
enhance: known limitations section
ankur-arch Mar 10, 2024
c52dd79
enhance: update concepts page
ankur-arch Mar 10, 2024
fe8baf4
enhance: reshuffle faq section
ankur-arch Mar 10, 2024
8b2dd42
fix: broken summary tag
ankur-arch Mar 10, 2024
1815a84
feat: restructure getting started page and divide setup
ankur-arch Mar 11, 2024
eac3233
feat: add more content to waht is pulse
ankur-arch Mar 11, 2024
4db1f5e
feat: restructure content
ankur-arch Mar 11, 2024
f368196
Optimised images with calibre/image-actions
github-actions[bot] Mar 11, 2024
dce1f70
feat: refine what is pulse
ankur-arch Mar 11, 2024
50b0150
feat: refine pulse further
ankur-arch Mar 11, 2024
0415d12
feat: api reference pulse
ankur-arch Mar 11, 2024
61ff418
enhance: refine content a bit further
ankur-arch Mar 11, 2024
68bd64f
fix: spelling mistakes and roken links
ankur-arch Mar 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions content/200-orm/500-reference/250-error-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,38 @@ The engine failed to start. For example, it couldn't establish a connection to t
#### <inlinecode>P6009</inlinecode> (<inlinecode>ResponseSizeLimitExceeded</inlinecode>)

The global response size limit of Accelerate has been exceeded. You can find the limit [here](/accelerate/limitations#response-size-limit).

### Prisma Pulse

Prisma Pulse-related errors start with <inlinecode>P61xx</inlinecode>.

#### <inlinecode>P6100</inlinecode> (<inlinecode>ServerError</inlinecode>) – HTTP Status <inlinecode>500</inlinecode>

An unexpected server error occurred.
This can happen due to a technical issue within the Prisma Pulse or its infrastructure.
For any incidents related to Prisma Pulse, you can refer to our status page [here](https://www.prisma-status.com/) and reach out to our support team through one of our available [channels](https://www.prisma.io/docs/platform/support) to report your issue.

#### <inlinecode>P6101</inlinecode> (<inlinecode>DatasourceError</inlinecode>) – HTTP Status <inlinecode>400</inlinecode>

Reasons:

1. The datasource is not reachable by Prisma Pulse. The Console will validate the connection when enabling Pulse to reduce the likelihood of this error. However, the datasource may become unavailable after the configuration step, resulting in this error.
2. The datasource is reachable, but did not meet the requirements for Prisma Pulse. The Console will validate the configuration when enabling Pulse to reduce the likelihood of this error. However, the datasource may change after the configuration step, resulting in this error.

#### <inlinecode>P6102</inlinecode> (<inlinecode>Unauthorized</inlinecode>) – HTTP Status <inlinecode>400</inlinecode>

The API key is invalid.

#### <inlinecode>P6103</inlinecode> (<inlinecode>ProjectDisabledError</inlinecode>) – HTTP Status <inlinecode>400</inlinecode>

Prisma Pulse is not enabled for the configured API key.

#### <inlinecode>P6104</inlinecode> (<inlinecode>AccountHoldError</inlinecode>) – HTTP Status <inlinecode>400</inlinecode>

Your Prisma Data Platform account has been blocked, potentially due to exceeding the usage limit included in your current plan. Please review the error message for further information.

If you require further assistance, please get in touch with us via one of our support [channels](https://www.prisma.io/docs/platform/support).

#### <inlinecode>P6105</inlinecode> (<inlinecode>VersionNotSupported</inlinecode>) – HTTP Status <inlinecode>400</inlinecode>

The Prisma version of the project is not compatible with Prisma Pulse.
27 changes: 21 additions & 6 deletions content/400-pulse/100-what-is-pulse.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,31 @@ toc: true

<TopBlock>

[Pulse](https://www.prisma.io/data-platform/pulse) is a managed [change data capture (CDC)](https://en.wikipedia.org/wiki/Change_data_capture) service that captures change events from your database and delivers them instantly to your applications. With Pulse, you can quickly build real-time applications in a type-safe manner using [Prisma Client](/orm/prisma-client).
[Prisma Pulse](https://www.prisma.io/data-platform/pulse) is managed database-event infrastructure that captures and distributes your database events to your application. It simplifies subscribing to type-safe data changes with an extended [Prisma Client](/orm/prisma-client) to power real-time functionality.

</TopBlock>

## How Prisma Pulse works

Prisma Pulse leverages Change Data Capture (CDC) to efficiently observe and capture database changes as they occur. By monitoring the database's transaction log, Prisma Pulse identifies change events like inserts, updates, and deletes without impacting the database's performance.

The captured events are processed, evaluated, and swiftly distributed to relevant client subscriptions ensuring your applications stay synchronized with the latest database state.

This eliminates the need for complex polling or manual data synchronization, saving you development time and effort.

![What is Pulse](./images/what-is-pulse.png)

<Admonition type="warning">
## What you can build with Prisma Pulse

Pulse is currently in [Early Access](/platform/maturity-levels#early-access). Although we already have high confidence in it, the nature of an Early Access product is that significant iterations might happen at any time. Therefore, we advise against using it in a system that requires stability.<br /><br />
Prisma Pulse can power real-time functionality like chat, notifications, data broadcast, data synchronization, and more. It's ideal for ensuring data consistency in distributed systems, enhancing real-time user experiences.

We strongly recommend evaluating Pulse with a dedicated database instance that is exclusively used for Pulse and where downtime and data loss would be acceptable. Prisma assumes no responsibility for downtime or data loss.
![Prisma Pulse use-cases](./images/pulse-usecase.png)

</Admonition>
## Examples

</TopBlock>
Here are a few example projects using Prisma Pulse:

| Project | Description |
| :--------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| [pulse-starter](https://github.com/prisma/pulse-starter) | General Pulse starter project. |
| [pulse-resend-demo](https://github.com/prisma/pulse-resend-demo) | Optimize your onboarding with Pulse by triggering welcome emails via Resend for new user sign-ups. |
179 changes: 44 additions & 135 deletions content/400-pulse/200-getting-started.mdx
Original file line number Diff line number Diff line change
@@ -1,166 +1,59 @@
---
title: 'Getting started'
metaTitle: 'Getting started with Pulse'
metaDescription: 'Learn how to get up and running with Pulse.'
tocDepth: 3
metaTitle: 'Getting started with Prisma Pulse'
metaDescription: 'Learn how to get up and running with Prisma Pulse.'
tocDepth: 4
toc: true
---

<TopBlock></TopBlock>

## Prerequisites

To participate in Pulse's Early Access program, you need to meet the following prerequisites:
You'll need the following to integrate Prisma Pulse into your application;

- A GitHub account.
- Pulse requires [Prisma Client](/orm/prisma-client) version `4.16.1` or higher and [`@prisma/extension-pulse`](https://www.npmjs.com/package/@prisma/extension-pulse) version `v0.2.3` or higher.
- A publicly accessible PostgreSQL database.
- Ability to use the superuser account of the database instance. In the future, we will support the ability to connect to your database from Pulse with a limited access, non-superuser account.
- Prisma Data Platform workspace
- [Prisma Client](/orm/prisma-client) version `4.16.1` or higher and [`@prisma/extension-pulse`](https://www.npmjs.com/package/@prisma/extension-pulse) version `v0.2.3` or higher.
- A publicly accessible PostgreSQL (version 12+) database with [logical replication](https://www.postgresql.org/docs/current/logical-replication-quick-setup.html) enabled.
- Learn how to enable logical replication [here](/pulse/database-setup/general-database-instructions#enable-logical-replication)

You will also need a database with the following configurations:
## 1. Enable Pulse

- PostgreSQL version 12+.
- Ensure your database is publicly accessible.
- [Set the `wal_level` setting in PostgreSQL to `logical`](/pulse/getting-started#wal_level).
- A database superuser that can be used for connections inside Pulse.
- Connect to the database using `sslmode=disable` if the database provider uses self-signed certificates. _This is a Prisma Pulse [Early Access](/platform/maturity-levels#early-access) limitation that will be lifted before Prisma Pulse [General Availability](platform/maturity-levels#general-availability)_.
Access your Prisma Data Platform project and enable Prisma Pulse within an environment. We'll connect to your database and verify connectivity during setup.

## 1. Database setup
> Once enabled, you'll be prompted to create an API key that you'll use in your extended Prisma Client to authenticate requests. Store this API key in your application's `.env` file:
>
> ```env file=.env
> PULSE_API_KEY="your_lengthy_secure_pulse_api_key"
> ```

### General database configuration

#### Required settings

##### [<inlinecode id="wal_level">wal_level</inlinecode>](https://www.postgresql.org/docs/current/runtime-config-wal.html)

Some providers may not allow direct access to this setting. If you are unable to change this setting, please refer to the provider-specific guides for further assistance.

```sql
ALTER SYSTEM SET wal_level = logical;
```

You will need to restart the database after changing this setting.

#### Optional settings

The following increases the memory usage of the [write-ahead log](https://www.postgresql.org/docs/current/wal-intro.html) on your PostgreSQL database. We suggest setting these values initially and adjusting them if necessary.

##### <inlinecode>[max_replication_slots](https://www.postgresql.org/docs/current/runtime-config-replication.html)</inlinecode>

```sql
ALTER SYSTEM SET max_replication_slots = 20;
```

##### <inlinecode>[wal_keep_size](https://www.postgresql.org/docs/current/runtime-config-replication.html)</inlinecode>

```sql
ALTER SYSTEM SET wal_keep_size = 2048;
```

### Provider specific configuration

To learn about the database providers that Pulse supports, visit [here](/pulse/faq#what-database-providers-are-supported-with-pulse).

#### Railway

[Railway.app](https://railway.app) offers an excellent [templates feature](https://railway.app/templates). If you wish to quickly start with Pulse, you can use either of two templates:

- [Prisma Pulse DB Only](https://railway.app/template/pulse-pg): Provides a fresh, pre-configured PostgreSQL database which you can use with Pulse.
- [Prisma Pulse DB & App](https://railway.app/template/pulse-starter): Provides a pre-configured PostgreSQL database and a [Pulse starter app](https://github.com/prisma/pulse-starter).

##### Setup without using a template

<details><summary>1. Change the PostgreSQL database settings</summary>

You can run these queries in the Railway Database **Query** tab, using the [railway cli](https://docs.railway.app/databases/postgresql), or any other way you might run queries on your database.

1. Set the <inlinecode>[wal_level](https://www.postgresql.org/docs/current/runtime-config-wal.html)</inlinecode> to `logical`:

```sql
ALTER SYSTEM SET wal_level = logical;
```

2. Set the <inlinecode>[max_replication_slots](https://www.postgresql.org/docs/current/runtime-config-replication.html)</inlinecode> to `20`:

```sql
ALTER SYSTEM SET max_replication_slots = 20;
```

3. Set the <inlinecode>[wal_keep_size](https://www.postgresql.org/docs/current/runtime-config-replication.html)</inlinecode> to `2048`:

```sql
ALTER SYSTEM SET wal_keep_size = 2048;
```

4. Reload the PostgreSQL configuration:

```sql
SELECT pg_reload_conf();
```

</details>
<details>
<summary>2. Restart your database</summary>

1. Click on your database.

2. Navigate to the Deployments tab.

3. Go into the three-dots menu on the latest deployment and click the `Restart` option.

</details>

##### SSL mode

As Railway uses a self-signed certificate, you have to use [`sslmode=disable`](/orm/overview/databases/postgresql#configuring-an-ssl-connection) with Pulse. _This is a Prisma Pulse [Early Access](/platform/maturity-levels#early-access) limitation that will be lifted before Prisma Pulse [General Availability](platform/maturity-levels#general-availability)_.

## 2. Enable Pulse in a project

Log into the [Prisma Data Platform](https://console.prisma.io/login), create a new project and enable Pulse for that new project.

> An API key will be created after you enable and setup Pulse in your [project](/platform/concepts/projects).

## 3. Use Pulse in your application
## 2. Add Pulse to your application

<Admonition type="info">

We have created an [example repository](https://github.com/prisma/pulse-starter) on GitHub to help you get started using Pulse. If you would like to start there, you can do so.
We have created an [example repository](https://github.com/prisma/pulse-starter) on GitHub to help you get started using Prisma Pulse. If you would like to start there, you can do so.

</Admonition>

The following will show how you can utilize Pulse in an existing application. We will be adding Pulse to the [hello-prisma](/getting-started/setup-prisma/start-from-scratch/relational-databases-typescript-postgresql) example from our documentation.

### 3.1. Install the Pulse Prisma Client extension
We'll be adding Prisma Pulse to the [hello-prisma](/getting-started/setup-prisma/start-from-scratch/relational-databases-typescript-postgresql) starter project from our documentation.

In a project using [Prisma Client](/orm/prisma-client), run the following command to install the Pulse extension:

```terminal
npm install @prisma/extension-pulse
```
### 2.1. Install the Prisma Pulse Client extension

### Store your Pulse API key in your .env file
<Admonition>

The Pulse extension requires you to use an API key.

<Admonition type="info">

You should have received an API key when you added Prisma Pulse to your project in the Platform Console.
💡 Prisma Pulse requires [Prisma Client](/orm/prisma-client) version `4.16.1` or higher and [`@prisma/extension-pulse`](https://www.npmjs.com/package/@prisma/extension-pulse) `v0.2.3` or higher

</Admonition>

In `.env`, add a variable named `PULSE_API_KEY`:

```env file=.env
PULSE_API_KEY="YOUR-API-KEY"
Install the latest version of Prisma Client and Pulse Prisma Client extension

# Example:
# PULSE_API_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcGlfa2V5IjoiNGMxNzM0MGItMmFhYy00MGMxLWE1ZDctNzYyNmRjNjg3NjM4IiwidGVuYW50X2lkIjoiY2VhZjE0NThkZGUyYzJmNTU0ZmNkNTI2MmFmOWY1ODljMWJiZmRhNDU0N2UxMjM1ODk3MGQ2MGI1ZjRlNTU0OCIsImludGVybmFsX3NlY3JldCI6ImM1ZTcxYjJhLTE0NzdawdwDliZS1hM2IzLTczODFkNDM5ZmEwZSJ9.wCUlghC_suFBr2vnk0q_5I8iRNRDyEQo0W9rnhf6mCw"
```bash
npm install @prisma/client@latest @prisma/extension-pulse@latest
```

### 3.2. Create a Pulse-enabled Prisma Client
### 2.2. Extend your Prisma Client instance with the Pulse extension

To use Pulse, you must extend Prisma Client with the Pulse extension.
Add the following to extend your existing Prisma Client instance with the Pulse extension:
Add the following to extend your existing Prisma Client instance with the Prisma Pulse extension:

```ts
import { PrismaClient } from '@prisma/client'
Expand All @@ -171,9 +64,15 @@ const prisma = new PrismaClient().$extends(
)
```

### 3.3. Create your first Pulse subscription
<Admonition type="info">

You should have received an **API key** when you added Prisma Pulse to your environment in the Platform Console.

</Admonition>

With the Pulse extension applied, you may now use Pulse's `subscribe()` method on any model defined in your Prisma Schema to subscribe to data change events.
### 2.3. Create your first Prisma Pulse subscription

With the Prisma Pulse extension applied, you may now use Prisma Pulse's `subscribe()` method on any model defined in your Prisma Schema to subscribe to data change events.

In the example below, a subscription is made on a `user` table that listens for _any_ change event on that table:

Expand Down Expand Up @@ -209,3 +108,13 @@ main()
Refer to the [API Reference](/pulse/api-reference) section for more detail on the filtering options available to the `subscribe()` method.

</Admonition>

## Database setup

<Admonition>

Prisma Pulse requires a publicly accessible PostgreSQL (version 12+) database with logical replication enabled.

</Admonition>

To setup your database to work with Prisma Pulse, refer to the [database setup page](/pulse/database-setup).
Loading
Loading