Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

move the description to another chapter

abc3c2e86f7cefb3
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
index 08cea106b45..08fe63bb175 100644
--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
@@ -511,6 +511,7 @@ export const realtime = {
items: [
{ name: 'Overview', url: '/guides/realtime', items: [] },
{ name: 'Quickstart', url: '/guides/realtime/quickstart', items: [] },
+ { name: 'Protocol', url: '/guides/realtime/protocol', items: [] },
{
name: 'Channels',
url: undefined,
diff --git a/apps/docs/pages/guides/realtime/protocol.mdx b/apps/docs/pages/guides/realtime/protocol.mdx
new file mode 100644
index 00000000000..3d211079aa8
--- /dev/null
+++ b/apps/docs/pages/guides/realtime/protocol.mdx
@@ -0,0 +1,153 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'protocol',
+ title: 'Realtime Protocol',
+ description: "Understanding Realtime Protocol",
+}
+
+The Realtime Protocal is a set of message formats that you send and receive from the Realtime server.
+
+## Connection
+
+In the initial message, the client sends a message specifying the features that wants to use (Broadcase, Presence, Postgres Changes).
+
+```typescript
+{
+ "event": "phx_join",
+ "topic": string,
+ "payload": {
+ "config": {
+ "broadcast": {
+ "self": boolean
+ },
+ "presence": {
+ "key": string
+ },
+ "postgres_changes": [
+ {
+ "event": "*" | "INSERT" | "UPDATE" | "DELETE",
+ "schema": string,
+ "table": string,
+ "filter": string + '=' + "eq" | "neq" | "gt" | "gte" | "lt" | "lte" + '.' + string
+ }
+ ]
+ }
+ },
+ "ref": string
+}
+```
+
+In response, the server sends the Postgres configuration with a unique ID. With this ID, the client should route incoming changes to the appropriate callback.
+
+```typescript
+{
+ "event": "phx_reply",
+ "topic": string,
+ "payload": {
+ "response": {
+ "postgres_changes": [
+ {
+ "id": number,
+ "event": "*" | "INSERT" | "UPDATE" | "DELETE",
+ "schema": string,
+ "table": string,
+ "filter": string + '=' + "eq" | "neq" | "gt" | "gte" | "lt" | "lte" + '.' + string
+ }
+ ]
+ },
+ "status": "ok" | "error"
+ },
+ "ref": string
+}
+```
+
+## System messages
+
+System message are used to inform a client about the status of the Postgres subscription. The `payload.status` indicates if the subscription successful or not.
+The body of the `payload.message` can be "Subscribed to PostgreSQL" or "Subscribing to PostgreSQL failed" with subscription params.
+
+```typescript
+{
+ "event": "system",
+ "topic": string,
+ "payload":{
+ "channel": "any",
+ "extension": "postgres_changes",
+ "message": "Subscribed to PostgreSQL" | "Subscribing to PostgreSQL failed",
+ "status": "ok" | "error"
+ },
+ "ref": null,
+}
+```
+
+## Heartbeat
+
+The heartbeat message should be sent every 60 seconds to avoid a connection timeout.
+
+```typescript
+{
+ "event": "heartbeat",
+ "topic": "phoenix",
+ "payload": {},
+ "ref": string
+}
+```
+
+## Access Token
+
+To update the access token, you need to send to the server a message specifying a new token in the `payload.access_token` value.
+
+
+```typescript
+{
+ "event": "access_token",
+ "topic": string,
+ "payload":{
+ "access_token": string
+ },
+ "ref": string
+}
+```
+
+## Postgres CDC message
+
+Realtime sends a message with the following structure
+
+```typescript
+{
+ "event": "postgres_changes",
+ "topic": string,
+ "payload": {
+ "data": {
+ "columns": Array<{name: string, type: string}>,
+ "commit_timestamp": string,
+ "errors": null | string,
+ "old_record": {"id": number | string},
+ "record": {[key: string]: boolean | number | string | null},
+ "type": "*" | "INSERT" | "UPDATE" | "DELETE",
+ "schema": string,
+ "table": string
+ },
+ "ids": Array<number>
+ },
+ "ref": null
+}
+```
+
+## Broadcast message
+
+Structure of the broadcast event
+
+```typescript
+{
+ "event": "broadcast",
+ "topic": string,
+ "payload": {
+ "event": string,
+ "payload": {[key: string]: boolean | number | string | null | undefined},
+ "type": "broadcast"
+ },
+ "ref": null
+}
+```
\ No newline at end of file