How to increase debezium / kafka connect performance for initial snapshot of millions of records and enable snapshot parallely if possible?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Debezium, integrated with Kafka Connect, provides a powerful solution for capturing data changes in a database and streaming those changes to Apache Kafka. When dealing with large data sets, optimizing the initial snapshot process is crucial for efficient performance. By default, Debezium reads and sends the entire database in a single thread, which can be slow and resource-intensive for large databases. However, there are a number of strategies that can be implemented to enhance performance and potentially parallelize this process.
1. Optimizing Database and JDBC Settings
1.1 Increase Fetch Size
The fetch size of the JDBC connection affects how many rows are retrieved in each network call. Increasing the fetch size can significantly reduce the number of round trips required to fetch all data:
1.2 Database Server Tuning
Optimize the database parameters such as checkpoint intervals, write-ahead logging (WAL), and maintenance settings to ensure the database can handle large read loads and log-heavy operations efficiently.
2. Maximizing Debezium Performance Settings
2.1 Snapshot Mode
Debezium provides different snapshot modes: initial, when_needed, and never. For large datasets, consider initial_only to ensure the snapshot only occurs once, and subsequent data changes are captured via log mining.
2.2 Snapshot Fetch Size
Configure snapshot.fetch.size to control the number of rows fetched per query during the snapshot. A higher number can be set for large tables to reduce the number of database queries:
3. Utilizing Kafka Connect Tunings
3.1 Increasing Task Count
Increase the number of tasks for the connector to parallelize processing. This does not parallelize the snapshot itself but allows simultaneous processing of multiple tables:
3.2 Connector Tuning
Adjust connector options like poll.interval.ms and batch.size to improve throughput by controlling how often and how much data the connector pulls and pushes into Kafka.
4. Partitioning Large Tables
Partitioning large tables and using multiple Debezium connectors configured differently can allow parallel snapshots. This requires advanced configuration and might involve:
- Setting up different connectors for different subsets of your tables.
- Careful planning of key ranges or data segments to ensure data consistency.
5. Hardware and Infrastructure
5.1 Network and I/O
Increase network bandwidth and I/O capabilities as Kafka and Debezium are heavily dependent on these resources during large data transfers.
5.2 Kafka Broker Tuning
Optimize Kafka brokers by adjusting settings such as message.max.bytes and replica.fetch.max.bytes to handle larger messages more efficiently.
6. Monitoring and Logging
Implement robust monitoring on both the database and Kafka Connect to identify bottlenecks like slow queries or connector backlogs. Efficient logging can aid in troubleshooting and optimizing snapshot performance.
Summary Table of Key Points
| Focus Area | Key Configuration/Strategy |
| Database Settings | Increase fetch size, tune database parameters |
| Debezium Settings | Set appropriate snapshot mode, adjust snapshot fetch size |
| Kafka Connect | Increase tasks.max, tune polling and batch size |
| Data Partitioning | Use multiple connectors or manual data segmentation |
| Infrastructure | Enhance network and Kafka broker settings |
| Monitoring | Implement comprehensive monitoring and logging |
Conclusion
Improving performance for initial loads of millions of records in Debezium involves a combination of database tuning, strategic Debezium configuration, effective Kafka Connect setups, and robust infrastructure and monitoring. While true parallel snapshots per table aren't natively supported, creative solutions like partitioning data and segmenting connectors can simulate parallel processing. Each approach comes with trade-offs and should be carefully tested in a staging environment before production deployment.
Related reading
- How to increase the number of messages consumed by Spring Kafka Consumer in each batch?
- How to install Kafka on Windows?
- How to install rabbitmq management plugin (rabbitmq-plugins)
- How to integrate Django with Kafka using Python?
- How to initialize properties that depend on each other
- How to insert 9 billions records into a database in 2 minutes?
- How to increase thread priority in pthreads?
- How to initialize a Thread in Kotlin?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.