<aside> 🔁 Synced from GitHub #f9afe7d18ae4. Edit in the paidhr-system-docs repository, not here: changes made in Notion are overwritten.

</aside>

Queues & service-to-service calls

The services talk in two ways: direct HTTP calls (synchronous: the caller waits) and queues (asynchronous: the caller drops a message and moves on). Money always moves through queues.

The map

flowchart LR
  CORE[core-backend]
  EWA[ewa-service]
  WAL[wallet-service]
  BOT[channel bot]
  CP[control panel API<br/>in core-backend]
  CORE -- "HTTP: employees, employers, loans,<br/>invoices/settle, payslip sync" --> EWA
  EWA -- "HTTP: checksession, getusersession,<br/>company wallet id" --> CORE
  EWA -- "HTTP signed: /ewa/channel/notification" --> CORE
  EWA -- "HTTP: /ewa/billing-and-invoice" --> CP
  CORE -- "HTTP: misc/banks, wallet calls" --> WAL
  CORE == "SQS AwsSqsPaymentQueue<br/>group 'payments'" ==> WAL
  WAL == "SQS payment acknowledgement" ==> CORE
  CORE == "SQS GENERAL_SQS_QUEUE<br/>create_ewa_employee, create_contact" ==> EWA
  WAL -. "SQS WALLET_GENERAL<br/>update_wallet_kyc" .-> WAL
  BOT -- "HTTP signed" --> CORE & EWA

SQS queues

Queue (env var) From → To Message groups / content Handled by
AwsSqsPaymentQueue → wallet's SQS_INITIATE_PAYOUT core-backend → wallet-service Group payments: one payout batch (wallet, beneficiaries, amounts, charges) core: ProcessQualifiedPaymentWorkerService publishes. wallet: SqsConsumerService.handleMessage → PaymentService.initiatePayment
AwsSqsPaymentAcknowledgementQueue wallet-service → core-backend Result of each payout core: PaymentAcknowledgementConsumerService (polls every few seconds)
SQS_NOTIFY_PAYOUT_INITIALIZED wallet-service → listeners Payout started wallet-service
SQS_CORE_BACKEND (GENERAL_SQS_QUEUE) core-backend ↔ ewa-service create_ewa_employee (enrol someone in EWA), create_contact (CRM contact), PING ewa: modules/sqs/sqs.consumer.ts
SQS_WALLET_GENERAL into wallet-service update_wallet_kyc wallet: handleWalletGeneralMessage

All are FIFO queues routed by MessageGroupId. One stuck message in a group holds up every message behind it, so the consumers acknowledge messages they can never process rather than retrying forever. Failed payout messages land in a dead-letter queue (…QUEUE_DLQ); wallet-service has admin endpoints to read both the queue and the DLQ.

Internal queues (Redis / BullMQ)

wallet-service splits its work into BullMQ jobs, each with its own consumer in modules/wallet/consumers:

process-individual-payment, process-corporate-payment, complete-payment, retry-payment, reverse-failed-transaction, query-transaction, query-reversal, process-wallet-transaction, create-virtual-account, fund-virtual-account, create-virtual-card, poll-virtual-card-status, process-card-funding, poll-card-funding-transfer, process-bill-payment, requery-bill-payment, process-bmoni-kyc, resolve-account-name, external-disbursement, check-provider-liability, complete-currency-swap, send-webhook-notification.

Every job is logged to BullMqLog so a stuck payment can be traced job by job.

ewa-service has its own BullMQ queue, SEND_PUSH_NOTIFICATION, for phone pushes (consumer SendPushNotificationConsumer, shown in the Bull board). See EWA.

HTTP calls core-backend makes to ewa-service

From Core.Backend.Application/Implementations/EwaService.cs:

Path Why
employers/create-company, employers/update-company-webhook Create and configure the company in EWA
employees, employees/bulk, employees/sync-data Enrol and update employees
loans Send an approved external loan to the lending partner
admin/invoices/settle Mark an EWA invoice as paid
provider-integration/generate-payslips, provider-integration/payroll-ledger-sync Payroll data for integration partners
ats/applicants/interview-notification Hiring interview notices
user/app-users App users list

Signed channel endpoints

Some calls have no user session behind them: the channel bot, ewa-service's own notifications, payroll eligibility checks for USSD. These use HMAC-signed requests with a shared secret per channel (for example EWA_PAYROLL_CHANNEL_SECRET with prefix EWA_NOTIFICATION). The signature covers the organisation, the person, a timestamp and a hash of the body, and the endpoint must populate the tenant context itself.

💡 Sending a notification from ewa-service

Use the signed POST /ewa/channel/notification endpoint. The older route through core-backend's admin announcements needs a user session, so it fails with "session invalid" for anything a job sends.

External partners