Moving to a message broker: more reliable delivery and clearer event processing

We moved message delivery to a dedicated broker: events now pass through a reliable flow with queues, retries, idempotency, and clear processing statuses.

We have completed the transition of notification delivery and other background event flows to a dedicated message broker.

Why we made this change

Previously, business logic, event creation, and direct message delivery were tightly coupled. A temporary failure at an external provider could affect the main request, while diagnosing an issue required collecting information from several logs.

The new architecture separates these responsibilities: the application records the event, the broker accepts it into a queue, and specialized workers perform delivery and return a clear processing result.

How the new flow works

  • Reliable recording. The event is first stored in a transactional outbox, so an application restart does not cause it to disappear unnoticed.
  • RabbitMQ queue. The broker accepts messages and passes them to independent worker processes without blocking the main API.
  • Retries. Temporary delivery failures are handled automatically with a bounded number of attempts.
  • Idempotency. Processing the same event again should not result in uncontrolled message duplication.
  • Problem-message handling. Messages that still cannot be processed after retries are separated for further investigation instead of being lost in the main flow.

What has improved

Message delivery is no longer a critical part of the user request. The system handles restarts and short periods of external-service unavailability more reliably, while the API, broker, and workers can be scaled independently.

The operations team now has clearer statuses: it is possible to see when an event was created, published to a queue, picked up by a worker, delivered successfully, or sent for further investigation. Correlation identifiers connect the original event, processing attempts, and final error in the logs.

What comes next

The broker layer is designed as an extensible foundation for new channels and event types. Adding another handler does not require changing the main application flow: we only need to define the message contract, queue, and retry rules.

We will monitor queue length, delivery latency, retry counts, and problem messages separately. This will help us maintain predictable server load and detect deviations in notification processing earlier.