Let's imagine we have a user object and we want to sync the state of this object through a service-oriented architecture using events. Regarding the event that is sent when the user is modified, I was wondering which of these options would be better for the body of the event:
- Sending just the fields that have been modified.
- Sending all the fields in the user object, leaving in the subscriber the responsibility to check which fields have suffered any modification.
In the example I am thinking of, the following would be a feasible scenario:
- In service A the field
profile
of the user is updated, and an event in the topicuser-updated
event is sent - Service B, which is subscribed to that topic updates the user information, and as a consequence of that update the field
contact-email
of that user is modified. Given that the state of the user has changed, an event is sent to the same topic. - Service A, which is also subscribed to that topic, receives the event and locally updates the
contact-email
field of the user. Given that the state of the user has changed, an event is sent to the same topic. - Service B receives the last event where only
contact-email
has changed and tries to update the user. As there is no change between the existing user information and the received user information, there is no state change and no further event is sent touser-updated
topic.
This process seems quite complex for me even though there are just 2 services keeping track of the state of the user. In a real example, the number of such services could be much higher.