Skip to content

feat(dx): support multiple domain event handlers via pg-boss pub/sub - #3475

Draft
stalniy wants to merge 1 commit into
mainfrom
feat/api-multiple-domain-event-handlers
Draft

feat(dx): support multiple domain event handlers via pg-boss pub/sub#3475
stalniy wants to merge 1 commit into
mainfrom
feat/api-multiple-domain-event-handlers

Conversation

@stalniy

@stalniy stalniy commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Why

Closes #1846

What

Domain events previously mapped 1:1 to a single queue and handler, so an event could not be consumed by more than one handler. Switch domain event delivery to pg-boss publish/subscribe: each handler owns its own queue and subscribes to the event, so handlers fail, retry, and restart in isolation and can be made idempotent independently.

  • Add JobQueueService.publish() (pgBoss.publish) and registerEventHandlers() which creates a per-handler queue and subscribes it to the event
  • Add EventHandler interface with an optional queue suffix; the queue defaults to the event name to preserve in-flight jobs on rollout
  • Route DomainEventsService.publish through the new publish path
  • Migrate existing event handlers to EventHandler and split job registration into commands (send) vs events (publish/subscribe)

Domain events previously mapped 1:1 to a single queue and handler, so an
event could not be consumed by more than one handler. Switch domain event
delivery to pg-boss publish/subscribe: each handler owns its own queue and
subscribes to the event, so handlers fail, retry, and restart in isolation
and can be made idempotent independently.

- Add JobQueueService.publish() (pgBoss.publish) and registerEventHandlers()
  which creates a per-handler queue and subscribes it to the event
- Add EventHandler interface with an optional queue suffix; the queue
  defaults to the event name to preserve in-flight jobs on rollout
- Route DomainEventsService.publish through the new publish path
- Migrate existing event handlers to EventHandler and split job registration
  into commands (send) vs events (publish/subscribe)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c881e431-e8ca-406b-a0da-724d8e8440dc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/api-multiple-domain-event-handlers

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 71.79%. Comparing base (0cd230d) to head (43d21f2).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
apps/api/src/app/providers/jobs.provider.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3475      +/-   ##
==========================================
- Coverage   72.87%   71.79%   -1.08%     
==========================================
  Files        1133     1043      -90     
  Lines       29484    27148    -2336     
  Branches     7389     6929     -460     
==========================================
- Hits        21487    19492    -1995     
+ Misses       7042     6731     -311     
+ Partials      955      925      -30     
Flag Coverage Δ *Carryforward flag
api 85.85% <96.55%> (+0.03%) ⬆️
deploy-web 62.34% <ø> (ø) Carriedforward from 0cd230d
log-collector ?
notifications 91.44% <ø> (ø) Carriedforward from 0cd230d
provider-console 81.38% <ø> (ø) Carriedforward from 0cd230d
provider-inventory ?
provider-proxy 86.42% <ø> (ø) Carriedforward from 0cd230d
tx-signer ?

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...eployment-alert/enable-deployment-alert.handler.ts 100.00% <100.00%> (ø)
...us-granted/first-purchase-bonus-granted.handler.ts 100.00% <100.00%> (ø)
...-created/trial-deployment-lease-created.handler.ts 100.00% <100.00%> (ø)
...pp/services/trial-started/trial-started.handler.ts 100.00% <100.00%> (ø)
...re/services/domain-events/domain-events.service.ts 100.00% <100.00%> (ø)
...i/src/core/services/job-queue/job-queue.service.ts 93.85% <100.00%> (+0.93%) ⬆️
apps/api/src/app/providers/jobs.provider.ts 0.00% <0.00%> (ø)

... and 91 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support multiple handlers for single domain event

1 participant