liveBook · Manning

Polyglot topic

As explained in Kafka for Architects

A polyglot topic is a Kafka topic that contains multiple event types with distinct schemas.

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

How Kafka for Architects covers it

How deep it goes
Defines the pattern, contrasts RecordNameStrategy with TopicNameStrategy, and explains consumer deserialization responsibilities.
Examples
Uses ClientCreated, ClientUpdated, and ClientDeleted events sharing a client identifier for partitioning.
What it assumes
Assumes Kafka topics, schemas, partition keys, and schema registry concepts; distinguishes topic-bound from record-based subjects.
What you can do after
Apply it via RecordNameStrategy when cross-type ordering is essential and consumers can handle multiple schemas.
How it connects
Connects Kafka topics with schema registry, Avro schemas, partitioning, RecordNameStrategy, and domain-driven design.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka for Architects. The section links point to the parts of the book it draws on.