Skip to content

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

Adding the Realtime docs

Paul Copplestone9075fa48d1f5
diff --git a/packages/web/content/docs/realtime/getting-started.mdx b/packages/web/content/docs/realtime/getting-started.mdx
index a26aa7cbac0..9ce716aeb1d 100644
--- a/packages/web/content/docs/realtime/getting-started.mdx
+++ b/packages/web/content/docs/realtime/getting-started.mdx
@@ -4,9 +4,29 @@ export const metadata = {
sidebarLabel: 'Overview'
}
-
-Some overview.
+Supabase Realtime is an elixir server that allows you to listen to PostgreSQL inserts/updates/deletes over websockets.
## Motivation
-Some reasons.
\ No newline at end of file
+Change data capture solves a lot of tough engineering problems related to stale data. On top of that, some systems (like chat apps) require realtime data.
+Supabase Realtime is designed to solve these problems and be usable anywhere from mobile, web, and other servers.
+
+## How it works
+
+The server is built with [Phoenix](https://phoenixframework.org/), which is an Elixir framework that's amazing for listening via websockets.
+The Phoenix server listens to PostgreSQL's replication functionality and converts the byte stream into JSON. Tt then broadcasts the JSON over websockets.
+This is great since you can scale the Phoenix servers without any additional load on your DB.
+
+The great thing about this implementation is that you can make changes to your database from anywhere - your api, directly in the DB, via a console etc -
+and you will still receive the changes via Realtime.
+
+## What this isn't
+
+We are building the client libraries which make it super simple to connect to the server.
+However we don't intend to build client-side databases that can do all the offline conflict resolution that other services like Firebase provide.
+
+Supabase Realtime is a passive listen/broadcast system. You don't use it to make updates to your database.
+
+## Features
+
+- Works without wal2json :)
\ No newline at end of file
diff --git a/packages/web/content/docs/realtime/installation.mdx b/packages/web/content/docs/realtime/installation.mdx
index 6971cf7a27a..8195c413c75 100644
--- a/packages/web/content/docs/realtime/installation.mdx
+++ b/packages/web/content/docs/realtime/installation.mdx
@@ -4,7 +4,60 @@ export const metadata = {
}
-## Hello world
+## Database preparation
+We have tried to keep the requirements to use this as simple as possible. However there are still *some* things that you need to enable on your Postgres database (namely, replication).
-FOo bAr
\ No newline at end of file
+**1. Enable replication**
+
+Make sure your database has replication turned on:
+
+```sh
+SHOW wal_level; # This should be "logical"
+SHOW max_replication_slots; # You need at least one free slot for Supabase
+```
+
+**2. Listen to all table changes**
+
+Create a publication for Supabase to listen to on all of your tables.
+
+```sh
+CREATE PUBLICATION supabase_realtime FOR ALL TABLES;
+```
+
+
+**3. (Optional) Receive old data**
+
+If you want to receive the data the previous data (i.e. what the fields were *before* updates), then you need to set each table to have a full replica identity:
+
+```sh
+ALTER TABLE YOUR_TABLE_NAME replica identity full; # Change YOUR_TABLE_NAME
+```
+
+
+## Running the server
+
+The easiest way to use this is to set up a docker compose:
+
+```yml
+# docker-compose.yml
+version: '3'
+services:
+ realtime:
+ image: supabase/realtime
+ ports:
+ - "4000:4000"
+ environment:
+ - POSTGRES_USER=postgres
+ - POSTGRES_PASSWORD=postgres
+ - POSTGRES_DB=postgres
+ - POSTGRES_HOST=localhost
+ - POSTGRES_PORT=5432
+```
+
+Once you are set up you can run `docker-compose up`
+
+
+## Next steps
+
+Now that your server is running you can connect to it via one of the client libraries
\ No newline at end of file
diff --git a/packages/web/content/docs/realtime/realtime-js.mdx b/packages/web/content/docs/realtime/realtime-js.mdx
index 4be607bff1d..2d82c74a52d 100644
--- a/packages/web/content/docs/realtime/realtime-js.mdx
+++ b/packages/web/content/docs/realtime/realtime-js.mdx
@@ -6,13 +6,32 @@ export const metadata = {
## Install
-
```sh
npm install --save @supabase/realtime-js
```
## Usage
+#### Connect to the server
+
```js
-// @TODO
+import { Socket } = '@supabase/realtime-js'
+
+var API_SOCKET = process.env.SOCKET_URL
+var socket = new Socket(API_SOCKET)
+var realtimeChannel = this.socket.channel('realtime')
+
+socket.connect()
+if (realtimeChannel.state !== 'joined') {
+ realtimeChannel
+ .join()
+ .receive('ok', resp => console.log('Joined successfully', resp))
+ .receive('error', resp => console.log('Unable to join', resp))
+ .receive('timeout', () => console.log('Networking issue. Still waiting...'))
+
+ // Listen to all changes in the database
+ realtimeChannel.on('shout', payload => {
+ console.log('Update received!', payload)
+ })
+}
```
\ No newline at end of file