Skip to content

feat: Introduce MessageBus for Event Driven architecture#23839

Closed
hariombalhara wants to merge 2 commits intohariom/pri-305-bookingcreateservice-rename-handlers-to-servicesfrom
booking-refactor-event-bus
Closed

feat: Introduce MessageBus for Event Driven architecture#23839
hariombalhara wants to merge 2 commits intohariom/pri-305-bookingcreateservice-rename-handlers-to-servicesfrom
booking-refactor-event-bus

Conversation

@hariombalhara
Copy link
Member

@hariombalhara hariombalhara commented Sep 15, 2025

What does this PR do?

Introducing MessageBus

Note: The name is chosen to be MessageBus, and not EventBus, so that it is not confused with Cal.com Events.

Overview

Every feature in @calcom/features should define the actions it takes for a specific lifecycle event during a request. This ensures that the logic is organized, modular, and easily testable.

Example

For instance, the message messages/booking.created/handler defines what happens when a booking.created event occurs.

Extending MessageBus

For more complex request flows, developers can extend the MessageBus to define their own Buses and use those Buses.

Example:

A BookingMessageBus could define messages such as:

  • booking.created
  • booking.rescheduled
  • booking.requestRescheduled

Benefits

  • Cohesion: All actions related to a lifecycle event are grouped together.
  • Testability: Individual handlers can be tested in isolation.
  • Extensibility: Custom message buses can be easily created for specific workflows.

This approach streamlines event handling, reduces coupling, and makes the system more maintainable.

Visual Demo (For contributors especially)

A visual demonstration is strongly recommended, for both the original and new change (video / image - any one).

Video Demo (if applicable):

  • Show screen recordings of the issue or feature.
  • Demonstrate how to reproduce the issue, the behavior before and after the change.

Image Demo (if applicable):

  • Add side-by-side screenshots of the original and updated change.
  • Highlight any significant change(s).

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Are there environment variables that should be set?
  • What are the minimal test data to have?
  • What is expected (happy path) to have (input and output)?
  • Any other important info that could help to test that PR

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my changes generate no new warnings

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 15, 2025

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.

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

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch booking-refactor-event-bus

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions
Copy link
Contributor

github-actions bot commented Sep 15, 2025

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "event-bus". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@keithwillcode keithwillcode added core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO labels Sep 15, 2025
@hariombalhara hariombalhara force-pushed the hariom/pri-305-bookingcreateservice-phases-1-quick-enrichment-and-validation branch from 3c78374 to 82d6e28 Compare September 16, 2025 10:38
@hariombalhara hariombalhara force-pushed the booking-refactor-event-bus branch from 2f4cec7 to 87db55a Compare September 16, 2025 10:38
@vercel
Copy link

vercel bot commented Sep 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Sep 23, 2025 0:31am
cal-eu Ignored Ignored Sep 23, 2025 0:31am

@hariombalhara hariombalhara changed the title event-bus feat: Introduce MessageBus for Event Driven architecture Sep 16, 2025
@hariombalhara hariombalhara force-pushed the booking-refactor-event-bus branch from 87db55a to 378690d Compare September 16, 2025 11:11
@hariombalhara hariombalhara force-pushed the hariom/pri-305-bookingcreateservice-phases-1-quick-enrichment-and-validation branch from 82d6e28 to 033ea95 Compare September 16, 2025 11:11
@hariombalhara hariombalhara force-pushed the booking-refactor-event-bus branch from 378690d to 45e2c23 Compare September 16, 2025 12:01
@hariombalhara hariombalhara force-pushed the hariom/pri-305-bookingcreateservice-phases-1-quick-enrichment-and-validation branch from 033ea95 to 90e3547 Compare September 17, 2025 09:55
@hariombalhara hariombalhara force-pushed the booking-refactor-event-bus branch from 45e2c23 to 08b5162 Compare September 17, 2025 09:55
@volnei
Copy link
Contributor

volnei commented Sep 17, 2025

hey @hariombalhara, I have some points of improvement that I'd love to us to take in account. This is not regarding the implementation, which is good, but more related to resilience and performance.

I really value the event mechanism and I think we should go forward with it, but maybe we should rethink it to get all benefits.

What's not that good:

  1. Resilience:
    1.1. retries - I can't see any retry mechanism which make this implementation weak and not trustable as it should be;
    1.2. idempotency - Also important to have some control to avoid duplicated events being fired;
    1.3. backup - if the server restarted or process goes down the events are gone 💥
  2. Fault tolerance:
    2.1. As it is implemented if we have a defect handler it will break all subsequent, it should isolate the exceptions;
  3. Tests
    3.1. No tests implemented, but it's okay since it's in draft yet;
  4. Implementation
    4.1. BookingMessageBus should be a singleton (DI)

What I think is better for this case:

  • If the objective is something really weak (what I don't agree) the Node Events API is good enough, seems that we're reimplementing it;
  • If the objective is that to be a definitive guide I would recommend to implement it using Redis pub/sub or Redis Streams (even better) that will address the main resilience points.

cc @keithwillcode

@hariombalhara hariombalhara force-pushed the booking-refactor-event-bus branch from 08b5162 to b16024a Compare September 22, 2025 09:50
@hariombalhara hariombalhara force-pushed the hariom/pri-305-bookingcreateservice-phases-1-quick-enrichment-and-validation branch from 90e3547 to dee6f2d Compare September 22, 2025 09:50
@hariombalhara hariombalhara force-pushed the hariom/pri-305-bookingcreateservice-phases-1-quick-enrichment-and-validation branch from dee6f2d to 155ad02 Compare September 22, 2025 13:09
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A handler for trigger.dev would be defined here.

import type { Logger } from "tslog";

import { safeStringify } from "@calcom/lib/safeStringify";
import { HashedLinkService } from "@calcom/lib/server/service/hashedLinkService";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This service should probably move to the privateLink feature also.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah certainly.But I didn't want to do any other refactor as part of this PR.

@hariombalhara hariombalhara force-pushed the hariom/pri-305-bookingcreateservice-phases-1-quick-enrichment-and-validation branch from 155ad02 to e0ce121 Compare September 22, 2025 14:04
@hariombalhara hariombalhara force-pushed the booking-refactor-event-bus branch from 02c537d to 998d322 Compare September 22, 2025 14:04
@hariombalhara hariombalhara changed the base branch from hariom/pri-305-bookingcreateservice-phases-1-quick-enrichment-and-validation to graphite-base/23839 September 23, 2025 09:20
@hariombalhara hariombalhara force-pushed the booking-refactor-event-bus branch from 998d322 to 6b969e7 Compare September 23, 2025 12:31
@hariombalhara hariombalhara changed the base branch from graphite-base/23839 to hariom/pri-305-bookingcreateservice-rename-handlers-to-services September 23, 2025 12:31
@hariombalhara hariombalhara force-pushed the booking-refactor-event-bus branch from 6b969e7 to b15618e Compare September 23, 2025 13:39
@hariombalhara hariombalhara mentioned this pull request Sep 23, 2025
3 tasks
- Add react-awesome-query-builder and clone to serverExternalPackages
- Fixes module resolution errors in booking flow caused by client-side
  dependencies being bundled server-side through import chain:
  RegularBookingService → getRoutedUsers → findTeamMembersMatchingAttributeLogic

Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
@hariombalhara
Copy link
Member Author

Closing it as per internal discussion. We don'tt want to pursue it further for now, will be re-evaluated if we really need it.

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

Labels

core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants