Realtime with Postgres, explained simply
Subscribing your UI to database changes: how realtime works, when to use it, and a complete example in just a few lines.
"Realtime" is when your UI updates the moment the database changes, with no page reload. A message that appears, a counter that ticks, an order that flips to "paid" right before your eyes.
When to use it
- Messaging and chat.
- Instant notifications.
- Presence ("who's online") and shared cursors.
- Dashboards that refresh on their own.
How it works, in a nutshell
Postgres keeps a log of all its writes (the WAL). Realtime listens to that log and pushes each change to your UI over a WebSocket connection held open. No repeated polling, no server to manage.
Polling vs realtime, Hitting the API every 2 seconds (polling) wastes resources and stays behind. A realtime connection only consumes resources when something actually happens.
A complete example
const ws = new WebSocket(
'wss://clicbase.com/db/ma-base/realtime'
)
ws.onmessage = (e) => {
const { table, type, record } = JSON.parse(e.data)
if (table === 'commandes' && type === 'INSERT') {
afficherEnDirect(record) // nouvelle commande -> à l'écran
}
}
ws.onclose = () => reconnecter() // garde la connexion vivante
A few lines, and your UI goes live. Try realtime on your project.
When to use realtime
| Use case | Example |
|---|---|
| Chat | A message appears without reload |
| Notifications | Live badge/alert |
| Presence | Who's online right now |
| Dashboards | Live counters & stats |
Frequently asked questions
What is realtime with PostgreSQL?
It's your UI updating instantly when the database changes, without a page reload: a new message, a counter, a status change appears live for every connected client.
How do I enable realtime on Clicbase?
Realtime is included: you subscribe to a table's changes via the API, and Clicbase pushes inserts, updates and deletes to your clients — with no WebSocket server to manage.
Launch your backend in minutes
Postgres database, API, auth, storage, realtime, plus your emails and domain. Free to start.