Richard Miles
Richard Miles

Reputation: 557

What information do I store for a partial event update in Event Sourcing?

I have the following data for an existing topic event.

id: 123
version: 1
data: { name: "Bob", age: 21 }
topic: 'candidate'
action: 'create'

Now I would like to visualise an update to this record. e.g. If the candidate has now been rejected.

Would I add the new event, by spreading / including the previous event data?

id: 123
version: 2,
data: { name: "Bob", age: 21, rejected: true }
topic: 'candidate'
action: 'update'

or would I record this as a stand alone entry?

id: 123
version: 2,
data: { rejected: true }
topic: 'candidate'
action: 'update'

or should I do something completely different?

Upvotes: 0

Views: 122

Answers (1)

Levi Ramsey
Levi Ramsey

Reputation: 20561

In general, you want the event to solely be "what changed". So from that perspective, the second one is better than the first.

But the principle can be applied even further. What changed is that the candidate was rejected, and that can be defined by a constant string like "rejected" as the event's data/payload:

id: 123
version: 2
data: 'rejected'
topic: 'candidate'
action: 'update'

Upvotes: 1

Related Questions