The Problem ( in simple words )
Softwares lose data working with MQ systems.
High volume processing requires data to be managed within memory. MQ-based systems like Kafka, Rabbit MQ, and Active MQ are some examples.
While these systems manage millions of messages, they are ‘transient in nature’. Meaning – once a message is delivered. It’s done ! No redelivery, no success/ failure feedback, no querying the data back.
This means the software ought to work with 100% reliability. Anyone in the real world knows that simply isn’t true !
In the real world, software breaks. Code runs into unhandled conditions and error scenarios.
The Problem ( in nerdy words )
From : https://event-driven.io/en/outbox_inbox_patterns_and_delivery_guarantees_explained/
The problems of “at least once” and “exactly once” are NOT managed by MQ systems.
At least once:
A guarantee that a message will be delivered at least once. Maybe more.
If we receive a message multiple times – then our system should be able to handle it ( be idempotent )
Idempotent:
If I send a message once OR multiple times, the system will remain in the same state.
In other words – sending the message multiple times, will NOT mess up the system.
Exactly once:
The guarantee that a message will be delivered once and only once.
Kafka provides this with the groupId, offset counts for each topic.
At most once:
The message will be delivered a maximum once
And it is possible for the message to be NOT delivered even once. Ofcourse, we don’t want this to happen.
We want a message to be delivered and processed only once !
Since a memory-only system is transient in nature. Persisting message states and guaranteeing “exactly once” delivery is NOT possible within MQ systems.
The Solution ( in simple words )
Persist incoming and outgoing data into local memory. ( Inbox Outbox pattern )
A mailing system works as follows:
This design decouples the data exchange ( message delivery ), from data processing ( message processing )
How does it help ?
The Solution ( in Nerdy words )
Use the Inbox/ Outbox design pattern.
Inbox
Outbox
The tables can also be used for audit and reporting purposes.
Problem solved !
Seems like we are just discussing decoupling message delivery and receipt from logic on received messages. Yes?
Thats right @Paul.
You’ve put it as an intuitive design, but most standard libraries do NOT provide this function. And therefore this needs to be custom implemented.