Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Google Cloud Platform icon
Labs

Evolving an Avro Schema in a Kafka Application

Confluent Schema Registry is a useful tool for coordinating contracts between producers and consumers, as well as simplifies the process of serializing and deserializing complex data objects. However, it also provides some powerful functionality to help you manage changes to your data schemas. In this lab, you will have the opportunity to make a change to an existing schema by adding a new field. This will give you some hands-on experience with the process of evolving a schema using the Confluent Schema Registry.

Google Cloud Platform icon
Lab platform
Lab Info
Level
Intermediate
Last updated
Sep 15, 2025
Duration
30m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Clone the Starter Project and Run It to Make Sure Everything Is Working
    1. Clone the starter project into your home directory:
    cd ~/
    git clone https://github.com/linuxacademy/content-ccdak-schema-evolve-lab.git
    
    1. Run the code to ensure it works before modifying it:
    cd content-ccdak-schema-evolve-lab
    ./gradlew runProducer
    ./gradlew runConsumer
    

    Note: The consumer should output some records that were created by the producer.

  2. Challenge

    Update the Purchase Schema to Add the `member_id` Field
    1. Edit the schema definition file:
    vi src/main/avro/com/linuxacademy/ccdak/schemaregistry/Purchase.avsc
    
    1. Add the member_id field with a blank default:
    {
      "namespace": "com.linuxacademy.ccdak.schemaregistry",
      "compatibility": "FORWARD",
      "type": "record",
      "name": "Purchase",
      "fields": [
        {"name": "id", "type": "int"},
        {"name": "product", "type": "string"},
        {"name": "quantity", "type": "int"},
        {"name": "member_id", "type": "int", "default": 0}
      ]
    }
    
  3. Challenge

    Update the Producer to Set the `member_id` for the Records It Publishes
    1. Edit the schema definition file:
    vi src/main/avro/com/linuxacademy/ccdak/schemaregistry/Purchase.avsc
    
    1. Add the member_id field with a blank default:
    {
      "namespace": "com.linuxacademy.ccdak.schemaregistry",
      "compatibility": "FORWARD",
      "type": "record",
      "name": "Purchase",
      "fields": [
        {"name": "id", "type": "int"},
        {"name": "product", "type": "string"},
        {"name": "quantity", "type": "int"},
        {"name": "member_id", "type": "int", "default": 0}
      ]
    }
    

    Update the Producer to Set the member_id for the Records It Publishes

    1. Edit the producer Main class:
    vi src/main/java/com/linuxacademy/ccdak/schemaregistry/ProducerMain.java
    
    1. Implement the new member_id field in the producer by setting it for the records being produced:
    package com.linuxacademy.ccdak.schemaregistry;
    
    import io.confluent.kafka.serializers.AbstractKafkaAvroSerDeConfig;
    import io.confluent.kafka.serializers.KafkaAvroSerializer;
    import java.util.Properties;
    import org.apache.kafka.clients.producer.KafkaProducer;
    import org.apache.kafka.clients.producer.ProducerConfig;
    import org.apache.kafka.clients.producer.ProducerRecord;
    import org.apache.kafka.common.serialization.StringSerializer;
    
    public class ProducerMain {
    
        public static void main(String[] args) {
            final Properties props = new Properties();
            props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
            props.put(ProducerConfig.ACKS_CONFIG, "all");
            props.put(ProducerConfig.RETRIES_CONFIG, 0);
            props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
            props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class);
            props.put(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, "http://localhost:8081");
    
            KafkaProducer<String, Purchase> producer = new KafkaProducer<String, Purchase>(props);
    
            Purchase apples = new Purchase(1, "apples", 17, 77543);
            producer.send(new ProducerRecord<String, Purchase>("inventory_purchases", apples.getId().toString(), apples));
    
            Purchase oranges = new Purchase(2, "oranges", 5, 56878);
            producer.send(new ProducerRecord<String, Purchase>("inventory_purchases", oranges.getId().toString(), oranges));
    
            producer.close();
        }
    
    }
    
    1. Run the producer:
    ./gradlew runProducer
    
    1. Run the consumer:
    ./gradlew runConsumer
    
    1. Verify the data in the output file. We should see the new member_id data in the last lines of the file:
    cat /home/cloud_user/output/output.txt
    
About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight