Updating messages in Kafka(Java)

Hi,
How can I update the message in kafka via java? I ve producer and consumer where POST working fine but how should I use PATCH with kafka

Clarify? Kafka isn’t an HTTP protocol. Also messages cannot be modified once sent to the broker

So let me ask in another way… How do I consume and overwrite only changes for related object

What I am trying to ask is, let suppose I sent this object to Kafka and consume it… Then I would like to update the price… So how consumer can identify this

    "title": "Thsirt",
    "img": "img1",
    "categories": [
        "Fitness",
        "Men"
    ],
    "size": "40",
    "price": 16,
    "countInStock": 20
}```

One option is to send a whole new event

    "title": "Thsirt",
    "img": "img1",
    "categories": [
        "Fitness",
        "Men"
    ],
    "size": "40",
    "price": 42,
    "countInStock": 20
}```

Other option would be to build a KTable that holds a “itemUUID” as a key, and then you have a stream of fields that change {"UUID": "xyz", "fields": {"price": 42}}. Then you have a stream processor that parses these events, and updates the record according to the ordered events, by each key.

The first option is more common if you use Kafka Connect from databases like Mongo or an RDBMS, particularly with Debezium

This pages covers some more details https://stackoverflow.blog/2022/07/21/event-driven-topic-design-using-kafka/

Might be noob question but how consumer can understand its the same product

That’s exactly the issue. Your producer needs to generate some identifier. Then you need to maintain state somewhere

Thus why any shopping store has product SKUs

What kind of identifier, something like key ? What is SKUs

Yes, a key. A SKU is a “Stock keeping unit”. Your example shows a TShirt. What sets that shirt apart from any other shirt?

Or in a physical store, a barcode is associated with a SKU and barcodes map to some numeric value.

Sorry for bothering but can you please share one example about this key

Can we say its not a good practice to use kafka for PATCH

Most programming languages have UUID generator functions. Start with that when you have any “new” shirt event. Then you need to “lookup” the same value when you perform any “update”.

Like I said, Kafka isn’t an HTTP protocol. Updates/Upserts work fine if you design your event payloads properly.

Thanks a lot