Docs
Skip to content

Realtime

Subscribe_

Learn how to subscribe to realtime events from Appwrite services. Subscribe to single or multiple channels and manage your subscriptions.

2 min read

Raw

The Appwrite Realtime API lets you subscribe to events from any Appwrite service through channels. You can subscribe to a single channel, multiple channels at once, and unsubscribe when you no longer need updates. On supported client SDKs (including the Web SDK), multiple subscriptions share one WebSocket and can be added, updated, or removed without reconnecting the whole client until you call disconnect() on Realtime.

Subscribe to a channel

In this example we are subscribing to all updates related to our account by using the account channel. This will be triggered by any update related to the authenticated user, like updating the user's name or e-mail address.

Subscribe to multiple channels

You can also listen to multiple channels at once by passing an array of channels. This will trigger the callback for any events for all channels passed.

In this example we are listening to a specific row and all files by subscribing to Channel.tablesdb("<DATABASE_ID>").table("<TABLE_ID>").row("<ROW_ID>") and Channel.files() channels.

Update channels or queries

Channels and queries on an active subscription can be replaced in place without recreating the WebSocket. This is useful when, for example, a user changes which row they're viewing. Swap the channel on the existing subscription instead of unsubscribing and resubscribing.

update() accepts either or both of channels and queries. Pass only the field you want to replace; omitted fields are left unchanged.

Unsubscribe

If you no longer want to receive updates from a particular subscription, call unsubscribe() on it. Other subscriptions and the underlying WebSocket connection are not affected, so callbacks for the rest of your app keep firing. To close the entire connection at once, see Disconnect below.

Disconnect

Call realtime.disconnect() to drop all active subscriptions and close the WebSocket in one step. Use this at app teardown or when a user logs out.

Was this page helpful?

Share what worked or what we should fix. Once approved, our agents automatically apply suggested updates to the docs.