Skip to main content

What is LiveSync?

LiveSync is a powerful realtime data synchronization product designed to facilitate broadcasting realtime updates from backend databases to application clients at scale. LiveSync ensures that data updates are propagated reliably, and in order, to all connected clients in realtime.

Overview

LiveSync can be used in applications where your database is the source of truth for the application state, and that state needs to be reflected in realtime to client applications. LiveSync enables this data synchronization while maintaining data integrity and low latency. By using Ably Pub/Sub channels and SDKs, clients subscribing to messages published by a LiveSync database connector benefit from features like connection-recovery, exactly-once delivery and ordering guarantees out of the box. Ably’s platform guarantees and four pillars of dependability apply by default.

How It Works

LiveSync uses Ably’s pub/sub channels as the mechanism for synchronizing data updates across clients. When a message is published on a channel by the database connector, it is immediately broadcast to all subscribers of that channel.

Architecture

The flow works as follows:
  1. Database Changes: Your application writes data to your database
  2. Change Detection: The database connector detects changes
  3. Message Publishing: Changes are published to Ably channels
  4. Client Updates: All subscribed clients receive updates in realtime

Supported Databases

Ably provides hosted connectors for:

Postgres

The Postgres database connector uses the transactional outbox pattern to reliably publish database changes to Ably channels. It provides:
  • Transactional consistency
  • Exactly-once delivery
  • Message ordering guarantees
  • Support for optimistic updates with the Models SDK
Learn more about Postgres connector →

MongoDB

The MongoDB database connector utilizes MongoDB Change Streams to distribute document changes in realtime. It offers:
  • Real-time change event streaming
  • Dynamic channel routing based on document content
  • Support for full document inclusion
  • Pipeline filtering and transformation
Learn more about MongoDB connector →

Use Cases

LiveSync can benefit a wide range of applications where it’s important to broadcast database changes in realtime to keep clients in sync:

Collaborative Applications

  • CRM Systems: Real-time updates to customer records, deals, and interactions
  • Task Management: Live updates to tasks, assignments, and project status
  • Document Editing: Collaborative form editing with live changes

E-Commerce & Auctions

  • Inventory Management: Real-time stock level updates
  • Online Auctions: Live bid updates and auction status
  • Shopping Carts: Synchronized cart state across devices

Communication & Social

  • Chat Applications: Live message delivery and conversation updates
  • Activity Feeds: Real-time newsfeeds and notifications
  • Comment Systems: Live comments and reactions

Gaming

  • Turn-Based Games: Synchronized game state across players
  • Leaderboards: Real-time score updates
  • Multiplayer Coordination: Live game state synchronization

Key Features

Channel-Based Broadcasting

LiveSync leverages Ably’s pub/sub channels to broadcast updates. Each channel can represent a specific resource or data model, enabling fine-grained access control and efficient data distribution.
// Subscribe to database changes on a specific channel
const channel = ably.channels.get('documents:123');

await channel.subscribe((message) => {
  console.log('Database update received:', message.data);
});

Hosted Database Connectors

Take advantage of the Ably hosted database connectors to automatically publish changes from your database as messages on Ably channels. The hosted connectors are:
  • Fully managed: No infrastructure to maintain
  • Fault-tolerant: Automatic failover and recovery
  • Scalable: Handles high-throughput workloads
  • Secure: Integrated with Ably’s authentication and capabilities

Reliable Delivery

LiveSync provides:
  • Exactly-once delivery: Messages are delivered exactly once to each subscriber
  • Ordering guarantees: Messages are delivered in the order they were published
  • Connection recovery: Automatic reconnection and message replay

Access Control

Using Ably’s Auth and Capabilities system, you can control:
  • Which channels a client is allowed to subscribe to
  • Which operations (subscribe, publish, history) are permitted
  • Token-based authentication for secure client access

Pricing

LiveSync pricing is mainly based on message consumption (alongside concurrent connections and concurrent channels). This means that each update published from the database connector to Ably channels is counted as a single message. The message is received by every client subscribed to that channel, each of which counts as one additional message. Example: If one update is published by the database connector and there are three clients subscribed, that one update will result in four messages in total (1 published + 3 received). View pricing details →

Getting Started

Ready to integrate LiveSync into your application? Follow these steps:
  1. Choose Your Database: Select either Postgres or MongoDB
  2. Set Up the Connector: Configure the database connector in your Ably dashboard
  3. Configure Your Database: Set up the required tables or collections
  4. Integrate the SDK: Use Ably SDKs to subscribe to changes in your client applications

Quick Example

import { Realtime } from 'ably';

// Initialize Ably client
const ably = new Realtime({ key: 'YOUR_API_KEY' });

// Subscribe to a channel
const channel = ably.channels.get('users:updates');

await channel.subscribe((message) => {
  // Handle database change event
  const { operationType, data } = message.data;
  
  switch (operationType) {
    case 'insert':
      console.log('New record:', data);
      break;
    case 'update':
      console.log('Updated record:', data);
      break;
    case 'delete':
      console.log('Deleted record:', data);
      break;
  }
});

Next Steps

Setup Guide

Learn how to set up and configure LiveSync for your application

Database Sync

Understand database synchronization patterns and best practices

Conflict Resolution

Learn how to handle conflicts in distributed systems

Build docs developers (and LLMs) love