1 of 33

Domain Events - cross-service

WE5.2.6 overview

2 of 33

Outline

  • How might cross-service Domain Events help WMF?
  • What are Domain Events?
  • What are cross-service events?
  • What did we accomplish and learn for WE5.2.6
  • Recommendations
  • Ask for leadership

3 of 33

How might this help us?

  • Encourage data capability building
  • Data backed product velocity
  • Data reusability
  • Reduce coupling

(the why)

4 of 33

MediaWiki data capabilities

  • WMF is prioritizing more projects that require data transformation capabilities that MediaWiki does not provide
  • There is a need to source and transform MediaWiki data outside of MediaWiki
  • There is a need to serve transformed data, usually through MediaWiki product features
  • Can events help? Often, yes!

5 of 33

Product Velocity

If event data is

  • Reusable
  • Broadcast
  • Receivable outside MediaWiki
  • Receivable inside MediaWiki

Then, product features can

  • Transform data outside of MediaWiki
  • Serve transformed data from MediaWiki
  • Use data for more than its original purpose

6 of 33

Data Reuse

Broadcast events improve data reusability across the whole of WMF (and beyond).

  • Broadcast once, receive in many places
  • Incentive for product teams to make and broadcast events for their own use, as well as for future uses.
  • Encourages data as a product thinking.

7 of 33

Decoupling

In-process events reduce coupling between MediaWiki components.

Cross-service events can reduce coupling between MediaWiki and other systems.

  1. Broadcasting event data so that other services can use data without MediaWiki’s database (via replicas).

2. Receiving event data so that MediaWiki can react to, store and serve data from other services, without polling those services at run time.

8 of 33

MediaWiki Domain Events

(the what)

9 of 33

Domain Events

register

register

dispatch

dispatch

event

listener

listener

In-process MediaWiki PHP emitters and receivers are decoupled.

Code responsible for saving edits is not aware of code responsible for saving RecentChanges, talk page notifications, ResourceLoader module cache, or other downstream product features.

Initial goal: to make MediaWiki and extension development more sustainable

10 of 33

Domain Events

  • Extensions developers should also design DomainEvents!
  • Encourages extension code to be more decoupled
  • Enables the reuse of event data outside of its original purpose

11 of 33

Cross-service

Integration Events

WE5.2.6

(the what)

12 of 33

Hypothesis WE5.2.6

If we explore designing an architecture for cross-service events, we can make MediaWiki data more reusable beyond the MediaWiki platform. *

FY2024-2025 Q3

This hypothesis aims to:

  • Investigate technical unknowns
  • Influence the architecture of the Domain Events systems
  • Influence the data modeling of MediaWiki core DomainEvents.
  • Recommend next steps

13 of 33

Hypothesis WE5.2.6

FY2024-2025 Q3

Outcome:

WE5.2.6 Broadcasting and receiving cross-service events discovery and design document

Detailed exploration and documentation of the technical questions around how to enable cross-service events in MediaWiki

14 of 33

Hypothesis WE5.2.6

FY2024-2025 Q3

15 of 33

(the what, part 2)

16 of 33

Cross-service scenarios

cross-service – scenarios in which an event is received in a different application or service than the emitter.

Each scenario has distinct technical implications.

17 of 33

Cross-service scenarios

  • same-wiki – A MediaWiki PHP listener is invoked within the same-wiki site as the emitter.
    • enwiki receives a PageUpdatedEvent that was emitted by enwiki in a different process (outside of the user request).

  • inter-wiki – A MediaWiki PHP listener is invoked with an event that was emitted by a different wiki site context.
    • enwiki receives an ImageUpdated event from commonswiki.
    • wikifunctions receives a WikiBaseEntityUpdated event from wikidatawiki
    • global user blocks*
    • global user renames*

  • off-wiki – A MediaWiki PHP listener is invoked with an event that was not emitted by MediaWiki.
    • enwiki receives a PageRevertRiskPredictionUpdated event from LiftWing or Data Lake
    • Enwiki receives an IpReputationUpdated event from an external service

18 of 33

Cross-service scenarios

  • beyond-wiki – MediaWiki emitting events for reception by non-MediaWiki processes
    • PageState events from all wikis
      • ingested into Hive tables in the WMF Data Lake.
      • consumed by Search Update Pipeline to trigger updates to ElasticSearch indexes
      • consumed by mediawiki-event-enrichment to create events that contain revision content, HTML content, wikidata entity content, etc. to generate ‘dumps’ of this data.
      • consumed by LiftWing to emit PageRevertRiskPredictionUpdated, or other page prediction events.
    • WikiBaseEntityUpdated
      • Consumed by WQDS Streaming Updater to update graph database
    • wiki state change events used to update and maintain a feature store for use by LiftWing model inference

  • beyond-wiki-public – events for reception by receivers out of WMF production

19 of 33

Goals

  • Investigate how broadcasting, serializing, and receiving events cross-service might be accomplished.
  • Explore commonalities between cross-service scenarios.
  • Propose implementation options that ideally consolidates systems and supports as many cross-service scenarios as possible.
  • Propose short term recommendations that provide the most value for WMF’s current and upcoming objectives

20 of 33

Learnings

  • Both Event Platform and WMF wide APIs share a similar problem:
    • We use MediaWiki to build WMF global platform features, but MediaWiki at WMF is ~1000 different websites. Which is canonical? Should we use MediaWiki to build global platform features?*
    • DPE and MW API should work closely to align efforts here.
  • There are many inter-wiki use cases, but the valuable ones require fine grained dependency tracking.
    • E.g. An enwiki page should be re-rendered because a dependency has changed.
    • Events on their own do not solve this problem, but they could help build a standard dependency tracking system.
  • Existent same-wiki and inter-wiki use cases are relatively well supported by JobQueue RPCs.
  • PII redaction is complicated and should not be part of the MediaWiki Domain Event System

21 of 33

Learnings

Which cross-service scenario support would most benefit WMF?

What capabilities are we lacking?

  • off-wiki:
    • MediaWiki currently has no standard mechanism to receive events (or any data) from non MediaWiki emitters
    • Supporting these scenarios have a potentially high impact at WMF, especially as more product features that need ‘generated’ or ‘derived’ data (outside of MediaWiki) are prioritized.

22 of 33

Learnings

Which cross-service scenarios do we already support, even if poorly?

  • same-wiki and inter-wiki
    • should be achievable with JobQueue Domain Event helpers (this does not improve data reusability)
  • beyond-wiki
    • is manually achievable with EventBus and Event Platform now. We should encourage and improve its use.
  • beyond-wiki public
    • is quite complicated to support. Out of scope for Domain Events work.

23 of 33

Recommendations - short term

Improve usability of off-wiki generated data in MediaWiki by enabling MediaWiki to receive events.

24 of 33

Recommendations - short term

Recommendation 1: event bus MediaWiki receiving

Implementing event bus (kafka) MediaWiki receiving would allow non MediaWiki emitters to emit data in a way that is decoupled from the MediaWiki usage of that data.

The emitted event data would be reusable for many use cases, including those inside of MediaWiki.

E.g. PageRevertRiskScore events could be emitted by LiftWing.

Those events could be consumed into the Data Lake, by Enterprise, or by MediaWiki for building products features like moderator tools.

Event bus MediaWiki receiving next steps

  • Determine feasibility of PHP MediaWiki Kafka Consumer
  • Continue exploring the event bus MediaWiki receiving implementation
  • Implement DomainEvent event bus interfaces and support, integrated with (static) EventStreamConfig.
  • Open question: If feasible, could MediaWiki Kafka support remove the need for change-propagation service?

25 of 33

Recommendations - short term

Recommendation 2: non MediaWiki job submission

Enable non MediaWiki processes to submit MediaWiki job events.

This solution would not improve data reusability, but is a fast path to enabling usage of generated data in MediaWiki

E.g. LiftWing, would have to emit multiple versions of PageRevertRiskScore event data, for Data Lake, Search and Enterprise, and also as a job into each wiki where the data should be pushed.

Non MediaWiki job submission next steps:

26 of 33

Recommendations - long term

Integrate DomainEvents with Event Platform to build MediaWiki event driven capabilities at WMF.

  • Implement support using an event bus
  • Serialization: via JsonCodec (TBD where to implement)
  • Broadcast-able DomainEvents should be WikiAware
  • Broadcasting: Option A. DomainEvent listener broadcasts events
  • Stream Segregation: Option A. Stream per event entity (at first)
  • Consuming events: Option B. PHP Kafka Consumer
  • Kafka consumer group granularity: Option C. Per wiki site
  • Retries & deduplication: Option A. JobQueue for retries
    • Unless we want to tackle replacing change-propagation and unify async callback execution via a PHP Kafka Consumer.
  • Listener registration and invocation: Support events by implementing event bus related DomainEvent interfaces.
  • Pluggable event bus consumer to support dev environments.
  • Integrate Domain Event with WMF Event Platform.
    • Schemas: Option B. MediaWiki schema registry
      • Keep close contact with MW REST API work for schema synergies and solutions.
    • Streams: Option A. Dynamic EventStreamConfig

27 of 33

Ask for leadership

Please consider, recognize and acknowledge the problem:

  • WMF is prioritizing more projects that require data transformation capabilities that MediaWiki does not provide
  • There is a need to source and transform MediaWiki data outside of MediaWiki
  • There is a need to serve transformed data, usually through MediaWiki product features

Please prioritize platform capability initiatives that address this problem holistically, whether it is via cross-process Domain Events, or something else.

Until we address this problem, we will either:

  • Not build novel things using MediaWiki data
  • Repeatedly expend resources building hacky and brittle data pipelines

28 of 33

Feedback please!

The discovery and design doc is long and detailed

How to engage with this document” section provides instructions and shortcuts for reviewers

For higher level review:

Please help us provide examples of how making it easier to share data between MediaWiki and non MediaWiki systems would help you build your products.

29 of 33

Feedback please!

  • AO: Feel free to add direct feedback here! Or as comments!

30 of 33

Appendix

Slides that didn’t make it into the main deck above, but might be useful to show.

31 of 33

Domain Events

function handlePageRevisionUpdatedEvent(

PageRevisionUpdatedEvent $event

) {

// (Invoked after the HTTP request is finished.)

// Do whatever you need to do with

// the fact the page that was updated

}

PHP interface example

32 of 33

Domain Events

class CampaignUserRegistrationEvent

implements DomainEvent {

// class that represents when a user registers

// for a Campaign event

}

PHP interface example

33 of 33

Domain Events

// In Campaigns extension handling user registration

$userRegistrationEvent = new CampaignUserRegistrationEvent( ... );

$eventDispatcher->dispatch( $userRegistrationEvent );

// Somewhere else… another extension?

function handleCampaignUserRegistrationEvent(

CampaignUserRegistrationEvent $event

) {

// Do whatever you need to do with

// the fact a user registered for a campaign

}

PHP interface example