A polyglot topic is a Kafka topic that contains multiple event types with distinct schemas. It fits cases where preserving ordering across related events matters more than keeping one schema per topic. section 6.4.3
Ordered client events
ClientCreated, ClientUpdated, and ClientDeleted can share a topic when all events use the client identifier as their partition key. Consumers then receive each client’s changes in order, but must deserialize several event types into different objects. section 6.4.3
Design implications include:
- Use RecordNameStrategy when event schemas should be independent of a specific topic. section 6.4.3
- Recognize the trade-off: consumers must identify event types and deserialize them into different objects. section 6.4.3
Listing 6.10 An example of the client event in Avro format
{
"type": "record",
"name": "ClientEvent",
"namespace": "com.example",
"fields": [
{
"name": "eventId",
"type": "string",
"doc": "Unique identifier for the event"
},
{
"name": "eventType",
"type": "string",
"doc": "Type of event (e.g., 'ClientCreated', 'ClientUpdated')"
},
{
"name": "timestamp",
"type": "long",
"logicalType": "timestamp-millis",
"doc": "Event timestamp in milliseconds"
},
{
"name": "clientId",
"type": "string",
"doc": "Unique identifier for the client"
},
{
"name": "clientName",
"type": "string",
"doc": "Name of the client"
}
]
}
An Avro ClientEvent schema illustrates shared event metadata, eventType discrimination, timestamps, and client identity. section 6.4.3
