I'm now implementing a transactional outbox pattern with polling publisher. and I have a question about how to anize kafka message to publish.
I have this Outbox mongodb document.
@Data
@Document
public class PaymentOutbox {
@Id
private String id;
private String aggId;
private ProcessStage processStage;
private String payload;
@Builder
protected PaymentOutbox(String aggId, ProcessStage processStage, String payload) {
this.aggId = aggId;
this.processStage = processStage;
this.payload = payload;
}
}
and I use avro to publish Outbox Message through kafka. my avro schema is this.
{
"namespace": "com.someexample",
"name": "PaymentOutboxMessage",
"type": "record",
"fields": [
{
"name": "aggId",
"type": "string"
},
{
"name": "processStage",
"type": "string"
},
{
"name": "payload",
"type": "string"
}
]
}
payload will carry result of payment. at this point, I have a question.
which is better way and most practical way to make avro schema?
using full payload which is result of payment. -> first I thought it is little bit awkward because it is duplication of document. but I don't have to do select query in @KafkaListener.
using only id of payment that can @KafkaListener perform select query. -> I have to do findOne() using mongoTemplate but less cost of Kafka Message.
I'm sorry for my poor english skill.
first I implemented with first scenario. but I just want to know proper way to implementing it.