Kafka partition synchronization strategy

Updated at:

When you configure a data synchronization job to Kafka, you can adjust the Kafka partition synchronization strategy to improve performance. For example, you can synchronize data to different partitions based on hash results.

Hash algorithm

DTS uses Java’s default hashcode algorithm to calculate hash values.

Configuration method

Configure the Policy for Shipping Data to Kafka Partitions during the Configure Objects step of your data synchronization job.

Warning

After you start the data synchronization job, do not change the number of partitions in the destination topic. Otherwise, the synchronization task may fail or result in data inconsistency for downstream consumers.

Strategy details

Source database is Kafka

Policy Description Advantage and disadvantage
Ship All Data to Partition 0 Migrates all data and DDL statements to Partition 0 of the destination topic.
  • Advantage: The creation and change order of all objects is preserved as in the source database.
  • Disadvantage: Migration performance is limited.
Ship Data to Separate Partitions Based on Hash Values of Database and Table Names Uses the database and table names as the partition key to calculate the hash value, then migrates the data and DDL statements of each table to the corresponding partition of the destination topic.
Note
  • The data and DDL statements of the same table are migrated to the same partition.
  • If a DDL statement is irrelevant to a table, for example, CREATE DATABASE, the statement is migrated to Partition 0.
  • Advantage: The creation and change order of each destination table matches the source table, with good migration performance.
  • Disadvantage: Data changes across different tables may be out of order after migration.
Ship Data to Separate Partitions Based on Hash Values of Primary Keys Uses a table column as the partition key to calculate the hash value. By default, the primary key is used. If a table does not have a primary key, the unique key is used instead. Each row is migrated to the corresponding partition of the destination topic. You can also specify one or more columns as partition keys.
Note
  • If you use this policy, DDL statements are migrated to Partition 0 of the destination topic by default.
  • If a table does not have a primary key or unique key, DTS migrates the data and DDL statements of the table to Partition 0 of the destination topic.
  • Advantage: This policy provides the best migration performance.
  • Disadvantage: The change order of each data record is preserved, but changes across different tables or tables without a primary key may be out of order.

Source database is Tair/Redis

Policy Name

Description

Pros and cons

Ship All Data to Partition 0

Deliver all data and DDL information to Partition 0 of the destination topic.

  • Advantage: The order of object creation and changes matches the source database.

  • Disadvantage: Performance is average.

Ship the full data and incremental data of an ApsaraDB for Redis instance to separate partitions

Deliver full data and incremental data from the Redis instance to different partitions in the destination topic.

  • Advantage: Data from the Redis instance is distributed across multiple partitions.

  • Disadvantage: Data for the same key might appear in different partitions. Performance is average.

Ship data to separate partitions based on hash values of Redis Keys

Use the Redis key as the partition key to compute a hash value. Then, deliver both full and incremental data to different partitions in the destination topic.

  • Advantage: Data from the Redis instance is distributed across multiple partitions.

  • Disadvantage: Data for the same key might appear in different partitions. Performance is average.

Source database is another database

Policy Name

Description

Pros and cons

Ship All Data to Partition 0

Deliver all data and DDL information to Partition 0 of the destination topic.

  • Advantage: The order of object creation and changes matches the source database.

  • Disadvantage: Performance is average.

Ship Data to Separate Partitions Based on Hash Values of Database and Table Names

Combine the database name and table name as the partition key to compute a hash value. Then, deliver each table’s data and DDL information to different partitions in the destination topic.

Note
  • Data and DDL information for the same table go to the same partition.

  • DDL statements unrelated to tables (for example, CREATE DATABASE) go to Partition 0.

  • Advantage: The order of creation and changes for a single table matches the source. Performance is good.

  • Disadvantage: The relative order between different tables cannot be guaranteed.

Ship Data to Separate Partitions Based on Hash Values of Primary Keys

Use table columns (by default, the primary key. If no primary key exists, use a unique key) as the partition key to compute a hash value. Then, deliver different rows to different partitions in the destination topic. You can also specify one or more columns as the partition key.

Note
  • Under this policy, DDL information is delivered to Partition 0 by default.

  • If a table has neither a primary key nor a unique key, DTS delivers both its data and DDL information to Partition 0.

  • Advantage: This policy offers the best performance.

  • Disadvantage: Only the order of changes for a single record is guaranteed. Order cannot be guaranteed for tables without primary keys or across multiple tables.