A production-ready, database-agnostic Change Data Capture system that captures and replicates INSERT, UPDATE, and DELETE operations across databases.
- Multiple CDC Strategies: Trigger-based, timestamp-based, and version-based CDC
- Database Support: SQLite, PostgreSQL, MySQL
- Automatic Replication: Real-time or batch synchronization
- Change Tracking: Captures INSERT, UPDATE, DELETE with before/after values
- Monitoring: Built-in health monitoring and statistics
- Production Ready: Error handling, logging, and retry mechanisms
- Extensible: Easy to add custom database adapters
- Python 3.8 or higher
- SQLite (included with Python)
- PostgreSQL or MySQL (optional, for production use)
# Clone the repository
git clone https://github.com/arya23923/cdc-system.git
cd cdc-system
# Or download the files directly and organize them as:
# cdc-system/
# ├── cdc_system.py
# ├── example_usage.py
# ├── config.py
# ├── requirements.txt
# └── README.md# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activatepip install -r requirements.txtCreate requirements.txt with:
psycopg2-binary==2.9.9
mysql-connector-python==8.2.0
python-dotenv==1.0.0
Run the basic demo to see CDC in action:
python example_usage.py basicThis will:
- Create source and target databases
- Set up CDC infrastructure with triggers
- Insert, update, and delete sample data
- Replicate changes to the target database
- Show statistics and verify replication
┌─────────────────┐
│ Source DB │
│ (Production) │
└────────┬────────┘
│
│ Triggers capture
│ INSERT / UPDATE / DELETE
↓
┌─────────────────┐
│ CDC Audit │
│ Table │
└────────┬────────┘
│
│ CDC Replicator
│ reads changes
↓
┌─────────────────┐
│ Target DB │
│ (Replica) │
└─────────────────┘
Methods:
setup_trigger_based_cdc(columns)- Setup CDC infrastructureget_pending_changes(limit)- Get unsynced changesmark_as_synced(cdc_ids)- Mark changes as processedget_change_statistics()- Get CDC statistics
replicator = CDCReplicator(source_cdc, target_db, target_table)Methods:
replicate_changes(batch_size)- Replicate pending changes
monitor = CDCMonitor(cdc_system)Methods:
get_health_report()- Get system health metricsprint_report()- Print formatted report
MIT License - feel free to use in your projects!