Skip to content

powersync-ja/self-host-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PowerSync Self-Hosted Example

This is an example self-hosted project using the PowerSync Open Edition version of the PowerSync Service, which is published to Docker Hub as journeyapps/powersync-service.

This example uses Docker Compose to define and run the containers.

Learn more about self-hosting PowerSync here.

Run

This repository contains basic demonstrations in the demos folder.

  • Node.js (Postgres)

    • This can be started from the repo root with docker compose -f demos/nodejs/docker-compose.yaml up
  • Node.js (Postgres + Custom Write Checkpoints)

    • This can be started from the repo root with docker compose -f demos/nodejs-custom-checkpoints/docker-compose.yaml up
  • Node.js (MongoDB)

    • This can be started from the repo root with docker compose -f demos/nodejs-mongodb/docker-compose.yaml up
  • Node.js (MySQL)

    • This can be started from the repo root with docker compose -f demos/nodejs-mysql/docker-compose.yaml up
  • Django

    • This can be started from the repo root with docker compose -f demos/django/docker-compose.yaml up
  • Supabase

    • See the README for instructions.

Config

The configuration can be modified to match other project topologies.

Edit the demo .env files and config files in the ./config directory with your specific settings.

Connections

Populate the replication->connections entry with your database connection details.

  • Postgres: A simple Postgres server is provided in the ps-postgres.yaml Docker Compose file. Be sure to keep the credentials in powersync.yaml in sync with the config in ps-postgres.yaml if using this server.

  • MongoDB: See the nodejs-mongodb demo for MongoDB connection configuration.

Storage

The PowerSync Service uses MongoDB under the hood to store sync bucket state and operation history, regardless of whether you are syncing with a Postgres or MongoDB backend source database.

A basic MongoDB replica-set service is available in ps-mongo.yaml. The powersync.yaml config is configured to use this service by default. Different MongoDB servers can be configured by removing the include statement from docker-compose.yaml and updating powersync.yaml.

Authentication

This example uses JWKS which provides the public key directly to the PowerSync instance in powersync.yaml's jwks section.

The key-generator project demonstrates generating RSA key pairs for token signing.

Sync Rules

Sync Rules are currently defined by placing them in ./config/sync_rules.yaml.

Memory Limits

It's recommended to set the NODE_OPTIONS="--max-old-space-size=<size>" environment variable to increase the default Node.js memory limit.

Service memory limits should be adjusted to roughly 80 percent of the system memory capacity.

Cleanup

If you want to start from a fresh start:

  • Delete the Docker volumes mongo_storage and db_data Their full names might vary depending on the directory where the docker-compose command was executed.
  • Delete the service Docker containers.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published