Prerequisites
Before setting up LiveSync, ensure you have:- An active Ably account with an API key
- A supported database (Postgres 10+ or MongoDB 4.0+)
- Database credentials with appropriate permissions
- Basic understanding of your database architecture
Setup Overview
Setting up LiveSync involves three main steps:- Configure your database - Set up required tables/collections
- Create an integration rule - Connect your database to Ably
- Integrate client SDKs - Subscribe to changes in your applications
Postgres Setup
Step 1: Create Required Tables
The Postgres database connector requires two tables in your database: an outbox table and a nodes table.Step 2: Create Trigger Function
Create a trigger to notify the connector when new records are added to the outbox:Step 3: Configure Database Permissions
Create a dedicated user with minimal required permissions:Step 4: Create Integration Rule
Create a Postgres integration rule in the Ably dashboard:- Navigate to your Ably Dashboard
- Select your application
- Click the Integrations tab
- Click New Integration Rule
- Choose Postgres from the list
| Field | Description | Example |
|---|---|---|
| URL | Postgres connection string | postgres://user:pass@host:5432/dbname |
| Outbox table schema | Schema name for outbox table | public |
| Outbox table name | Name of the outbox table | outbox |
| Nodes table schema | Schema name for nodes table | public |
| Nodes table name | Name of the nodes table | nodes |
| SSL mode | SSL connection level | prefer / require / verify-ca / verify-full |
| SSL root certificate | CA certificate (if required) | Certificate content |
| Primary site | Data center location | us-east-1-A |
Step 5: Test the Connection
Verify your setup by inserting a test record:MongoDB Setup
Step 1: Enable Change Streams
Ensure your MongoDB deployment supports Change Streams:- MongoDB Atlas: Change Streams are enabled by default
- Self-hosted: Requires a replica set or sharded cluster (MongoDB 4.0+)
Step 2: Configure Collection
Optionally enable pre and post images for full document access:Step 3: Create Integration Rule
Create a MongoDB integration rule in the Ably dashboard:- Navigate to your Ably Dashboard
- Select your application
- Click the Integrations tab
- Click New Integration Rule
- Choose MongoDB from the list
| Field | Description | Example |
|---|---|---|
| URL | MongoDB connection string | mongodb://user:pass@host/db |
| Watch | What to watch | collection |
| Database name | Target database | myapp |
| Collection name | Target collection | users |
| Full Document | Include full document | updateLookup / whenAvailable / off |
| Full Document before change | Include previous state | whenAvailable / off |
| Pipeline | Change stream pipeline | See below |
| Primary site | Data center location | us-east-1-A |
Step 4: Configure Pipeline
Define a MongoDB aggregation pipeline to route events to channels:Step 5: Configure Database Permissions
Create a user with Change Stream access:Client SDK Integration
Install Ably SDK
Install the Ably SDK for your platform:Subscribe to Changes
Implement realtime subscriptions in your client application:Authentication & Security
API Keys and Capabilities
Configure API keys with appropriate capabilities:Token Authentication
Implement token authentication for client applications:Configuration Best Practices
Channel Naming
Use consistent channel naming conventions:Message Structure
Design consistent message payloads:Error Handling
Implement robust error handling:Monitoring and Debugging
Dashboard Metrics
Monitor your LiveSync integration in the Ably dashboard:- Message throughput
- Connection count
- Error rates
- Integration rule status
Logging
Enable debug logging for troubleshooting:Testing
Test your integration with curl:Next Steps
Database Synchronization
Learn database sync patterns and best practices
Conflict Resolution
Handle conflicts in distributed systems
Postgres Connector
Deep dive into Postgres-specific features
MongoDB Connector
Explore MongoDB Change Streams integration
