Paul Kirby
Paul Kirby

Reputation: 580

Message Bus and Events - How to React?

I'm designing an event-based system that involves two services, A and B.

When a user updates a resource in service A using a PUT, that service will send a notification onto a message queue. Service B reads from that queue, and then must update the state of one of its resources based on the change that occurred to the resource in A.

As I see it, there are two ways to handle this:

  1. The message that service A sends contains the field of the resource that changed, and what it changed from and to. When service B consumes this message, it uses that information to determine the state of its resource.
  2. The message that service A sends only contains a link to the resource that changed. When service B consumes this message, it calls that link to retrieve the current state of A's resource for its own processing.

Which method do you all find more agreeable? I lean towards #1 due to the receiver of the message not needing to possibly have out-of-band knowledge of service B (yes, it has a link but it might not have the correct headers, the correct HTTP verb, etc), and to reduce the amount of service chatter.

Any ideas would be appreciated!

Upvotes: 1

Views: 712

Answers (1)

Michael Deardeuff
Michael Deardeuff

Reputation: 10707

Both are viable options. Which version you choose depends on multiple things.

  • How expensive is it to look up the resource? If it is expensive, then lean towards Option 1.
  • How expensive is it to send the change on the queue?Option 1 sends a diff, and if that diff is large, it could become costly. Option 2 only sends a link to the resource. A third option is a to store the diff as a resource.
  • Can the system deal with multiple changes to the resource? For example, the resource could change multiple times between the time A sends the notification and system B reads the resource. If the system can deal with this, Option 2 has the opportunity to ignore some updates, potentially reducing processing. If the system cannot deal with this you must use Option 1.

Upvotes: 1

Related Questions