architectureamazon-sqsevent-driven-design

SQS Messaging Design: Payload vs. Reference?


I'm working on an event-driven system using AWS SQS and facing a design decision when sending commands between services. The command triggers an operation in the receiving service, and that operation requires multiple pieces of data — potentially 15+ parameters.

The dilemma:

I’m trying to keep the architecture clean, scalable, and maintainable

My gut: It feels messy to cram all parameters into a single message, but I'm aware of introducing latency and tight coupling by forcing the consumer to retrieve external data.

What’s the most robust and clean approach in your experience? Any best practices for hybrid strategies?


Solution

  • I'd always prefer including the necessary data in the message and avoid the "callback". Only sending a notification with a reference, and have the receiver get the actual data via query

    I'd only use a notification with a reference if the payload is too big for the message channel and if the referenced data is immutable. E.g. if your service generates a PDF document and wants to notify others about it.

    P.S.: You should be mindful of the terminology. Your saying you're developing an event- driven system, but then you talk about sending commands.

    Events and commands are very different things!

    (In almost all cases... for a more differentiated view see https://www.reactivesystems.eu/2024/11/30/not-all-commands-are-equal.html)

    If you're sending commands, you're implementing a message-driven system, but it's not an event-driven system.
    In fact, if you want to keep it scalable and maintainable, you should think about making it actually event-driven, and publish events, not send commands.