Skip to main content

Event Streaming (Avro/Kafka)

Type-safe code generation for Apache Kafka and Avro schemas. No more Object types, no more manual casting, no more runtime surprises.

What is it?​

Typr generates type-safe JVM code from Avro schemas (.avsc) and protocols (.avpr). You write schemas, run the generator, and get clean, immutable data classes with typed Kafka producers and consumers.

Before (Standard Avro tooling):

public class OrderPlaced extends SpecificRecordBase {
private Object orderId; // Actually a UUID, but typed as Object
private Object customerId; // Actually a Long
public Object get(int field) { ... } // No type safety
}

Object value = order.get(0);
UUID id = (UUID) value; // Runtime cast, might fail

After (Typr):

public record OrderPlaced(
UUID orderId,
Long customerId,
BigDecimal totalAmount,
List<String> items
) implements OrderEvents {
// Immutable, all fields properly typed
}

UUID id = order.orderId(); // No casting needed

Features​

FeatureDescription
Immutable RecordsJava records, Kotlin data classes, Scala case classes
Typed Producersproducer.send(orderId, new OrderPlaced(...))
Typed ConsumersHandler interface with one method per event type
Multi-Event TopicsSealed interfaces for topics with multiple event types
Complex Unions["string", "int", "boolean"] β†’ StringOrIntOrBoolean
Wrapper Typesx-typr-wrapper for type-safe IDs
Precise TypesDecimal10_2 with compile-time constraint validation
Typed HeadersStrongly-typed Kafka headers
RPC SupportRequest/reply from .avpr protocols
Framework IntegrationSpring Boot, Quarkus, Cats (fs2-kafka)

Supported Languages​

  • Java 21+ - Records with pattern matching
  • Kotlin 2.0+ - Data classes with nullable types
  • Scala 3 - Case classes with Option types

Wire Formats​

FormatDescription
Avro + ConfluentBinary Avro with Schema Registry
AvroPlain binary Avro
JSONJackson, Circe, or ZIO JSON

Effect Types​

EffectReturn TypeUse Case
BlockingTSynchronous code
CompletableFutureCompletableFuture<T>Async Java
MutinyUni<T>Quarkus
CatsIOIO[T]Cats Effect
ZIOTask[T]ZIO

Next Steps​