The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add realtime section back
Terry Suttone120471d01fb
diff --git a/apps/docs/components/Navigation/Navigation.constants.ts b/apps/docs/components/Navigation/Navigation.constants.tsindex a8b3a82b458..c77ba490b70 100644--- a/apps/docs/components/Navigation/Navigation.constants.ts+++ b/apps/docs/components/Navigation/Navigation.constants.ts@@ -1,3 +1,5 @@+// [Terry] Also need to look at getPageType() in ./lib/helpers+// to set a menu to a pageimport SupabaseJsV1Nav from 'data/nav/supabase-js/v1'import SupabaseJsV2Nav from 'data/nav/supabase-js/v2'import SupabaseDartV0Nav from 'data/nav/supabase-dart/v0'@@ -5,6 +7,7 @@ import SupabaseDartV1Nav from 'data/nav/supabase-dart/v1'import SupabaseCLINav from 'data/nav/supabase-cli'import SupabaseAPINav from 'data/nav/supabase-api'import AuthServerNav from 'data/nav/auth-server'+import RealtimeServerNav from 'data/nav/realtime-server'import StorageServerNav from 'data/nav/storage-server'import { NavMenu, References } from './Navigation.types'@@ -335,6 +338,7 @@ export const menuItems: NavMenu = {label: 'Self-hosting',items: [{ name: 'Auth Server', url: '/reference/auth', items: [] },+ { name: 'Realtime Server', url: '/reference/realtime', items: [] },{ name: 'Storage Server', url: '/reference/storage', items: [] },],},@@ -346,5 +350,6 @@ export const menuItems: NavMenu = {'reference/cli': SupabaseCLINav,'reference/api': SupabaseAPINav,'reference/auth': AuthServerNav,+ 'reference/realtime': RealtimeServerNav,'reference/storage': StorageServerNav,}diff --git a/apps/docs/data/nav/realtime-server.ts b/apps/docs/data/nav/realtime-server.tsnew file mode 100644index 00000000000..dee6ab65b28--- /dev/null+++ b/apps/docs/data/nav/realtime-server.ts@@ -0,0 +1,12 @@+const Nav = [+ {+ label: 'Realtime',+ items: [+ { name: 'Realtime Server', url: '/reference/realtime', items: [] },+ { name: 'Configuration', url: '/reference/realtime/config', items: [] },+ { name: 'Release Notes', url: '/reference/realtime/release-notes', items: [] },+ ],+ },+]++export default Navdiff --git a/apps/docs/data/nonGeneratedReferencePages.ts b/apps/docs/data/nonGeneratedReferencePages.tsindex 73585f54f19..fd5ba84d1f5 100644--- a/apps/docs/data/nonGeneratedReferencePages.ts+++ b/apps/docs/data/nonGeneratedReferencePages.ts@@ -21,6 +21,8 @@ const nonGeneratedReferencePages = ['docs/reference/auth/release-notes','docs/reference/storage','docs/reference/storage/release-notes',+ 'docs/reference/realtime',+ 'docs/reference/realtime/release-notes',]export default nonGeneratedReferencePagesdiff --git a/apps/docs/docs/reference.mdx b/apps/docs/docs/reference.mdxindex 7e9b6d7415a..66af911fe47 100644--- a/apps/docs/docs/reference.mdx+++ b/apps/docs/docs/reference.mdx@@ -50,18 +50,24 @@ Reference documentation for self-hosting Supabase features.<div className="grid grid-cols-2 gap-3"><div className="w-1/2"><ButtonCard- to='/reference/auth'- title='Auth Server'+ to="/reference/auth"+ title="Auth Server"description=" JSON Web Token (JWT)-based API for managing users and issuing access tokens."/></div><div className="w-1/2"><ButtonCard- to='/reference/storage'- title='Storage'+ to="/reference/realtime"+ title="Realtime"+ description="Build multiplayer applications and listen to your database changes via websockets."+ />+ </div>+ <div className="w-1/2">+ <ButtonCard+ to="/reference/storage"+ title="Storage"description="S3-compatible object storage service that integrates with Postgres."/></div>-</div></div>diff --git a/apps/docs/docs/reference/realtime.mdx b/apps/docs/docs/reference/realtime.mdxnew file mode 100644index 00000000000..fe278cb0122--- /dev/null+++ b/apps/docs/docs/reference/realtime.mdx@@ -0,0 +1,58 @@+---+slug: /+sidebar_position: 1+id: realtime+title: Supabase Realtime Server+sidebar_label: Supabase Realtime Server+---++Supabase Realtime is a server built with Elixir using the [Phoenix Framework](https://www.phoenixframework.org) that allows you to listen to changes in your PostgreSQL database via logical replication and then broadcast those changes via WebSockets.++There are two versions of this server: `Realtime` and `Realtime RLS`.++`Realtime` server works by:++1. listening to PostgreSQL's replication functionality (using PostgreSQL's logical decoding)+2. converting the byte stream into JSON+3. broadcasting to all connected clients over WebSockets++`Realtime RLS` server works by:++1. polling PostgreSQL's replication functionality (using PostgreSQL's logical decoding and [wal2json](https://github.com/eulerto/wal2json) output plugin)+2. passing database changes to a [Write Ahead Log Realtime Unified Security (WALRUS)](https://github.com/supabase/walrus) PostgresSQL function and receiving a list of authorized subscribers depending on Row Level Security (RLS) policies+3. converting the changes into JSON+4. broadcasting to authorized subscribers over WebSockets++### Why not just use PostgreSQL's `NOTIFY`?++A few reasons:++1. You don't have to set up triggers on every table.+2. `NOTIFY` has a payload limit of 8000 bytes and will fail for anything larger. The usual solution is to send an ID and then fetch the record, but that's heavy on the database.+3. `Realtime` server consumes two connections to the database, then you can connect many clients to this server. Easier on your database, and to scale up you just add additional `Realtime` servers.++### Benefits++1. The beauty of listening to the replication functionality 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 WebSockets.+2. Decoupling. For example, if you want to send a new slack message every time someone makes a new purchase you might build that functionality directly into your API. This allows you to decouple your async functionality from your API.+3. This is built with Phoenix, an [extremely scalable Elixir framework](https://www.phoenixframework.org/blog/the-road-to-2-million-websocket-connections).++### Does this server guarantee delivery of every data change?++Not yet! Due to the following limitations:++1. Postgres database runs out of disk space due to Write-Ahead Logging (WAL) buildup, which can crash the database and prevent Realtime server from receiving and broadcasting changes. This can be mitigated in the Realtime RLS version of this server by setting the Postgres config `max_slot_wal_keep_size` to a reasonable size.+2. Realtime server can crash due to a larger replication lag than available memory, forcing the creation of a new replication slot and resetting replication to read from the latest WAL data.+3. When Realtime server falls too far behind for any reason, for example disconnecting from database as WAL continues to build up, then database can delete WAL segments the server still needs to read from, for example after reconnecting.++## Client libraries++- [JavaScript](https://github.com/supabase/realtime-js)+- [Dart](https://github.com/supabase/realtime-dart)++## Additional Links++- [Source Code](https://github.com/supabase/storage-api)+- [Known bugs and issues](https://github.com/supabase/storage-js/issues)+- [Storage Guides](https://supabase.com/docs/guides/storage)+- [OpenAPI Docs](https://supabase.github.io/storage-api/)diff --git a/apps/docs/docs/reference/realtime/generated/.gitkeep b/apps/docs/docs/reference/realtime/generated/.gitkeepnew file mode 100644index 00000000000..e69de29bb2ddiff --git a/apps/docs/docs/reference/realtime/release-notes.mdx b/apps/docs/docs/reference/realtime/release-notes.mdxnew file mode 100644index 00000000000..b402b0d2708--- /dev/null+++ b/apps/docs/docs/reference/realtime/release-notes.mdx@@ -0,0 +1,7 @@+---+id: release-notes+---++# Release Notes++All release notes can be found in the [GitHub Releases](https://github.com/supabase/realtime/releases) page.diff --git a/apps/docs/generator/templates/ConfigTemplate.ts b/apps/docs/generator/templates/ConfigTemplate.tsindex 949de8d0bd8..5958218077f 100644--- a/apps/docs/generator/templates/ConfigTemplate.ts+++ b/apps/docs/generator/templates/ConfigTemplate.ts@@ -22,11 +22,11 @@ toc_max_heading_level: 3<%- parameter.description %>-<ul>-<li>Required: <code><%= parameter.required %></code></li>-<li>Default: <code><%- parameter?.default ? parameter?.default : 'None' %></code></li><% if(parameter?.links?.length){ %>+<ul class="method-list-group">+<li class="method-list-item-label flex items-center gap-4">Required: <code><%= parameter.required %></code></li>+<li class="method-list-item-label flex items-center gap-4">Default: <code><%- parameter?.default ? parameter?.default : 'None' %></code></li><% if(parameter?.links?.length){ %><li>-<span>See also:</span>+<h3>See also:</h3><ul><% parameter.links?.forEach(function(link){ %><li><a href="<%- link.link %>"><%- link.name %></a></li><% }); %></ul></li><% } %>diff --git a/apps/docs/lib/docs.ts b/apps/docs/lib/docs.tsindex 9380a21c1c3..d67a61583f7 100644--- a/apps/docs/lib/docs.ts+++ b/apps/docs/lib/docs.ts@@ -23,6 +23,7 @@ export function getDocsBySlug(slug: string) {(realSlug.includes('reference/cli/') && !nonGeneratedReferencePages.includes(realSlug)) ||(realSlug.includes('reference/api/') && !nonGeneratedReferencePages.includes(realSlug)) ||(realSlug.includes('reference/auth/') && !nonGeneratedReferencePages.includes(realSlug)) ||+ (realSlug.includes('reference/realtime/') && !nonGeneratedReferencePages.includes(realSlug)) ||(realSlug.includes('reference/storage/') && !nonGeneratedReferencePages.includes(realSlug))? getPathToGeneratedDoc(realSlug): realSlugdiff --git a/apps/docs/lib/helpers.ts b/apps/docs/lib/helpers.tsindex 72a2484e483..b5df2c0d5c0 100644--- a/apps/docs/lib/helpers.ts+++ b/apps/docs/lib/helpers.ts@@ -20,6 +20,8 @@ export function getPageType(asPath: string) {page = 'reference/cli'} else if (asPath.includes('/reference/auth')) {page = 'reference/auth'+ } else if (asPath.includes('/reference/realtime')) {+ page = 'reference/realtime'} else if (asPath.includes('/reference/storage')) {page = 'reference/storage'} else if (asPath.includes('/reference')) {diff --git a/apps/docs/package.json b/apps/docs/package.jsonindex 6137211c5b6..d659b41442d 100644--- a/apps/docs/package.json+++ b/apps/docs/package.json@@ -8,7 +8,7 @@"start": "next start","lint": "next lint","postbuild": "node ./scripts/build-search.js",- "generate:all": "npm-run-all --parallel gen:api gen:cli gen:gotrue gen:storage gen:supabase-dart:v0 gen:supabase-dart:v1 gen:supabase-js:v1 gen:supabase-js:v2",+ "generate:all": "npm-run-all --parallel gen:api gen:cli gen:gotrue gen:storage gen:supabase-dart:v0 gen:supabase-dart:v1 gen:supabase-js:v1 gen:supabase-js:v2 gen:realtime","gen:api": "npm-run-all gen:api:usage","gen:api:usage": "ts-node ./generator/index.ts gen --type api --url https://api.supabase.com --input ../../spec/transforms/api_v0_openapi_deparsed.json --output ./docs/reference/api/generated/usage.mdx","gen:cli": "npm-run-all gen:cli:commands gen:cli:config",@@ -27,7 +27,9 @@"gen:supabase-js:v1": "npm-run-all gen:supabase-js:v1:ref","gen:supabase-js:v1:ref": "ts-node ./generator/index.ts gen --type legacy --input ../../spec/supabase_js_v1.yml --output ./docs/reference/javascript/v1/generated","gen:supabase-js:v2": "npm-run-all gen:supabase-js:v2:ref",- "gen:supabase-js:v2:ref": "ts-node ./generator/index.ts gen --type legacy --input ../../spec/supabase_js_v2_temp.yml --output ./docs/reference/javascript/generated"+ "gen:supabase-js:v2:ref": "ts-node ./generator/index.ts gen --type legacy --input ../../spec/supabase_js_v2_temp.yml --output ./docs/reference/javascript/generated",+ "gen:realtime": "npm-run-all gen:realtime:config",+ "gen:realtime:config": "ts-node ./generator/index.ts gen --type config --input ../../spec/realtime_v0_config.yaml --output ./docs/reference/realtime/generated/config.mdx"},"dependencies": {"@algolia/autocomplete-js": "^1.7.2",