Skip to content

Event Architecture

BANA services communicate asynchronously through three mechanisms: Kafka (event streaming + CDC), Redis pub/sub (lightweight event bus), and WebSocket (real-time client notifications). This page catalogs every topic, channel, and event type.

Kafka Topics

Defined in packages/core/src/queues/kafka/topics.ts.

Application Events

TopicProducerConsumer(s)Purpose
payment.successsalefinance, inventoryPayment for a sale order completed
purchase-order.receivedinventoryfinancePurchase order received and confirmed
commerce.initializedcommercefinance, inventoryNew merchant onboarding completed
merchant.createdcommerceinventoryNew merchant created (inventory setup)
product.createdcommercetaxationNew product created
product.updatedcommercetaxationProduct updated
product-variant.createdcommercepricingNew product variant created
product-variant.updatedcommercepricingProduct variant updated
ledger.generateledger (producer)ledger (consumer)Ledger PDF/XLSX generation job

CDC Topics (Debezium)

Defined in packages/search/src/common/kafka-topics.ts. Debezium captures PostgreSQL WAL changes and publishes them to Kafka, which the search service consumes to sync Typesense.

CDC TopicSource TableTypesense Collection
nx.seller.public.Organizerpublic.Organizerorganizers
nx.seller.public.Merchantpublic.Merchantmerchants
nx.seller.public.Categorypublic.Categorycategories
nx.seller.public.Devicepublic.Devicedevices
nx.seller.public.SaleChannelpublic.SaleChannelsale-channels
nx.seller.public.Productpublic.Productproducts
nx.seller.public.ProductInfopublic.ProductInfo(enriches products)

Dead letter queue: nx.seller.cdc.dlq

Kafka Consumer Groups

ServiceClient IDGroup IDTopics
financeSVC-00040-FINANCE_CONSUMERSVC-00040-FINANCE_CONSUMER_GROUPpayment.success, purchase-order.received, commerce.initialized
inventorySVC-00050-INVENTORY_CONSUMERSVC-00050-INVENTORY_CONSUMER_GROUPpayment.success, commerce.initialized, merchant.created
pricingSVC-00070-PRICING_CONSUMERSVC-00070-PRICING_CONSUMER_GROUPproduct-variant.created, product-variant.updated
taxationSVC-00130-TAXATION_CONSUMERSVC-00130-TAXATION_CONSUMER_GROUPproduct.created, product.updated
ledgerSVC-00060-LEDGER-{n}SVC-00060-LEDGER_GROUPledger.generate
search (CDC)commerce-cdc-consumercommerce-cdc-groupAll nx.seller.public.* CDC topics

Kafka Producer Client IDs

ServiceClient ID
commerceSVC-00020-COMMERCE_PRODUCER
saleSVC-00030-SALE_PRODUCER
inventorySVC-00050-INVENTORY_PRODUCER
ledgerSVC-00060-LEDGER-01

Redis Pub/Sub Event Channels

Lightweight event channels for intra-service communication. These don't go through Kafka — they're direct Redis pub/sub.

Payment Events

Defined in packages/core/src/common/events/payment-events.ts.

ChannelPublisherSubscriber(s)Purpose
payment.order.successsale (payment webhook handler)finance, inventoryOrder payment completed — triggers income recording and stock adjustment

Sale Check Events

Defined in packages/sale/src/common/sale-check.constants.ts.

EventDescription
sale.check.createdNew check created for a sale order
sale.check.updatedCheck amounts/items updated
sale.check.mergedTwo checks merged together
sale.check.rolledBackCheck merge rolled back
sale.check.paidCheck fully paid
sale.order.mergedTwo orders merged
sale.order.mergeRolledBackOrder merge rolled back
sale.order.splitOrder split into multiple orders

WebSocket Topics

WebSocket topics follow the pattern ws:{namespace}.{domain}.{entity}. Room names follow wr:{namespace}/{path}.

Builder utilities

Defined in packages/core/src/common/events/websocket-events.ts:

  • WebSocketTopics — builds topic strings: ws:observation.sale.sale-order
  • WebSocketRooms — builds room names: wr:observation/merchants/{merchantId}

Per-service topics

Sale (packages/sale/src/common/websocket.ts):

TopicPurpose
ws:observation.sale.sale-orderOrder created/updated
ws:observation.sale.sale-order-itemOrder item changes
ws:observation.sale.sale-checkCheck state changes
ws:observation.sale.kitchen-ticketKitchen ticket dispatched
ws:observation.sale.kitchen-ticket-itemKitchen ticket item updates
ws:observation.allocation.allocation-usageSeat/allocation usage changes

Payment (packages/payment/src/common/websocket.ts):

TopicPurpose
ws:observation.payment.transactionPayment transaction status updates
ws:observation.payment.payment-attemptIndividual payment attempt events

Outreach (packages/outreach/src/components/websocket/topics.ts):

TopicPurpose
ws:observation.outreach.inquiry.submittedNew inquiry submitted (real-time admin notification)

Webhook Event Types

MQ-Pay → Sale (Payment Webhooks)

Defined in packages/sale/src/common/webhook-types.ts. The sale service receives these from MQ-Pay via the X-Webhook-Event-Type HTTP header:

Event TypeDirectionPurpose
mq-pay:attempt.successMQ-Pay → SalePayment attempt succeeded
mq-pay:attempt.failedMQ-Pay → SalePayment attempt failed
mq-pay:attempt.expiredMQ-Pay → SalePayment attempt timed out
mq-pay:attempt.cancelledMQ-Pay → SalePayment attempt cancelled by user
mq-pay:transaction.settledMQ-Pay → SaleFull transaction settled (all items paid)
mq-pay:transaction.cancelledMQ-Pay → SaleTransaction cancelled

MQ-Pay Internal Events

Published via Node.js EventEmitter within the MQ-Pay library:

EventPurpose
mq-pay:transaction.createdNew payment transaction created
mq-pay:transaction.settledTransaction fully settled
mq-pay:transaction.cancelledTransaction cancelled
mq-pay:attempt.createdPayment attempt initiated
mq-pay:attempt.sentRequest sent to provider
mq-pay:attempt.successProvider confirmed success
mq-pay:attempt.failedProvider reported failure
mq-pay:attempt.expiredAttempt timed out
mq-pay:attempt.cancelledAttempt cancelled
mq-pay:refund.successRefund completed
mq-pay:refund.failedRefund failed

These are bridged to the sale service via MQPaySaleEventAdapterSaleEventMapperServiceSalePaymentEventHandlerService.

Event Flow Diagrams

New Merchant Onboarding

Payment Flow

Product Sync (CDC)

PageDescription
ArchitectureService registry, dependency chain, component matrix
Infrastructure — KafkaKafka KRaft cluster setup
Infrastructure — CDCDebezium CDC pipeline configuration
Packages OverviewPer-package documentation

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.