Skip to main content

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:
  1. Configure your database - Set up required tables/collections
  2. Create an integration rule - Connect your database to Ably
  3. 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:
  1. Navigate to your Ably Dashboard
  2. Select your application
  3. Click the Integrations tab
  4. Click New Integration Rule
  5. Choose Postgres from the list
Configure the rule with the following settings:

Step 5: Test the Connection

Verify your setup by inserting a test record:
Monitor your Ably dashboard to confirm the message was published.

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:
  1. Navigate to your Ably Dashboard
  2. Select your application
  3. Click the Integrations tab
  4. Click New Integration Rule
  5. Choose MongoDB from the list
Configure the rule with the following settings:

Step 4: Configure Pipeline

Define a MongoDB aggregation pipeline to route events to channels:
Dynamic channel routing based on document fields:

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