PowerSync Sync Rules allow developers to control which data gets synchronized to which devices (i.e. they enable dynamic partial replication).

Introduction

We recommend starting with our Sync Rules from First Principles blog post, which explains on a high-level what Sync Rules are, why they exist and how to implement them.

The remainder of these docs dive further into the details.

Defining Sync Rules

Each PowerSync Service instance has a Sync Rules configuration where Sync Rules are defined using SQL-like queries (limitations and more info here) combined together in a YAML file.

This SQL-like syntax is used when connecting to either Postgres or MongoDB as the backend source database.

The PowerSync Service uses these SQL-like queries to group data into “sync buckets” when replicating data to client devices.

Sync rules are configured per PowerSync instance.

Functionality includes:

  • Selecting tables/collections and columns/fields to sync.
  • Filtering data according to user ID.
  • Filter data with static conditions.
  • Filter data with custom parameters (from the JWT or from clients directly)
  • Transforming column/field values.

Replication Into Sync Buckets

PowerSync replicates and transforms relevant data from the backend source database according to Sync Rules.

Data from this step is persisted in separate sync buckets on the PowerSync Service. Data is incrementally updated so that sync buckets always contain current state data as well as a full history of changes.

Diagram showing how data is replicated from the source database into sync buckets.

Client Database Hydration

PowerSync asynchronously hydrates local SQLite databases embedded in the PowerSync Client SDK based on data in sync buckets.

Data flow showing sync buckets which are created based on sync rules.