nestjs-kafka
nestjs-kafka copied to clipboard
Caching of latest schema ID's
Firstly, thanks for the work here!🚀
In KafkaAvroRequestSerializer
, the latest schema id's are saved. Definitely makes sense for me - but what happens when a schema updates (and with it the correct latest id)?
Do we need a mechanism for period refreshes of the latest schema id's?
Hi @maxgr0 Thanks! 😁
So the current workflow I have while using this library is to restart the service in order to pick up the new schema version. I know there has been a fair bit of re work done to the underlying library: https://github.com/kafkajs/confluent-schema-registry
By default when a new message from Kafka is received it includes the registry I'd: https://github.com/kafkajs/confluent-schema-registry/blob/master/src/SchemaRegistry.ts
Which the library gets from cache or loads from schema. We could look at similar functionality.
Have you thoughts on how you'd want to implement it?
deserialize
is not a problem - logic here makes sense for me.
Just wondering if I have a thinking error here. We're having a couple of replicas sitting behind a Kubernetes Ingress. When producer-related code updates, the replicas update successively anyways (so the schema id's are updated in any case). This raises the question if something like a TTL is really needed 🤔 What are your thoughts about this @rob3000?
I think an implementation could be easy to do, setting a variable like lastSchemaIdFetch
and compare it when serialize
is done. To let this be scaled up without having thousands of parallel requests to the schema registry, a second indicator e.g. isFetchingSchema
could be used.
I think having something like a TTL for the serialize
would make sense so that it would auto update to the latest schema without requiring intervention.
I think that implementation idea sounds great!
Sounds good! Do you plan to add this feature in the next time or are you busy at the moment?
Hi @maxgr0 sorry for the delay, I've pushed out this change to master, will look to get through testing this later today/tomorrow.
@rob3000 oh mate you're the real MVP. Please send over your PayPal, I owe you some beers!
@maxgr0 thanks! Though to be fair the guys over at KafkaJS could use the beers more than i :)