Back to articles
Technology Insight

Real-Time Multi-Dimensional Data Synchronization Between MySQL and Elasticsearch Across Separate VPS Using Debezium CDC

May 29, 2026

Introduction to Real-Time Data Synchronization

In modern enterprise architecture, separating transactional databases from search and analytics engines is a fundamental design pattern. MySQL excels at handling Online Transaction Processing (OLTP) workloads, maintaining relational integrity, and processing ACID transactions. However, when it comes to complex text searching, multi-dimensional filtering, and real-time aggregations, MySQL can quickly become a performance bottleneck.

Enter Elasticsearch, a distributed, JSON-based search and analytics engine built for horizontal scalability and near-real-time search capabilities. To leverage the strengths of both systems, organizations must implement a robust data synchronization mechanism. Traditional batch-based ETL (Extract, Transform, Load) pipelines introduce significant lag, making them unsuitable for time-sensitive business operations. This blog post explores how to achieve lightweight, real-time, multi-dimensional data synchronization between MySQL and Elasticsearch hosted on two distinct Virtual Private Servers (VPS) using Change Data Capture (CDC) via Debezium.

The Power of Change Data Capture (CDC) and Debezium

Change Data Capture (CDC) is a software design pattern that determines and tracks data that has changed so that action can be taken using the changed data. Unlike traditional polling methods that query the database at fixed intervals (which stresses the database CPU and introduces latency), CDC reads directly from the database's transaction logs.

Debezium is an open-source, distributed platform for change data capture. It points at your databases, monitors them, and records all row-level changes into log files. By reading MySQL's binary log (binlog), Debezium captures every INSERT, UPDATE, and DELETE operation instantly with minimal overhead, making it an exceptionally lightweight solution compared to continuous SQL-polling mechanisms.

Architectural Overview: Syncing Across Two Separate VPS Instances

Operating across two separate VPS instances requires careful planning regarding network security, latency, and resource allocation. Below is the conceptual architecture of our real-time pipeline:

  • VPS 1 (Source & Streaming Layer): Hosts the production MySQL Database, Apache Kafka, and Kafka Connect running the Debezium MySQL Connector.
  • VPS 2 (Target & Analytics Layer): Hosts the Elasticsearch Cluster and Logstash (or a custom lightweight Kafka consumer/connector) to index data into target indices.

Security Note: Because data travels between two distinct physical or virtual servers over a network, all traffic between VPS 1 and VPS 2 must be encrypted using TLS/SSL, and firewall rules (such as UFW or iptables) must strictly whitelist communication between the specific IP addresses of both servers.

Step-by-Step Implementation Guide

Let's dive into the step-by-step configuration required to establish this lightweight streaming pipeline.

Step 1: Configuring MySQL on VPS 1

For Debezium to capture changes, MySQL must be configured to write row-level changes to its binary log. Edit your MySQL configuration file (my.cnf or mysqld.cnf) and apply the following settings:

[mysqld]
server-id         = 223344
log_bin           = mysql-bin
binlog_format     = ROW
binlog_row_image  = FULL
expire_logs_days  = 7

After updating the configuration, restart the MySQL service. Next, create a dedicated database user for Debezium with the appropriate replication privileges:

CREATE USER 'debezium'@'%' IDENTIFIED BY 'YourSecurePassword';
GRANT SELECT, RELOAD, SHOW DATABASES, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'debezium'@'%';
FLUSH PRIVILEGES;

Step 2: Deploying Kafka and Debezium on VPS 1

To keep the footprint ultra-lightweight, you can deploy Apache Kafka, Zookeeper, and Kafka Connect via Docker Compose on VPS 1. Create a docker-compose.yml file containing the Kafka ecosystem and include the Debezium MySQL connector plugin inside the Kafka Connect image container.

Once deployed, register the Debezium MySQL connector by sending a JSON payload to the Kafka Connect REST API:

{
  "name": "mysql-source-connector",
  "config": {
    "connector.class": "io.debezium.connector.mysql.MySqlConnector",
    "tasks.max": "1",
    "database.hostname": "localhost",
    "database.port": "3306",
    "database.user": "debezium",
    "database.password": "YourSecurePassword",
    "database.server.id": "184054",
    "database.server.name": "vps1_mysql",
    "database.include.list": "inventory_db",
    "database.history.kafka.bootstrap.servers": "kafka:9092",
    "database.history.kafka.topic": "schema-changes.inventory"
  }
}

Step 3: Setting Up Elasticsearch on VPS 2

On VPS 2, ensure Elasticsearch is properly installed and configured to accept external traffic from VPS 1 securely. In elasticsearch.yml, modify the network settings:

network.host: 0.0.0.0
http.port: 9200
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

Create the necessary mapping indices in Elasticsearch that mirror the multi-dimensional structure required by your application front-end. Ensure data types like geo_point, nested objects, or keyword arrays are predefined for maximum search efficiency.

Step 4: Consuming Kafka Topics and Ingesting to Elasticsearch

With Debezium successfully streaming MySQL mutations into Kafka topics (e.g., vps1_mysql.inventory_db.products), you need a lightweight consumer to push these changes to VPS 2. You can use Kafka Connect Elasticsearch Sink Connector running on VPS 1, pointing directly to the public/private secure IP of VPS 2:

{
  "name": "elasticsearch-sink-connector",
  "config": {
    "connector.class": "io.confluent.connect.elasticsearch.ElasticsearchSinkConnector",
    "tasks.max": "1",
    "topics": "vps1_mysql.inventory_db.products",
    "connection.url": "https://:9200",
    "connection.username": "elastic",
    "connection.password": "ElasticSecurePassword",
    "type.name": "_doc",
    "key.ignore": "false",
    "schema.ignore": "true"
  }
}

Handling Multi-Dimensional Data Transformations

Relational databases decompose data into normalized tables (e.g., Orders, Customers, Products). Elasticsearch, conversely, performs optimally when data is denormalized and multi-dimensional. To bridge this structural gap in real-time, you have two strategic paths:

  1. Database Views: Create a MySQL view that joins multiple tables, and configure Debezium to stream the view changes (Note: This requires specific configuration and log capturing considerations).
  2. Kafka Streams / SMT (Single Message Transformations): Utilize Kafka Connect SMTs or a lightweight Node.js/Python stream processor to intercept raw table logs from Kafka, enrich them by aggregating multi-dimensional relationships, and emit the final denormalized JSON object straight to the Elasticsearch sink topic.

Production Considerations and Best Practices

Deploying a cross-VPS distributed system demands strict adherence to operational best practices to ensure resilience and high performance:

  • Network Reliability & Retries: Public networks experience intermittent packet loss. Configure aggressive retry mechanisms within your Kafka Connect sink parameters (errors.retry.timeout and errors.retry.delay.max.ms) to seamlessly handle temporary cross-VPS network disconnects without losing data integrity.
  • Schema Evolution: Database migrations are inevitable. Ensure Debezium is configured to track schema modifications so that sudden column additions or removals in MySQL do not break the down-stream Elasticsearch indexing consumer.
  • Monitoring and Alerts: Monitor consumer group lags closely. If the ingestion speed into Elasticsearch drops below the transaction generation speed in MySQL, lag will accumulate. Tools like Prometheus and Grafana can track Kafka offset lag to preemptively warn infrastructure teams.

Conclusion

Implementing a real-time, multi-dimensional synchronization pipeline between MySQL and Elasticsearch across separate VPS environments doesn't require resource-heavy, expensive tools. By leveraging Debezium and CDC architecture, you bypass resource-intensive polling mechanisms entirely, processing changes directly via transaction logs with sub-second latency. This guarantees that your end-users always experience lightning-fast search queries backed by the absolute latest production transactional data.

Real-Time Multi-Dimensional Data Synchronization Between MySQL and Elasticsearch Across Separate VPS Using Debezium CDC | DPTCloud