> ## Documentation Index
> Fetch the complete documentation index at: https://powersync-sync-streams-nav.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Sync Streams

> Sync Streams define which data syncs to each client. Learn what a stream is and how PowerSync replicates and streams the data.

With Sync Streams, you write SQL-like queries to define streams of data, and your client app subscribes to the streams it needs. This enables *partial sync*: each client syncs only the relevant subset of data, instead of the entire database. PowerSync keeps subscribed data synced in real-time to a client-side SQLite database, where it stays available when the device is offline.

For example, you might define a stream that syncs only the current user's to-do items, another for shared projects they have access to, and another for reference data that everyone needs. Your app subscribes to these streams on demand, and only that data syncs to the device. Apps that need all relevant data available upfront can set `auto_subscribe: true` so streams sync automatically when clients connect.

<Note>
  **Are you still using Sync Rules?** Sync Streams support everything Sync Rules do, plus more expressive queries (including JOIN support), on-demand syncing, and a simpler developer experience (e.g. React hooks that manage subscriptions automatically).

  You can migrate in a few clicks. Click **Migrate to Sync Streams** in the PowerSync Dashboard, or run `powersync migrate sync-rules` in the CLI to generate a draft from your current config. See [Migrate to Sync Streams](/sync/rules/migrate-to-sync-streams) for details.
</Note>

## How It Works

Each PowerSync Service instance has a deployed Sync Streams configuration: a YAML file that defines the streams that exist. Each stream has a name and a SQL-like query that selects the tables and columns to sync, filters rows by static conditions or by parameters, and can rename or transform columns. The Service uses this configuration in two places: when it replicates data from your source database into buckets, and when it streams those buckets to clients.

<Tip>See the [PowerSync Service architecture](/architecture/powersync-service) for more background.</Tip>

### Buckets and Parameters

PowerSync groups replicated data into [buckets](/architecture/powersync-service#bucket-system): partitions of data that are synced as a unit. A stream creates one bucket for each unique value of its filter, such as each user ID matched by `auth.user_id()` or each `list_id` that a client subscribes with. A stream without parameters creates a single bucket that syncs the same data to every subscriber.

Buckets are implicit in Sync Streams. The Service creates them from your stream queries, parameters, and subqueries, and you do not define or name them yourself. See [Bucket Count](/sync/streams/bucket-count) for how queries determine the number of buckets.

### Replication From the Source Database

The Service [replicates and transforms](/architecture/powersync-service#replication-from-the-source-database) data from your source database according to your stream queries, and persists the data and metadata in buckets. Buckets are updated incrementally, so they contain the latest state as well as a history of changes (operations). This operation history allows clients to sync only the deltas they need to get up to date. See [Protocol](/architecture/powersync-protocol#protocol) for details.

<Note>
  For example, a stream `user_lists` with the query `SELECT * FROM lists WHERE owner_id = auth.user_id()` creates one bucket per user. If users `A` and `B` exist in the source database, the Service creates a bucket for each of them. When user `A` connects and subscribes, they sync only their own bucket.
</Note>

<Frame caption="Data is replicated from the source database into buckets.">
  <img src="https://mintcdn.com/powersync-sync-streams-nav/RiYaJIlM05vksakM/images/usage/sync-rules/powersync-docs-diagram-sync-streams-002.png?fit=max&auto=format&n=RiYaJIlM05vksakM&q=85&s=3cc1ce164ca8c2b85f1985612885a293" width="1920" height="1080" data-path="images/usage/sync-rules/powersync-docs-diagram-sync-streams-002.png" />
</Frame>

### Streaming Sync to Clients

Whenever buckets change (buckets are added or removed, or operations are added to existing buckets), the Service [streams these changes in real-time](/architecture/powersync-service#streaming-sync) to the subscribed clients. The set of buckets a client receives adjusts as it subscribes to and unsubscribes from streams, and depends on its subscription, connection, and authentication parameters.

On the client, bucket data is persisted in SQLite, where you query it through your [client-side schema](/intro/setup-guide#define-your-client-side-schema). See [Client Architecture](/architecture/client-architecture#client-side-schema-and-sqlite-database-structure) for the database structure.

<Frame caption="Operations in buckets are synced to clients in real-time based on their stream subscriptions, and a client-side SQLite database is materialized from the bucket data.">
  <img src="https://mintcdn.com/powersync-sync-streams-nav/RiYaJIlM05vksakM/images/usage/sync-rules/powersync-docs-diagram-sync-streams-003.png?fit=max&auto=format&n=RiYaJIlM05vksakM&q=85&s=7a8699e8a3c0378fae01cff527d965f0" width="1920" height="1080" data-path="images/usage/sync-rules/powersync-docs-diagram-sync-streams-003.png" />
</Frame>

## Next Steps

<CardGroup cols={2}>
  <Card title="Quickstart" icon="rocket" href="/sync/streams/quickstart">
    Define your first streams and subscribe to them from your app.
  </Card>

  <Card title="Using Parameters" icon="sliders" href="/sync/streams/parameters">
    Filter data with auth, subscription, and connection parameters.
  </Card>

  <Card title="Writing Queries" icon="code" href="/sync/streams/queries">
    Query syntax, joins, subqueries, and multiple queries per stream.
  </Card>

  <Card title="Client-Side Usage" icon="mobile" href="/sync/streams/client-usage">
    Manage subscriptions in each SDK and UI framework.
  </Card>
</CardGroup>
