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:
The service continuously replicates data from the source database, then:
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.
The service authenticates users using JWTs, before allowing access to data.
Once a user is authenticated:
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.
To access the source code for the PowerSync Service, refer to the powersync-service repo on GitHub.