0Pricing
Apache Kafka & Stream Processing Fundamentals · Pelajaran

Skema Avro & Protobuf

Pelajari format serialisasi populer seperti Avro dan Protobuf serta cara menggunakannya bersama Schema Registry.

Skema Avro & Protobuf adalah pelajaran Apache Kafka & Stream Processing Fundamentals gratis di CoddyKit. Ini adalah pelajaran 2 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Apache Kafka & Stream Processing Fundamentals, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Apache Kafka & Stream Processing Fundamentals mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

Data Formats for Kafka

When sending data through Kafka, it's just bytes. To make sense of these bytes, both the sender (producer) and receiver (consumer) need to agree on a common structure.

This is where data serialization formats and schemas come in, providing a blueprint for your data.

Meet Apache Avro

Apache Avro is a popular, language-agnostic data serialization system. It relies heavily on schemas to define the structure of data.

  • Compactness: Data is serialized into a compact binary format.
  • Schema Evolution: Avro handles schema changes gracefully, allowing producers and consumers with different schema versions to communicate.
  • Language Agnostic: Tools exist for many programming languages.

Avro Schemas: JSON Power

Avro schemas are defined using JSON. This makes them human-readable and easy to manage. A schema describes the data's fields, their types, and any default values.

Basic Avro types include string, int, long, boolean, float, double, bytes, and null.

Building an Avro Schema

Let's define a simple Avro schema for a "User" record. Notice the type, name, and fields with their own name and type.

{
  "type": "record",
  "name": "User",
  "namespace": "com.coddykit.avro",
  "fields": [
    {"name": "name", "type": "string"},
    {"name": "age", "type": ["int", "null"], "default": 0}
  ]
}

How Avro Uses Schemas

With Avro, the schema travels with the data (or is known by the consumer via Schema Registry). This means the actual data payload is very small, as field names and types aren't repeated for every message.

The schema acts as a contract, ensuring data consistency and enabling efficient serialization and deserialization.

Meet Protocol Buffers (Protobuf)

Protocol Buffers (Protobuf) is Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. It's designed to be smaller and faster than XML.

  • Efficiency: Very compact binary format.
  • Code Generation: Compilers generate code for various languages based on .proto definitions.
  • Backward/Forward Compatibility: Supports schema evolution through careful field numbering.

Protobuf Schemas: .proto Files

Protobuf schemas are defined in .proto files using a special syntax. You define message types, which are like classes, and specify fields within them.

Each field requires a type, a name, and a unique field number. These numbers are crucial for backward and forward compatibility.

Building a Protobuf Schema

Here's a simple .proto definition for a "Product" message. Notice the syntax, message keyword, and the assigned field numbers (e.g., 1, 2).

syntax = "proto3";

package com.coddykit.protobuf;

message Product {
  string id = 1;
  string name = 2;
  double price = 3;
}

Avro vs. Protobuf: A Quick Comparison

Both Avro and Protobuf are excellent for data serialization, but they have different characteristics:

  • Schema Format: Avro uses JSON; Protobuf uses its own .proto syntax.
  • Code Generation: Avro is schema-first (can generate code); Protobuf is often code-first (generates code from .proto).
  • Data Size: Both are very compact, often outperforming JSON/XML.
  • Schema Evolution: Both support it, but with different strategies (Avro relies on Schema Registry, Protobuf on field numbers).

Quick Check

You've learned about Avro and Protobuf. Which statement correctly identifies the primary way Avro and Protobuf schemas are defined?

Recap: Structured Data for Kafka

Great job! In this lesson, we explored two powerful data serialization formats: Apache Avro and Protocol Buffers (Protobuf).

  • Avro uses JSON for schema definitions and is excellent for schema evolution.
  • Protobuf uses a .proto syntax with field numbers for compact, efficient data.

Both help ensure data consistency and efficiency when used with Kafka and Schema Registry, which we'll explore further next!

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Skema Avro & Protobuf” gratis?

Ya — teks lengkap “Skema Avro & Protobuf” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Apache Kafka & Stream Processing Fundamentals, upgrade ke CoddyKit PRO. Kursus Apache Kafka & Stream Processing Fundamentals mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Skema Avro & Protobuf”?

Pelajari format serialisasi populer seperti Avro dan Protobuf serta cara menggunakannya bersama Schema Registry. Kamu berlatih Apache Kafka & Stream Processing Fundamentals dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai Apache Kafka & Stream Processing Fundamentals?

Tidak diperlukan pengalaman sebelumnya. Apache Kafka & Stream Processing Fundamentals di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 2 dari 4.

Berapa lama pelajaran “Skema Avro & Protobuf” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran Apache Kafka & Stream Processing Fundamentals ini?

Ya. Setiap pelajaran Apache Kafka & Stream Processing Fundamentals menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Mengapa Pengelolaan Skema?
  2. Skema Avro & Protobuf
  3. Mengintegrasikan Schema Registry dengan Kafka
  4. Evolusi Skema dan Mode Kompatibilitas
← Kembali ke Apache Kafka & Stream Processing Fundamentals