This is article 5 of 10 in the Mercado Tech Brasil series on solutions architecture. In the previous article, we looked at APIs, where one system calls another and waits for the answer. Now the focus is messaging and events, the model in which systems communicate without having to be available at the same moment.
Synchronous and asynchronous in solutions architecture
In synchronous communication, the caller waits. If the other side is slow or down, the slowness spreads. In asynchronous communication, the sender leaves a message in an intermediate structure and moves on; the receiver processes it when it can.
Picture an e-commerce site during a sales peak. When an order is confirmed, several things need to happen: deduct stock, issue the invoice, notify the carrier, send the email to the customer and update the reports. If the confirmation screen waits for all of that, any slow service stalls the sale. With messaging, the order system publishes that the order was confirmed, and each interested party reacts at its own pace.
Messaging and events: queues and topics
- Queue: each message is delivered to a single consumer. It is used to distribute work, such as generating documents or processing incoming files.
- Topic with subscriptions: each message is delivered to every interested party. It is used to announce that something happened, such as "order confirmed" or "customer updated their profile."
A useful distinction: a command asks for something to be done ("issue the invoice"); an event reports something that has already happened ("order confirmed"). Events reduce coupling, because the publisher does not need to know who will react.
Benefits of messaging and events in solutions architecture
- Decoupling: new consumers join without changing the publisher.
- Peak absorption: the queue holds the excess and consumers process it at the pace they can manage.
- Resilience: if the email service goes down, messages wait instead of being lost.
- Independent scaling: you can scale only the most overloaded consumers.
The safeguards you can't skip
Duplicate messages
Most platforms guarantee at-least-once delivery, which means the same message can arrive twice. Consumers need to be idempotent: processing again must not produce two emails or two stock deductions.
Failures and problematic messages
Define how many times a message will be retried and where it goes after that. A monitored dead-letter queue keeps one faulty item from blocking the whole flow.
Eventual consistency
For a few moments, the order may show as confirmed while the report has not been updated yet. The business needs to accept this, and users need to have it explained to them.
Saving and publishing together
If the system saves the order to the database and fails before publishing the event, the others will never learn about the order. The outbox pattern solves this: the event is saved in the same transaction as the order and published afterward by a separate process.
In practice
In process automation, messaging is what separates a fragile flow from a robust one. When I design integrations in consulting, I use synchronous calls for quick lookups and events for anything that can wait a few seconds. I also include tracing with a correlation ID from the start, so an order can be followed end to end across systems.
Translated from the original in Portuguese. Read the original.