The Workers Law
Heavy I/O operations such as dispatching 50,000 WhatsApp messages, streaming audio to telephony carriers, or parsing massive lead CSV files must never execute inside the NestJS HTTP request cycle. BrokerOS enforces that all background jobs, bulk broadcasts, and external provider dispatches are enqueued via BullMQ backed by Redis and processed independently byapps/workers/.
BullMQ Processing Pipeline
Dedicated Worker Processors
All worker processors live inapps/workers/src/processors/ and run as dedicated Node.js worker nodes:
1. marketing-voice.processor.ts
- Processes autonomous outbound AI voice campaigns.
- Integrates
normalizeVoiceLeadVariablesfrom@brokeros/constantsto sanitize customer names, project titles, and phonetic pronunciations. - Uses
tryCarrierBridgeDispatchfrom@brokeros/int-voiceto initiate calls via Vobiz, Exotel, Twilio, or Telnyx. - Enforces strict carrier trunk concurrency limits (e.g., maximum 25 concurrent calls per trunk) to prevent SIP line exhaustion.
2. marketing-whatsapp.processor.ts
- Processes outbound Meta message template broadcasts and drip automations.
- Regulates dispatch velocity according to Meta Messaging Tiers:
- Tier 1: 1,000 unique customers per rolling 24 hours
- Tier 2: 10,000 unique customers per rolling 24 hours
- Tier 3: 100,000 unique customers per rolling 24 hours
- Modular sub-runners in
processors/whatsapp/:whatsapp-broadcast.runner.ts: Batch broadcast distributionwhatsapp-automation.runner.ts: Conditional drip workflow executionwhatsapp-template.syncer.ts: Synchronizes approved templates from Meta
3. marketing-sms.processor.ts
- Dispatches bulk promotional and transactional SMS messages.
- Appends DLT principal entity IDs and template IDs for telecommunications compliance in India.
- Batches gateway transmissions (Gupshup, Twilio, Sinch, AWS SNS) in chunks of 100 recipients.
4. marketing-email.processor.ts
- Streams personalized HTML emails through SendGrid, Brevo, or AWS SES.
- Injects tracked short-links and transparent 1x1 tracking pixels for open and click attribution.
- Suppresses previously bounced or complained recipient addresses automatically.
5. scheduled-messages.processor.ts
- Processes scheduled 1-on-1 team inbox messages across SMS, Email, and WhatsApp.
- Runs on a high-frequency 10-second interval scanner to pick up due messages promptly.
- Delegates dispatch execution directly to the deep
@brokeros/messagingmodule (dispatchScheduledMessage):- Atomic Reservation: Acquires a mutex lock via conditional database transition (
status: 'SCHEDULED'transitioning tostatus: 'PROCESSING'), preventing race conditions with concurrent worker nodes or immediate API triggers. - Provider Execution: Dispatches via cached adapter instances across SMS (Twilio, Gupshup, Sinch, AWS SNS), Email (SendGrid, Brevo, AWS SES), or WhatsApp (Meta Cloud API).
- Audit Preservation: Transitions message state in-place to
DELIVERED,SENT, orFAILEDwhile maintaining thread conversation summaries without deleting audit rows.
- Atomic Reservation: Acquires a mutex lock via conditional database transition (
- Resilient against worker restarts and power cycles: any message in
SCHEDULEDstatus withscheduledAt <= NOW()is picked up immediately upon restart.