Arquitetura de Sistemas Distribuídos e Resiliência

Architecture Challenges for Messaging in an Omnichannel Platform

Building an omnichannel messaging platform goes far beyond simply sending and receiving messages.

architecturequalitysoftware

Architecture Challenges in an Omnichannel Messaging Platform

Introduction

Building an omnichannel messaging platform goes far beyond simply sending and receiving messages.

When a company centralizes channels such as WhatsApp, Facebook Messenger, Instagram, WebChat, Telegram, proprietary APIs, and messaging brokers into a single solution, significant challenges arise related to scalability, availability, security, and data consistency.

A well-planned architecture is essential to guarantee a good experience for the end user.

Furthermore, it must be able to withstand adverse scenarios such as:

A messaging platform needs to be resilient, scalable, and observable in order to keep operating even when part of the infrastructure is failing.


Architecture Overview

A modern omnichannel messaging architecture typically has several specialized layers.

text
Conectores Externos
        ↓
Webhook
        ↓
Backend
        ↓
Fila
        ↓
Consumer
        ↓
Processor
        ↓
Workflow Engine
        ↓
Banco de Dados

Backend
        ↓
WebSocket
        ↓
Frontend

Each layer has specific responsibilities and its own challenges.


Webhooks

Webhooks represent the platform's entry point.

It is through them that messages coming from the various connected channels arrive.


Main challenges

Receiving messages from multiple sources

An omnichannel platform can receive events from:

Each integration has different formats and behaviors.

The platform must normalize this information into a single internal model.


Responding quickly

Most providers work with aggressive timeouts.

Example:

text
Webhook → Timeout de 5 segundos

If the full processing happens before responding, there is a risk of:

That's why the webhook must:

  1. Validate the message
  2. Persist or enqueue it
  3. Respond immediately

Validating authenticity

Every incoming request must have its origin validated.

Examples:

This prevents malicious agents from sending fake messages to the platform.


Returning errors correctly

Avoid generic responses such as:

http
500 Internal Server Error

Whenever possible:

http
400 Bad Request

for an invalid payload.

http
401 Unauthorized

for an invalid signature.

http
403 Forbidden

for unauthorized access.

This makes monitoring and troubleshooting easier.


Backend

The backend is responsible for exposing the APIs used by the frontend and coordinating the platform's operations.


Main challenges

High availability

Even during high message volumes, the backend must remain available for:

A congested queue must not make the administrative system unavailable.


Security

All communication must use:

Ensuring that each user only accesses authorized data.


Consistent responses

In case of error, the backend must provide clear information.

Example:

json
{
  "error": "validation_error",
  "field": "phone",
  "message": "Número inválido"
}

Allowing the frontend to properly guide the user.


Frontend

The frontend is the point of contact between the platform and its operators.


Main challenges

Performance

The system must be fast and responsive.

Even companies with thousands of simultaneous conversations need to maintain a smooth experience.


Guiding the user

In unexpected situations, the system must clearly inform:

Example:

text
Falha ao enviar mensagem.
Clique para tentar novamente.

Displaying status

The operator needs to know:

As well as the exact time of each event.


Real-time updates

The user should not have to rely on:

text
F5
Atualizar página

All updates must happen automatically through WebSockets.


WebSocket

WebSockets are responsible for real-time communication.


Main challenges

Resilient connections

The system must support:

Without harming the operator's experience.


Correct event distribution

Not every user should receive every event.

Example:

text
Mensagem Empresa A

Must not reach:

text
Usuário Empresa B

Correct routing is essential.


Permission control

Every event must validate:

Before being distributed.


Consumer

The consumer processes messages received from the queues.


Main challenges

Identifying the origin

When consuming a message it must be possible to determine:

Ensuring traceability.


Routing to the correct tenant

A WhatsApp message from one company can never be processed in the context of another company.

Isolation between tenants is mandatory.


Dead Letter Queue

Problematic messages must not block the main queue.

Recommended flow:

text
Fila Principal
      ↓
Falha
      ↓
Dead Letter Queue

Circuit Breaker

If an external provider is unavailable:

text
Facebook indisponível

it must not impact:

text
WhatsApp
Instagram
WebChat

Prefetch control

The number of messages processed simultaneously must respect the available resources.

Example:

text
CPU disponível
Memória disponível
Número de workers

Enabling horizontal scalability.


Processor

The processor is responsible for sending messages to external channels.


Main challenges

Building the request

Each channel has its own requirements.

Example:

WhatsApp:

json
{
  "to": "...",
  "type": "text"
}

Facebook:

json
{
  "recipient": "...",
  "message": {}
}

The processor needs to transform the internal model into the format expected by each provider.


Credential management

Each company can have:

Different for each integration.


Scalability

Just like the consumer, the processor must:

According to message volume.


Workflow Engine

The workflow layer is responsible for the platform's automations.


Main challenges

Building automated flows

Examples:


Low latency

The user expects near-instant responses.

Slow flows harm the service experience.


Avoiding excessive queries

A common mistake is performing multiple database queries at every step of the flow.

This causes:

Whenever possible, one should use:


Traceability

It is essential to log:

Enabling auditing and diagnostics.


Non-blocking external calls

When running external integrations:

text
ERP
CRM
Gateway de Pagamento
API de Consulta

the workflow must not block the entire queue while waiting for a response.

An approach based on Promises and asynchronous processing reduces bottlenecks.


Scalability

Just like consumers and processors, workflows must allow:

According to demand.