A production-ready Go server application that provides HTTP endpoints for PowerSync-enabled applications to sync data between client devices and PostgreSQL, MySQL, MongoDB, or Microsoft SQL Server databases.
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/auth/token |
PowerSync uses this endpoint to retrieve a JWT access token which is used for authentication. |
| GET | /api/auth/keys |
PowerSync uses this endpoint to validate the JWT returned from the endpoint above. |
| POST | /api/data |
PowerSync uses this endpoint to sync batch operations (PUT/PATCH/DELETE) that occurred on the client application. |
| PUT | /api/data |
PowerSync uses this endpoint to sync single upsert events that occurred on the client application. |
| PATCH | /api/data |
PowerSync uses this endpoint to sync single update events that occurred on the client application. |
| DELETE | /api/data |
PowerSync uses this endpoint to sync single delete events that occurred on the client application. |
| PUT | /api/data/checkpoint |
PowerSync uses this endpoint to create checkpoints for sync operations. |
- gin-gonic/gin: HTTP web framework
- jackc/pgx/v5: PostgreSQL driver
- go-sql-driver/mysql: MySQL driver
- mongo-go-driver: MongoDB driver
- go-mssqldb: Microsoft SQL Server driver
- go-jose: JWT signing and validation
- Go 1.25.4 or later
- One of the following databases:
- PostgreSQL 12+
- MySQL 8.0+
- MongoDB 4.4+
- Microsoft SQL Server 2017+
For local development, Docker containers are recommended. For production, use managed database services or your own database infrastructure.
-
Clone the repository
-
Generate RSA key pairs for JWT signing. Follow the PowerSync authentication guide or use your own keys.
Important: The application will generate temporary keys for development if
POWERSYNC_PRIVATE_KEYandPOWERSYNC_PUBLIC_KEYare not set. Never use auto-generated keys in production. -
Configure environment variables. Create a
.envfile or set them in your environment:
PORT=6060
DATABASE_TYPE=postgres
DATABASE_URI=postgres://user:pass@localhost:5432/mydb?sslmode=disable
POWERSYNC_URL=https://your-instance.powersync.com
POWERSYNC_PRIVATE_KEY=your_base64_encoded_private_key_jwk
POWERSYNC_PUBLIC_KEY=your_base64_encoded_public_key_jwk
JWT_ISSUER=your_issuerRequired variables:
DATABASE_TYPE: One ofpostgres,mysql,mongodb, ormssqlDATABASE_URI: Connection string for your databasePOWERSYNC_URL: Your PowerSync instance URLPOWERSYNC_PRIVATE_KEY: Base64-encoded private key JWK (required for production)POWERSYNC_PUBLIC_KEY: Base64-encoded public key JWK (required for production)JWT_ISSUER: JWT issuer identifier
Optional variables:
PORT: Server port (default: 6060)
- Install dependencies:
go mod download- Run the application:
go run cmd/api/main.goThe server will start on http://127.0.0.1:PORT (default port: 6060).
Verify the server is running:
curl http://127.0.0.1:6060/api/auth/token- Never use auto-generated keys in production - Always provide
POWERSYNC_PRIVATE_KEYandPOWERSYNC_PUBLIC_KEYenvironment variables - Use HTTPS - Ensure your production server uses TLS/SSL
- Secure database connections - Use SSL/TLS for database connections in production
- Environment variables - Store sensitive credentials securely (use secret management services)
- CORS configuration - Update CORS settings to restrict origins in production
- Docker: Use the provided Dockerfile for containerized deployment
- Cloud platforms: Deploy to AWS, GCP, Azure, or other cloud providers
- Traditional hosting: Run as a systemd service or similar
In the PowerSync Dashboard, configure the JWKS URI:
https://your-production-domain.com/api/auth/keys
Ensure the endpoint is publicly accessible and returns valid JWKS format.
For local development and testing, you can use ngrok to expose your local server:
- Install ngrok
- Run:
ngrok http 6060 - Use the HTTPS URL in PowerSync Dashboard:
https://your_id.ngrok-free.app/api/auth/keys
Tests use a mock persistence layer and don't require a database connection:
go test -v ./test/...Build the Docker image:
docker build -t powersync-go-backend .Run the container:
docker run -p 6060:6060 \
-e DATABASE_TYPE=postgres \
-e DATABASE_URI="postgres://user:pass@host:5432/db" \
-e POWERSYNC_URL="https://your-instance.powersync.com" \
-e POWERSYNC_PRIVATE_KEY="your_base64_encoded_private_key" \
-e POWERSYNC_PUBLIC_KEY="your_base64_encoded_public_key" \
-e JWT_ISSUER="your_issuer" \
powersync-go-backendOr use Docker Compose for easier management of multiple services.