6 Defining Data Contracts
This chapter covers
- Event design principles
- Supporting data contracts in Kafka
- Type evolution and schema changes
- Common challenges in managing data contracts
With the fundamentals of Kafka and its real-world fit in place, let’s now turn to a practical question: how to define events and express them as durable, evolvable data contracts. We’ll set event boundaries and granularity, compare state versus delta events (and when each fits), and map domain events to Kafka messages without losing business meaning. You’ll learn the tools and techniques for managing contracts over time: type evolution and compatibility, format choices, ownership, and how teams communicate changes. Finally, we make Schema Registry concrete—its architecture, the idea of subjects, compatibility rules—and survey practical alternatives. This should set you up with a clear path from whiteboard models to production-ready schemas that teams can rely on.
6.1 Field notes: Turning business facts into schemas
The team gathers to discuss an important question about how to define data contracts.
Max: Alright team, we haven't really talked about events yet. What exactly is an event, and how do we define it when systems communicate through Kafka? It's not like a service with a clear endpoint and parameters. So, how does a consumer know what data to expect?