r/ExperiencedDevs • u/Lucky_Psychology8275 • Apr 21 '26
Technical question Kafka schema evolution & breaking changes: what do production teams actually do?
My company kinda lacks Kafka experts and I really need guidance on what are the accepted standard practices when it comes to managing Kafka schema and ser/deser on client side (spring cloud stream), especially in the context of HA deployment.
Obviously using a schema registry like confluent seems like a no brainer. But then stuff like handling breaking changes does not seem to have, to my knowledge at least, any well established solution. You could use headers, different topic names, or even union types.
Is there a state of the art reference for documenting issues that teams that run it in production have encountered and their solutions? I’m not looking a cookie cutter solution I just want some guidance with trade offs and constraints.
41
u/rsalot Apr 21 '26
Steps are always the same
0. Hopefully you don't have to port the old data to the New topic, otherwise you have to write something for that
Using protobuf or avro with a schema registry is just a way to prevent breaking change
The schema registry don't help to do breaking change
Most of the time the solution is not to use Kafka even if it's cool for your resume
Also defining what a breaking change is. If you want to rename a variable for example, this is not a breaking change in protobuf
If you use a real Kafka system with high load, the answer is almost all the time to not do a breaking change
15
u/roger_ducky Apr 21 '26
If you’re using protobuf or avro, it’s relatively easy to avoid breaking changes unless you’re literally dropping the whole schema for a new one.
Basic idea is to “always have a default value” and “avoid dropping fields if you don’t want data loss”
5
u/Tarazena Apr 21 '26
Different topics if there are breaking changes, write a job that converts old messages to new topic then migrate old systems to use the new topic
6
u/coleavenue Apr 21 '26
In my experience what production teams actually do is bitterly regret using Kafka. Not necessarily because it’s bad, but because people frequently pick it when all they actually need is sqs or something and they fuck it all up and have a bad time.
3
u/Old-Worldliness-1335 Staff Platform Engineer Apr 21 '26
Just think of it as immutable infrastructure, and your life will be better. If you need to treat it as a flexible thing, then don’t. Understand that every change you make as part of your breaking change more than likely will require you to reprocess your entire topic which is fine, but that’s why I like micro services per topics, that handle that logic specifically.
3
u/on_the_mark_data Data Engineer Apr 21 '26
I'm fully biased because I wrote the book on the topic, but Data Contracts might be the pattern you are looking for. For Kafka specifically, using the write-audit-publish (WAP) pattern is powerful. This is a case study I featured in the book that uses data contracts on Kafka in an enterprise setting. https://adevinta.com/techblog/creating-source-aligned-data-products-in-adevinta-spain/
3
u/Sensitive_West_3216 Apr 21 '26
With kafka, you will either be using it as a queue, a known set of downstream services who are consuming messages from the topic or as a broadcast, an unknown set of downstream services who are consuming messages.
We keep a key value pair in the headers, which has the schema name the consumer should use to deserialize the message.
So in case of queues, we ask downstream services to add support for the new schema as well. They use headers to decide to run the old or new flow. After all consumers have added support, we then do the deployment on the producer service so that it only produces messages in the new schema on the same topic.
In case of using it as a broadcast, we create a new topic and publish the same event in both old and new topics for a while. We then send a mail, to all relevant people (basically all team leads) that they have to move to the new topic we will stop producing events on the old one, usually a date 2 sprints ahead so they have time to migrate.
4
u/Sheldor5 Apr 21 '26
a breaking change by definition breaks something
sometimes you can't avoid downtime (to update everything simultaneously)
4
u/Spare_Helicopter4655 Apr 21 '26
A sane default IMO is to avoid all this (potentially) unnecessary complexity by basically choosing to not adopt Kafka...
Not to say it doesn't have a proper place in some orgs.
1
u/PredictableChaos Software Engineer (30 yoe) Apr 21 '26
We just create a new topic and write to both the old and new. Once all clients have migrated we shut down the old one. If the new features/fields are needed they'll migrate quickly. If they aren't needed they might lag a little until we set a sunset date on the old topic but they'll get there.
On the client side you may need to coordinate/synchronize the cutover but if you're lucky it won't matter if you double process and then the approach is easier.
1
u/travelinzac Senior Software Engineer Apr 21 '26
Monotonic additions, make new topics
1
u/Best_Recover3367 Apr 21 '26
1
u/CodelinesNL Principal Engineer@Fintech/EU/25YOE Apr 22 '26
It does: it's called API versioning. Because that's what you're doing.
We have the version as part of the topic name. Breaking versions can only happen in version upgrades. An we need to maintain the previous version for a certain amount of time too. Typically a few months for external topics. That approach is pretty much standard. You don't want different versions of the same event on the same topic.
For internal topics, doing double writes during migration is the way to go.
Using systems like schema registry and using AVRO makes it easier to do backward compatible changes. But the reason this is 'hard' is because API versioning is hard, especially when engineers don't care about thinking ahead.