Avro ve Protobuf Şemaları
Avro ve Protobuf gibi popüler serileştirme biçimlerini ve bunların Schema Registry ile nasıl kullanıldığını öğrenin.
Avro ve Protobuf Şemaları, CoddyKit'te ücretsiz bir Apache Kafka & Stream Processing Fundamentals dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Apache Kafka & Stream Processing Fundamentals öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Apache Kafka & Stream Processing Fundamentals kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
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
.protodefinitions. - 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
.protosyntax. - 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
.protosyntax 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!
Sıkça Sorulan Sorular
“Avro ve Protobuf Şemaları” dersi ücretsiz mi?
Evet — “Avro ve Protobuf Şemaları” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Apache Kafka & Stream Processing Fundamentals kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Apache Kafka & Stream Processing Fundamentals kursu toplamda 4 dersten oluşur.
“Avro ve Protobuf Şemaları” dersinde ne öğreneceğim?
Avro ve Protobuf gibi popüler serileştirme biçimlerini ve bunların Schema Registry ile nasıl kullanıldığını öğrenin. Apache Kafka & Stream Processing Fundamentals ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Apache Kafka & Stream Processing Fundamentals öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Apache Kafka & Stream Processing Fundamentals, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.
“Avro ve Protobuf Şemaları” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Apache Kafka & Stream Processing Fundamentals dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Apache Kafka & Stream Processing Fundamentals dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Şema Yönetimi Neden Önemlidir?
- Avro ve Protobuf Şemaları
- Schema Registry'yi Kafka ile Tümleştirme
- Şema Evrimi ve Uyumluluk Kipleri