Skip to content

docs: add ADR for a transactional outbox in the data sinks - #288

Open
andrey-canon wants to merge 3 commits into
openedx:mainfrom
eduNEXT:and/outbox-adr
Open

andrey-canon wants to merge 3 commits into
openedx:mainfrom
eduNEXT:and/outbox-adr

Conversation

@andrey-canon

Copy link
Copy Markdown

Description

Adds ADR 0002, which proposes a transactional outbox for the data sinks.

Today every change to a record that Aspects copies to ClickHouse queues its own Celery task. That means one insert per change, work on the platform's shared workers, and changes that are lost when a task fails or is stopped. The ADR proposes that the signal receivers write a small row into an outbox table in the same transaction as the change, and that a management command sends the outbox to ClickHouse in batches.

The ADR covers:

  • the outbox table;
  • the rows each receiver writes;
  • the per-sink switch to the outbox;
  • how sending works, including the special handling for courses, pathway deletions and user retirement;
  • failure handling;
  • the drain_outbox_to_clickhouse command and how to schedule it in Tutor;
  • the Django admin;
  • consequences and rejected alternatives (CDC tools, scheduled queries, improving the Celery tasks, storing serialized rows in MySQL).

A proof of concept for the course enrollment data sink was built to validate the approach; it is not part of this PR.

Testing instructions

Documentation only. Build the docs (make docs) and read docs/decisions/0002-transactional-outbox-for-data-sinks.rst.

Merge checklist:
Check off if complete or not applicable:

  • Commit messages (and PR title, if squash merging) use the correct
    Conventional Commits type — they determine the
    release: fix: → patch, feat: → minor, ! / BREAKING CHANGE: → major
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated (not applicable)
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

🤖 Generated with Claude Code

andrey-canon and others added 2 commits December 3, 2026 12:11
Propose replacing the per-change Celery tasks of every data sink with an
outbox table written in the same transaction as the platform change and a
management command that sends it to ClickHouse in batches, run periodically by
the infrastructure. Record the per-sink rules (courses, pathway deletions,
user retirement), the failure handling, the admin, the rollout setting and the
rejected alternatives.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Turning off the learner profile and external identifier sinks stops their
outbox rows; the outbox only stores ids. Profile and external id rows sent
outside the retirement order are deleted without being sent when the user
is already retired.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Dec 3, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @andrey-canon!

This repository is currently maintained by @openedx/committers-analytics.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are 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.

Details
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.

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

Coverage report

This PR does not seem to contain any modification to coverable code.

@andrey-canon
andrey-canon requested a review from bmtcril December 3, 2026 17:29
@andrey-canon

Copy link
Copy Markdown
Author

@bmtcril the changes tested while writing this ADR are in this branch: https://github.com/eduNEXT/platform-plugin-aspects/tree/and/poc-enrollment-outbox

It is a proof of concept for the course enrollment data sink only. It is not meant to be merged.

What it includes

  • The SinkOutbox model and its migration.
  • The course enrollment receiver writing to the outbox instead of queuing a Celery task.
  • The drain_outbox_to_clickhouse command.
  • The failure handling.
  • A read-only Django admin with the actions Send now, Activate and Deactivate.

Nothing sends the outbox automatically in this branch. Running the command periodically belongs to the infrastructure and would come from tutor-contrib-aspects. To send the outbox while testing, run the command or use the Send now admin action.

How to test it

  1. Install the branch in the LMS and run the migration:

    ./manage.py lms migrate platform_plugin_aspects
    
  2. In the LMS settings, with the course enrollment sink enabled as usual, turn on the outbox:

    EVENT_SINK_CLICKHOUSE_COURSE_ENROLLMENT_OUTBOX = True
    
  3. Enroll or unenroll a learner. A row appears in the outbox at /admin/platform_plugin_aspects/sinkoutbox/ in the LMS, and no Celery task is queued.

  4. Send the outbox in one of two ways:

    • Run the command:
      ./manage.py lms drain_outbox_to_clickhouse
      
      Optional: --batch_size (default 1000) and --sink.
    • In the admin, select the rows and run Send now. It queues one Celery task with the selected rows, so it needs a running Celery worker.

    The enrollments reach course_enrollment in ClickHouse, and the sent rows are deleted from the outbox.

  5. With ClickHouse stopped, send again. The rows stay in the outbox with their attempts and last error, and the command exits with an error.

Describe the savepoint around the outbox insert, how course publishes and
user retirements are backed by MySQL, where serialization runs and what it
locks, the database consequences (high-churn table, primary database, read
bursts) and the admin's Send now overlapping the command. Replace the list
of unrelated existing problems with the scope of the decision, and lead
the CDC rejection with the data it cannot produce.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

2 participants