Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: [FC-0074] explain how the event bus works and how to use it #426

Merged
merged 12 commits into from
Dec 11, 2024

Conversation

mariajgrimaldi
Copy link
Member

@mariajgrimaldi mariajgrimaldi commented Nov 29, 2024

Description

This PR adds sections dedicated to the Open edX Event bus technology:

  1. An Overview of the technology:
    What is the Open edX Event Bus?
    Why use the Open edX Event Bus?
    How Does the Open edX Event Bus Work? With an architectural diagram.
    How is the Open edX Event Bus Used?

  2. Using the Open edX Event Bus: install event-bus plugins, configure them, produce events, consume events, run the consumer

  3. Event Bus Configurations: the available configurations taken from in-line code annotations.

  4. Glossary terms for the event-bus: event bus, message, message broker, worker, producer, consumer, topic

These docs were written based on the available documentation about the Open edX Event Bus:
https://openedx.atlassian.net/wiki/spaces/AC/pages/3508699151/How+to+start+using+the+Event+Bus
https://openedx.atlassian.net/wiki/spaces/AC/pages/3474784257/Event+Bus+Architecture+Overview

This PR partially addresses #238

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 29, 2024
@openedx-webhooks
Copy link

openedx-webhooks commented Nov 29, 2024

Thanks for the pull request, @mariajgrimaldi!

What's next?

Please work through the following steps to get your changes ready for engineering review:

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/hooks-extension-framework. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@mariajgrimaldi mariajgrimaldi changed the title docs: explain how the event bus works and how to use it docs: [FC-0074] explain how the event bus works and how to use it Nov 29, 2024
@mariajgrimaldi mariajgrimaldi added the FC Relates to an Axim Funded Contribution project label Nov 29, 2024
@@ -1,42 +0,0 @@
Using the Open edX Event bus
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we should add a redirect here?

@mariajgrimaldi mariajgrimaldi marked this pull request as ready for review December 2, 2024 14:07
@mariajgrimaldi mariajgrimaldi requested a review from a team as a code owner December 2, 2024 14:07
@mariajgrimaldi mariajgrimaldi marked this pull request as draft December 2, 2024 14:08
@mariajgrimaldi mariajgrimaldi marked this pull request as ready for review December 2, 2024 16:16
@sarina
Copy link
Contributor

sarina commented Dec 2, 2024

Should these docs live here? Or on docs.openedx.org? (I don't know the right answer just asking)

@mariajgrimaldi
Copy link
Member Author

Hey @sarina, not sure either. A similar question was raised here #279, what do you think about the alternatives?

* **Eliminate Expensive, Delayed, Batch Synchronization**: replace expensive batch processing with near real-time data updates.
* **Reduce the need for Plugins**: reduce the computational load for plugins that don't need to run in the same process by allowing cross-service communication of lifecycle events.

How Does the Open edX Event Bus Work?
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we also include more detail on how the data is serialized/deserialized? Or is this a good high-level overview?

Either way, I'm writing some documents on adding event bus support to new events so that the serialization/deserialization details can be included there.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is good for a high level overview. I think it would be nice to put something in here about the differences between the Event Bus and Celery tasks, and when to use each. It's one of the more common questions I get.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! I'm going to add a comparison table or something similar about them. Thank you for the suggestion!

Copy link
Member Author

Choose a reason for hiding this comment

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

I compared the event bus async communication style with async tasks here: fb51a60. Let me know if this is what you had in mind. Thanks!

Copy link
Contributor

@bmtcril bmtcril left a comment

Choose a reason for hiding this comment

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

Just a couple of comments, this is looking great!

Install the Open edX Event Bus Plugin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

First, you need to install the Open edX Event Bus plugin in both the producing and consuming services. The plugin is a Django app that provides the necessary tools and configurations to produce and consume events. You could install the Redis plugin by running:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a note here about things that go into selecting a backend and why we're using redis here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I added a note about redis being the community supported solution here: 0d3218a

@sarina
Copy link
Contributor

sarina commented Dec 3, 2024

@mariajgrimaldi the more I think about it the more I think leaving the docs here is good!

@bmtcril said he'd take a look at these docs for me, since he's more familiar with the event bus.

docs/how-tos/using-the-event-bus.rst Outdated Show resolved Hide resolved
docs/reference/glossary.rst Show resolved Hide resolved
@@ -0,0 +1,84 @@
Using the Open edX Event Bus
Copy link
Member Author

Choose a reason for hiding this comment

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

@bmtcril: I also created a document on how to ensure event bus compatibility for new events, what do you think about merging these two docs into one?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think they are probably good as they are, don't want to make them too long!

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call!


- Service A sends the event as a message to the event bus and continues its execution, as we previously explained.
- Service B polls the message broker for new messages and processes them.
- Service B re-emits the event with the data that was transmitted.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think re-emits is a little confusing here, I initially read it as "re-emits the event to the bus". Maybe change it to "locally emits the Django signal of the event..."?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I improved the wording here: 12e4768


This is an example of an asynchronous approach (from the producer point of view) to send messages to another services but with a blocking nature.

Use the Open edX Event bus instead of asynchronous tasks when:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is great! A thing we don't talk about often, and I'm not sure we should, is that the event bus (especially Kafka) can be used to send event data out of the Open edX ecosystem entirely. Many different databases and products can consume Kafka events for various purposes, for instance Student Information Services or Contact Relationship Managers may listen to enrollment events to update their own state. Do you think it's worth a bullet point here about that?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a pretty interesting use case we could include here: https://docs.openedx.org/projects/openedx-events/en/latest/reference/real-life-use-cases.html#cross-services-communication. I think it'd give community folks a more rounded view of all that can be done with the event bus, do you have more info on this use case? Although I could use the info in the comment.

For this document purpose, I added some high-level ideas of external services that can consume events sent through the event bus: ee3f8e5


First, you need to install the Open edX Event Bus plugin in both the producing and consuming services. The plugin is a Django app that provides the necessary tools and configurations to produce and consume events. You could install the Redis plugin by running:

.. code-block:: bash

pip install edx-event-bus-redis

Configure the Event Bus
~~~~~~~~~~~~~~~~~~~~~~~
.. note:: Redis is the community-supported plugin for the Open edX Event Bus and is the recommended plugin to use. You can find more information about the Redis plugin in the `event-bus-redis`_ repository. However, you can also implement your own plugin with your preferred message broker by following the :doc:`../how-tos/add-new-event-bus-concrete-implementation` documentation.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that both redis and kafka are community supported, but redis is just the default. We should mention Kafka as an alternative before doing another implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for clarifying, I actually thought it was only Redis. I've changed the note with the suggestion: 1a4bafa

Copy link
Contributor

@bmtcril bmtcril left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@mariajgrimaldi
Copy link
Member Author

@bmtcril, thank you so much for the thorough review!

@sarina: I'm going to go ahead and merge this since Brian already approved it. Let me know if there's another suggestion you'd like me to include!

@@ -0,0 +1,87 @@
Using the Open edX Event Bus
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to add more details about this, like console logs, etc, in another PR. Thanks!

@mariajgrimaldi mariajgrimaldi merged commit b681ebd into main Dec 11, 2024
8 checks passed
@mariajgrimaldi mariajgrimaldi deleted the MJG/event-bus-concepts branch December 11, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants