Skip to content

Feature/xmin sync#64

Merged
taariq merged 3 commits into
mainfrom
feature/xmin-sync
Dec 8, 2025
Merged

Feature/xmin sync#64
taariq merged 3 commits into
mainfrom
feature/xmin-sync

Conversation

@taariq
Copy link
Copy Markdown
Contributor

@taariq taariq commented Dec 8, 2025

xmin-Based Incremental Sync with Full Delete Reconciliation (Accelerated 1-Day Plan)

Author: Taariq
Date: 2025-12-08
Status: Proposal
Related Issues: N/A (to be created)


Executive Summary

This proposal introduces an xmin-based incremental sync mode for database-replicator that enables continuous replication from any PostgreSQL source to SerenDB without requiring wal_level=logical on the source database.

Key Benefits:

  • Zero customer friction (no source database configuration changes)
  • Works with any PostgreSQL provider (Neon, RDS, Supabase, self-hosted)
  • Full delete detection via periodic PK reconciliation
  • Runs entirely on SerenDB infrastructure (customers never run CLI commands after initial setup)

Trade-offs:

  • Higher compute usage on SerenDB side (acceptable given unlimited compute)
  • Polling-based (seconds latency vs sub-second for logical replication)
  • More network traffic than WAL streaming (see explanation below)

…lication

Implements core xmin-based sync functionality:

- XminReader: Reads changes from source using PostgreSQL xmin system column
  for efficient incremental change detection (Closes #55)

- SyncState: Persists high-water mark xmin values per table to enable
  resumable incremental syncs (Part of #55)

- ChangeWriter: Applies changes to target using INSERT ON CONFLICT DO UPDATE
  (upsert) pattern for efficient batched updates (Closes #56)

- Reconciler: Detects and removes orphaned rows in target that no longer exist
  in source through primary key comparison (Closes #57)

- Writer utilities: get_table_columns, get_primary_key_columns, row_to_values
  helpers for type-safe value extraction (Closes #58)

- SyncDaemon: Orchestrates continuous sync cycles with configurable intervals
  and reconciliation scheduling (Closes #59)

Features:
- Batched operations with PostgreSQL parameter limit handling
- Type-safe value conversion for common PostgreSQL types
- URL sanitization to prevent credential leakage in state files
- Comprehensive unit tests for all components

Related to #60 (sync command integration)
Related to #61 (integration tests)
Related to #62 (documentation)
Adds a new 'xmin-sync' CLI command that provides an alternative to logical
replication for continuous synchronization between PostgreSQL databases.

CLI options:
- --source: Source database URL
- --target: Target database URL
- --schema: Schema to sync (default: public)
- --tables: Comma-separated list of tables to sync (default: all)
- --interval: Sync interval in seconds (default: 60)
- --reconcile-interval: Delete detection interval (default: 3600)
- --batch-size: Rows per batch (default: 1000)
- --state-file: Custom path for sync state persistence
- --once: Run single sync cycle then exit (useful for cron)
- --no-reconcile: Skip delete detection

Features:
- Graceful shutdown via Ctrl+C
- Persistent state for resume capability
- Progress logging with table and row counts
- Error reporting for partial failures

Closes #60
@taariq taariq merged commit e2a5b37 into main Dec 8, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant