Current state: "Under Discussion"
Discussion thread: TBD
Released: 2.6 (target)
Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).
Today we have multiple ways to infer and inherit serde along the topology, and only fall back to the configured serde when inference does not apply. More specifically, the serde overriding precedence is the following:
- Serde specified explicitly via the control objects, such as Consumed, Produced, Grouped, etc.
Serde inferred from the parent / child operators which are specified explicitly. For example, for a topology like builder.stream(.., Consumed.of(..)).groupByKey().reduce() where the source stream's key-value serdes are specified via `Consumed`, then the reduced table's key and value serdes can inherit from the source stream since their types are not changed.
- Serde specified via the global config ("default.key.serde" and "default.value.serde").
Since this serde overriding logic is executed implicitly, it is hard for users to infer which serdes are actually going to be used. And if a user mistakenly sets a serde or simply default to the configured serde which mismatches, they will not get informed until they start processing and get a runtime ClassCastException.
So I'd propose we augment the topology description with serde information on place that would execute serde, i.e. source / sink topics and state store operators.
The generated String from TopologyDescription#toString would be augmented with the serde information in the form of:
To illustrate with a concrete example, suppose we have the following application code:
The current topology-description would be the following:
With this proposal, the augmented topology-description would be the following:
In order to support that, I'd propose the make the following API augments on the TopologyDescription and its corresponding children classes:
And with the augmented programing interface, we can also allow users to loop over all source / sink nodes and all state stores of a sub-topology so that we can expose all topics (sink, source, intermediate and changelog) as:
The reason we did not expose APIs for topic names directly is that for source nodes, it is possible to have Pattern and for sink nodes, it is possible to have topic-extractors, and hence it's better to let users leveraging on the lower-level APIs to construct the topic names programmatically themselves.
In order to fall back to global config values, we will need to leverage on the newly added `StreamsBuilder#build(Properties)`; if the old `StreamsBuilder#build()` is called, then serde information would not be exposed via the description (i.e. they will be null) since it is not yet "determined". Also if the TopologyDescription is from the topology built from `StreamsBuilder#build()`, then its `toString` function would not be augmented as well.
Note that the augmented topology description only contains the serde class name, but it does not necessarily include the inner class name.
Compatibility, Deprecation, and Migration Plan
If there are any applications that depends on parsing the string value for, e.g. visualizing the topology description, then their code needs to be updated accordingly. I think this is okay to break such compatibility without introducing a deprecation phase of it since we are leveraging on the newly added `build()` function.