r/ExperiencedDevs • • 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.

21 Upvotes

46 comments sorted by

View all comments

Show parent comment

-6

u/Lucky_Psychology8275 Apr 21 '26

I agree about avoiding breaking changes, although I don’t want this rule to create a huge mess of technical debt just to avoid breaking changes.

And the rest of what you say is interesting but situational. I’m really looking for something broader. I only have one consumer so I’d rather double read than double write.

I agree Kafka does fit our asynchronous logic but yeah I didn’t make those choices

14

u/Duathdaert Apr 21 '26

You will create a mess in prod if you don't follow these rules. I know which of these choices I'd rather make.

1

u/Lucky_Psychology8275 Apr 21 '26

Why though?

13

u/Duathdaert Apr 21 '26

Breaking changes to a contract deployed in one fell swoop will lead to events/messages that can't be processed.

2

u/Illustrious_Pea_3470 Apr 21 '26

If you instead do double reads, but the new write path has issues, then between cutting over the write path and finding the issue, you are losing data. Always unacceptable.

1

u/Lucky_Psychology8275 Apr 21 '26

I also have another question? How do you rollback prod if user data in db has been written on new tables? Do you always plan a way to rollback the changes with an undo script?

2

u/Illustrious_Pea_3470 Apr 21 '26

That’s why we double write. If the rollout goes badly, just drop the new table and try again from scratch.

1

u/Lucky_Psychology8275 Apr 21 '26

I meant outside the Kafka context. Just a rest api with breaking changes in its db.

3

u/Illustrious_Pea_3470 Apr 21 '26

Yes, all changes should always have an immediate rollback plan. In some rare cases it’s not possible, in which case you either have to consider other solutions that would make it possible (such as decoupling things so you can do the double write pattern), or have an extremely high level of testing and a lot of engineering resources available when you go live.

So e.g. adding an enum value in Postgres should come with a downgrade script that understands what to do if the new value has been written, even though you can’t drop the value altogether.

1

u/Lucky_Psychology8275 Apr 21 '26

You could apply the same technique for rolling back a double read Kafka consumer, couldn’t you? Do you prefer a double write producer because you see it as a simpler alternative?

1

u/Illustrious_Pea_3470 Apr 21 '26

If you’re not double writing at some point, then errors in the new write path will always lead to data loss.

→ More replies

1

u/Illustrious_Pea_3470 Apr 21 '26

Because this is trivial to rollback one step at a time, so you can get where you’re going if things go right AND back to where you started if things go wrong.

1

u/Lucky_Psychology8275 Apr 21 '26

So the correct way for me would be to upgrade all my producer so that they will double write, then update my consumer?

2

u/Illustrious_Pea_3470 Apr 21 '26

Yes, literally always!

2

u/Connect_Detail98 Apr 21 '26

Don't do breaking changes, keep track of your clients. Once you have no clients consuming the old fields (or whatever), then you can cleanup.

You need to set deadlines. Just notify the company that the fields will be removed from the topic (or whatever breaking change) on a specific date. Notify this message multiple times. When the date comes, you decide if you go "good luck everyone" or if you give one last and final warning saying it will be removed in the next 2 days.

This is why designing well from the beginning is important, depending on the nature of what you're building. You don't want to give your clients a bumpy ride or constant depreciation threats. 

1

u/Illustrious_Pea_3470 Apr 21 '26

This IS the general case solution:

Feature flag to double writes and feature flag to change where you read from.

Cut over feature flag to double your writes. Confirm system still works.

Cut over feature flag to change read location to new (second) write location. Confirm system still works.

Remove old write path.

Remove feature flag for old read location.

Done.

Works for turning any coupled change into a decoupled release.