Links

PowerSync Service

Each PowerSync instance runs a copy of the PowerSync service. The primary purpose of this service is to stream changes to clients.
This service has the following components:

Replication

The service continuously replicates data from the source database, then:
  1. 1.
    Pre-processes the data according to the sync rules (both data queries and parameter queries), splitting data into sync buckets and transforming the data if required.
  2. 2.
    Persists each operation into the relevant sync buckets, ready to be streamed to clients.
The recent history of operations to each row is stored, not only the current version. This supports the "append-only" structure of sync buckets, which allows clients to efficiently stream changes while maintaining data integrity. Sync buckets can be compacted to avoid an ever-growing history.
Replication is initially performed by taking a snapshot of all tables defined in the sync rules, then data is incrementally replicated using logical replication. When sync rules are updated, this process restarts with a new snapshot.

Authentication

The service authenticates users using JWTs, before allowing access to data.

Streaming Sync

Once a user is authenticated:
  1. 1.
    The service calculates a list of buckets for the user to sync using parameter queries.
  2. 2.
    The service streams any operations added to those buckets since the last time the user connected.
The service then continuously monitors for buckets that are added or removed, as well as for new operations within those buckets, and streams those changes.
Only the internal (replicated) storage of the PowerSync service is used — the source database is not queried directly during streaming.

See Also