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
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
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
