Build an end-to-end change data capture with Amazon MSK Connect and AWS Glue Schema Registry
For platform teams, the key design choice is not just streaming data, but preserving schema discipline across the whole path. CDC pipelines that move row-level database changes into Kafka and then into object storage depend on a serializer, a registry, and compatible worker settings all agreeing on record shape. That makes connector configuration part of the data contract, not just an operational detail.
MSK Connect shifts connector execution into a managed runtime, which simplifies deployment but increases the importance of plugin packaging, IAM permissions, network placement, and worker configuration. The source and sink connectors each need their own libraries, serialization settings, and topic or table mappings. In practice, this means integration work sits at the boundary between database change capture, Kafka transport, and downstream storage format conversion.
Schema evolution is the main control point for resilience. Backward compatibility helps downstream consumers keep reading older payloads while the source schema changes, but it also introduces governance overhead: incompatible changes must be rejected or isolated, and teams need a plan for dead-letter handling, version visibility, and consumer testing. For architects, the real trade-off is between fast schema change and predictable multi-system interoperability.
There is also a storage-layer implication. Writing CDC output to S3 in columnar form can improve downstream analytics efficiency, but it adds an extra transformation step and a partitioning strategy that must align with read patterns. That makes the pipeline suitable for near-real-time analytics and migration use cases, while still requiring careful operational ownership across source database, stream processing, registry policy, and sink layout.
- It eliminates the need for bulk load updating and inconvenient batch windows by enabling incremental loading or real-time streaming of data changes into your target repository.
- It ensures that data in multiple systems stays in sync. This is especially important if youโre making time-sensitive decisions in a high-velocity data environment.
Solution overview
On the producer side, for this example we choose a MySQL-compatible Amazon Aurora database as the data source, and we have a Debezium MySQL connector to perform CDC. The Debezium connector continuously monitors the databases and pushes row-level changes to a Kafka topic. The connector fetches the schema from the database to serialize the records into a binary form. If the schema doesnโt already exist in the registry, the schema will be registered. If the schema exists but the serializer is using a new version, the schema registry checks the compatibility mode of the schema before updating the schema. In this solution, we use backward compatibility mode. The schema registry returns an error if a new version of the schema is not backward compatible, and we can configure Kafka Connect to send incompatible messages to the dead-letter queue.
On the consumer side, we use an Amazon Simple Storage Service (Amazon S3) sink connector to deserialize the record and store changes to Amazon S3. We build and deploy the Debezium connector and the Amazon S3 sink using MSK Connect.
Example schema
For this post, we use the following schema as the first version of the table:{
โDatabase Nameโ: โsampledatabaseโ,
โTable Nameโ: โmoviesโ,
โFieldsโ: [
{
โnameโ: โmovie_idโ,
โtypeโ: โINTEGERโ
},
{
โnameโ: โtitleโ,
โtypeโ: โSTRINGโ
},
{
โnameโ: โrelease_yearโ,
โtypeโ: โINTEGERโ
}
]
}
Prerequisites
Before configuring the MSK producer and consumer connectors, we need to first set up a data source, MSK cluster, and new schema registry. We provide an AWS CloudFormation template to generate the supporting resources needed for the solution:- A MySQL-compatible Aurora database as the data source. To perform CDC, we turn on binary logging in the DB cluster parameter group.
- An MSK cluster. To simplify the network connection, we use the same VPC for the Aurora database and the MSK cluster.
- Two schema registries to handle schemas for message key and message value.
- One S3 bucket as the data sink.
- MSK Connect plugins and worker configuration needed for this demo.
- One Amazon Elastic Compute Cloud (Amazon EC2) instance to run database commands.
- Choose Launch Stack:
- Choose Next.
- For Stack name, enter suitable name.
- For Database Password, enter the password you want for the database user.
- Keep other values as default.
- Choose Next.
- On the next page, choose Next.
- Review the details on the final page and select I acknowledge that AWS CloudFormation might create IAM resources.
- Choose Create stack.
Custom plugin for the source and destination connector
A custom plugin is a set of JAR files that contain the implementation of one or more connectors, transforms, or converters. Amazon MSK will install the plugin on the workers of the MSK Connect cluster where the connector is running. As part of this demo, for the source connector we use open-source Debezium MySQL connector JARs, and for the destination connector we use the Confluent community licensed Amazon S3 sink connector JARs. Both the plugins are also added with libraries for Avro Serializers and Deserializers of the AWS Glue Schema Registry. These custom plugins are already created as part of the CloudFormation template deployed in the previous step.Use the AWS Glue Schema Registry with the Debezium connector on MSK Connect as the MSK producer
We first deploy the source connector using the Debezium MySQL plugin to stream data from an Amazon Aurora MySQL-Compatible Edition database to Amazon MSK. Complete the following steps:- On the Amazon MSK console, in the navigation pane, under MSK Connect, choose Connectors.
- Choose Create connector.
- Choose Use existing custom plugin and then pick the custom plugin with name starting
msk-blog-debezium-source-plugin. - Choose Next.
- Enter a suitable name like
debezium-mysql-connectorand an optional description. - For Apache Kafka cluster, choose MSK cluster and choose the cluster created by the CloudFormation template.
- In Connector configuration, delete the default values and use the following configuration key-value pairs and with the appropriate values:
- name โ The name used for the connector.
- database.hostsname โ The CloudFormation output for Database Endpoint.
- database.user and database.password โ The parameters passed in the CloudFormation template.
- database.history.kafka.bootstrap.servers โ The CloudFormation output for Kafka Bootstrap.
- key.converter.region and value.converter.region โ Your Region.
name=<Connector-name>
connector.class=io.debezium.connector.mysql.MySqlConnector
database.hostname=<DBHOST>
database.port=3306
database.user=<DBUSER>
database.password=<DBPASSWORD>
database.server.id=42
database.server.name=db1
table.whitelist=sampledatabase.movies
database.history.kafka.bootstrap.servers=<MSK-BOOTSTRAP>
database.history.kafka.topic=dbhistory.demo1
key.converter=com.amazonaws.services.schemaregistry.kafkaconnect.AWSKafkaAvroConverter
value.converter=com.amazonaws.services.schemaregistry.kafkaconnect.AWSKafkaAvroConverter
key.converter.region=<REGION>
value.converter.region=<REGION>
key.converter.registry.name=msk-connect-blog-keys
value.converter.registry.name=msk-connect-blog-values
key.converter.compatibility=FORWARD
value.converter.compatibility=FORWARD
key.converter.schemaAutoRegistrationEnabled=true
value.converter.schemaAutoRegistrationEnabled=true
transforms=unwrap
transforms.unwrap.type=io.debezium.transforms.ExtractNewRecordState
transforms.unwrap.drop.tombstones=false
transforms.unwrap.delete.handling.mode=rewrite
transforms.unwrap.add.fields=op,source.ts_ms
tasks.max=1
- connector.class is the Java class of the connector
- tasks.max is the maximum number of tasks that should be created for this connector
database.*, transforms.*) are specific to the Debezium MySQL connector. Refer to Debezium MySQL Source Connector Configuration Properties for more information.
Some settings (key.converter.* and value.converter.*) are specific to the Schema Registry. We use the AWSKafkaAvroConverter from the AWS Glue Schema Registry Library as the format converter. To configure AWSKafkaAvroConverter, we use the value of the string constant properties in the AWSSchemaRegistryConstants class:
key.converterandvalue.convertercontrol the format of the data that will be written to Kafka for source connectors or read from Kafka for sink connectors. We useAWSKafkaAvroConverterfor Avro format.key.converter.registry.nameandvalue.converter.registry.namedefine which schema registry to use.key.converter.compatibilityandvalue.converter.compatibilitydefine the compatibility model.
- Next, we configure Connector capacity. We can choose Provisioned and leave other properties as default
- For Worker configuration, choose the custom worker configuration with name starting
msk-gsr-blogcreated as part of the CloudFormation template. - For Access permissions, use the AWS Identity and Access Management (IAM) role generated by the CloudFormation template
MSKConnectRole. - Choose Next.
- For Security, choose the defaults.
- Choose Next.
- For Log delivery, select Deliver to Amazon CloudWatch Logs and browse for the log group created by the CloudFormation template (
msk-connector-logs). - Choose Next.
- Review the settings and choose Create connector.
Use the AWS Glue Schema Registry with the Confluent S3 sink connector running on MSK Connect as the MSK consumer
We deploy the sink connector using the Confluent S3 sink plugin to stream data from Amazon MSK to Amazon S3. Complete the following steps:-
- On the Amazon MSK console, in the navigation pane, under MSK Connect, choose Connectors.
- Choose Create connector.
- Choose Use existing custom plugin and choose the custom plugin with name starting
msk-blog-S3sink-plugin. - Choose Next.
- Enter a suitable name like
s3-sink-connectorand an optional description. - For Apache Kafka cluster, choose MSK cluster and select the cluster created by the CloudFormation template.
- In Connector configuration, delete the default values provided and use the following configuration key-value pairs with appropriate values:
-
- name โ The same name used for the connector.
- s3.bucket.name โ The CloudFormation output for Bucket Name.
- s3.region, key.converter.region, and value.converter.region โ Your Region.
-
name=<CONNERCOR-NAME>
connector.class=io.confluent.connect.s3.S3SinkConnector
s3.bucket.name=<BUCKET-NAME>
key.converter=com.amazonaws.services.schemaregistry.kafkaconnect.AWSKafkaAvroConverter
value.converter=com.amazonaws.services.schemaregistry.kafkaconnect.AWSKafkaAvroConverter
s3.region=<REGION>
storage.class=io.confluent.connect.s3.storage.S3Storage
partitioner.class=io.confluent.connect.storage.partitioner.DefaultPartitioner
format.class=io.confluent.connect.s3.format.parquet.ParquetFormat
flush.size=10
tasks.max=1
key.converter.schemaAutoRegistrationEnabled=true
value.converter.schemaAutoRegistrationEnabled=true
key.converter.region=<REGION>
value.converter.region=<REGION>
value.converter.avroRecordType=GENERIC_RECORD
key.converter.avroRecordType=GENERIC_RECORD
value.converter.compatibility=NONE
key.converter.compatibility=NONE
store.kafka.keys=false
schema.compatibility=NONE
topics=db1.sampledatabase.movies
value.converter.registry.name=msk-connect-blog-values
key.converter.registry.name=msk-connect-blog-keys
store.kafka.headers=false
- Next, we configure Connector capacity. We can choose Provisioned and leave other properties as default
- For Worker configuration, choose the custom worker configuration with name starting
msk-gsr-blogcreated as part of the CloudFormation template. - For Access permissions, use the IAM role generated by the CloudFormation template
MSKConnectRole. - Choose Next.
- For Security, choose the defaults.
- Choose Next.
- For Log delivery, select Deliver to Amazon CloudWatch Logs and browse for the log group created by the CloudFormation template
msk-connector-logs. - Choose Next.
- Review the settings and choose Create connector.
Test the end-to-end CDC log stream
Now that both the Debezium and S3 sink connectors are up and running, complete the following steps to test the end-to-end CDC:- On the Amazon EC2 console, navigate to the Security groups page.
- Select the security group
ClientInstanceSecurityGroupand choose Edit inbound rules. - Add an inbound rule allowing SSH connection from your local network.
- On the Instances page, select the instance
ClientInstanceand choose Connect. - On the EC2 Instance Connect tab, choose Connect.
- Ensure your current working directory is
/home/ec2-userand it has the filescreate_table.sql,alter_table.sql,initial_insert.sql, andinsert_data_with_new_column.sql. - Create a table in your MySQL database by running the following command (provide the database host name from the CloudFormation template outputs):
mysql -h <DATABASE-HOST> -u master -p < create_table.sql
- When prompted for a password, enter the password from the CloudFormation template parameters.
- Insert some sample data into the table with the following command:
mysql -h <DATABASE-HOST> -u master -p < initial_insert.sql
- When prompted for a password, enter the password from the CloudFormation template parameters.
- On the AWS Glue console, choose Schema registries in the navigation pane, then choose Schemas.
- Navigate to
db1.sampledatabase.moviesversion 1 to check the new schema created for the movies table:
{
"type": "record",
"name": "Value",
"namespace": "db1.sampledatabase.movies",
"fields": [
{
"name": "movie_id",
"type": "int"
},
{
"name": "title",
"type": "string"
},
{
"name": "release_year",
"type": "int"
},
{
"name": "__op",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "__source_ts_ms",
"type": [
"null",
"long"
],
"default": null
},
{
"name": "__deleted",
"type": [
"null",
"string"
],
"default": null
}
],
"connect.name": "db1.sampledatabase.movies.Value"
}
- On the Amazon S3 console, check for data written in Parquet format in the folder for your Kafka topic.
Schema evolution
After the initial schema is defined, applications may need to evolve it over time. When this happens, itโs critical for the downstream consumers to be able to handle data encoded with both the old and the new schema seamlessly. Compatibility modes allow you to control how schemas can or canโt evolve over time. These modes form the contract between applications producing and consuming data. For detailed information about different compatibility modes available in the AWS Glue Schema Registry, refer to AWS Glue Schema Registry. In our example, we use backward combability to ensure consumers can read both the current and previous schema versions. Complete the following steps:- Add a new column to the table by running the following command:
mysql -h <DATABASE-HOST> -u master -p < alter_table.sql
- Insert new data into the table by running the following command:
mysql -h <DATABASE-HOST> -u master -p < insert_data_with_new_column.sql
- On the AWS Glue console, choose Schema registries in the navigation pane, then choose Schemas.
- Navigate to the schema
db1.sampledatabase.moviesversion 2 to check the new version of the schema created for the movies table movies including the country column that you added:
{
"type": "record",
"name": "Value",
"namespace": "db1.sampledatabase.movies",
"fields": [
{
"name": "movie_id",
"type": "int"
},
{
"name": "title",
"type": "string"
},
{
"name": "release_year",
"type": "int"
},
{
"name": "COUNTRY",
"type": "string"
},
{
"name": "__op",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "__source_ts_ms",
"type": [
"null",
"long"
],
"default": null
},
{
"name": "__deleted",
"type": [
"null",
"string"
],
"default": null
}
],
"connect.name": "db1.sampledatabase.movies.Value"
}
- On the Amazon S3 console, check for data written in Parquet format in the folder for the Kafka topic.
Clean up
To help prevent unwanted charges to your AWS account, delete the AWS resources that you used in this post:- On the Amazon S3 console, navigate to the S3 bucket created by the CloudFormation template.
- Select all files and folders and choose Delete.
- Enter permanently delete as directed and choose Delete objects.
- On the AWS CloudFormation console, delete the stack you created.
- Wait for the stack status to change to DELETE_COMPLETE.
Conclusion
This post demonstrated how to use Amazon MSK, MSK Connect, and the AWS Glue Schema Registry to build a CDC log stream and evolve schemas for data streams as business needs change. You can apply this architecture pattern to other data sources with different Kafka connecters. For more information, refer to the MSK Connect examples.About the Author
Kalyan Janaki is Senior Big Data & Analytics Specialist with Amazon Web Services. He helps customers architect and build highly scalable, performant, and secure cloud-based solutions on AWS.Enjoyed this article? Sign up for our newsletter to receive regular insights and stay connected.
