Proposal
Serve article feature counts for the Attribution API (IR2.1.2d).
- T432604: IR2.1.2d: Feature count data product [Attribution API]
- What are Article Feature?
- Architecture and Design Document
- SCROLL: T436563: New Scroll Request for: ArticleFeatureCounts (ArticleFeatureCounts)
- Asana
The attribution API requires reference and citation counts. We propose a more generic solution to develop a data product that outputs all available article features in mwparserfromhtml.
This ticket is to approve design and provision storage for article feature counts per page revision — the reference/citation count signal of the Attribution API — as a new cached artifact in the Linked Artifact Cache (LAC / hoarde), keyspace linked_artifacts on the RESTBase Cassandra cluster.
A new lambda service (ArticleFeatureCounts) fetches the HTML of a page revision from the MediaWiki REST API and computes absolute article feature counts with mwparserfromhtml (Research). LAC stores the lambda's output verbatim and serves it. On every page change, a MediaWiki JobQueue job warms the cache for the new revision, so reads are normally cache hits. The Attribution API reads the artifact from LAC and exposes reference_count in the trust_and_relevance object.
┌─────────────────────────────────────────────────────────────────────────────┐
│ UPSTREAM (canonical source) │
│ MediaWiki: page HTML for (wiki_id, page_id, revision_id) │
│ PageLatestRevisionChangedEvent → mw.job.FeatureCountsUpdate (JobQueue) │
│ Side output: feature-counts event stream → Data Lake (historical analysis)│
└─────────────────────────────────────────────────────────────────────────────┘
│ GET, Cache-control: no-cache (warm)
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ SERVE + STORE (SRE Data Persistence) │
│ Linked Artifact Cache (hoarde, `linked-artifacts`) │
│ GET /revisions/v1/page_feature_counts/{wiki_id}/{page_id}[/{revision_id}]│
│ Cassandra: linked_artifacts.page_feature_counts (RESTBase cluster) │
│ │ cache miss (gRPC) │
│ ▼ │
│ ArticleFeatureCounts lambda → MW REST HTML → mwparserfromhtml → counts │
└─────────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ MediaWiki Attribution API → clients (Wikimedia Enterprise, community │
│ tools, reusers). │
└─────────────────────────────────────────────────────────────────────────────┘Terminology
| Term | Meaning |
|---|---|
| Attribution API | MediaWiki REST module that returns attribution-related page metadata. |
| Citation | An inline [1]-style marker linking a statement to a source (typeof mw:Extension/ref in HTML). Not unique — the same reference can be cited many times. |
| Reference | A unique citation — an entry in the References list ({{Reflist}}, li#cite_note-* in HTML). Reference groups (e.g. Notes) count as references. |
| Source | A unique reference target (one book, one website domain). Not yet computable — mwparserfromhtml does not produce it; Research work is needed. Out of scope for launch. |
| Feature counts | Absolute counts of page features in a revision rendering: references, citations, wikilinks, sections, media, infoboxes, etc. |
| LAC | Linked Artifact Cache, the linked-artifacts service (hoarde), owned by SRE Data Persistence. Durable storage with caching semantics for derived data linked to MediaWiki entities. |
| Lambda | The service LAC calls on a cache miss to compute the artifact. |
| Cache warm | A GET to LAC with Cache-control: no-cache, which forces the lambda to run and the result to be stored. |
| mwparserfromhtml | Research library that extracts page features from MediaWiki HTML. |
Data model
LAC's table shape is fixed by hoarde — one table per artifact namespace, all with the same columns (schema.cql):
| Column | Type | Description |
|---|---|---|
| wiki | TEXT | Wiki database code (e.g. enwiki); partition key component |
| page | BIGINT | MediaWiki page_id; partition key component |
| revision | BIGINT | MediaWiki rev_id; clustering key, DESC |
| content | BLOB | The lambda's output, stored verbatim (JSON, see below) |
| last_modified | TIMESTAMP | When the artifact was computed and stored |
| metadata | MAP<TEXT,TEXT> | Content type, and the computing software's name/version and language |
Artifact content (JSON in content):
{
"software_info": {"name": "mwparserfromhtml", "version": "1.x.y", "algorithm": "WikiStew?"},
"language": "en",
"counts": {
"reference": 187,
"citation": 243,
"external_link": 64,
"wikilink": 512,
"section": 14,
"heading": 13,
"category": 22,
"media_img": 9,
"infobox": 1,
...
}
}mwparserfromhtml's WikiStew currently exposes ~21 feature types.
Access pattern
- Reads (cache hit): single-partition Cassandra point read with WHERE wiki = ? AND page = ? AND revision = ?. Served over HTTP by LAC — GET /revisions/v1/page_feature_counts/{wiki_id}/{page_id}[/{revision_id}].
- Reads (cache miss): LAC calls the lambda, stores the result, and returns it. The Attribution API does not want to block on this — see T435557: Handling Flagged Revs for Reference Counts in Attribution API and T433607: Provide a way to query the LAC without triggering a compute job on a cache miss (return null or use Cache-control: only-if-cached, and let the warm happen asynchronously).
- Writes: one write path only, from LAC itself. Each store is INSERT (wiki, page, revision, …) plus a range delete of revision < ?, so a partition normally holds a single row — the newest revision computed.
- Cardinality: one partition per (wiki, page); ~1 row per partition. May hold more than one revision ocasionally due to flagged_revs accessing older stable revision.
- Rate of change: one write per in-scope page change (cache warm), plus one write per cache miss.
Data Size
Row size, storing all ~21 feature counts (uncompressed, before Cassandra overhead):
| Column | Estimated size | Explanation |
|---|---|---|
| wiki | ~8 bytes | Most wiki IDs are ≤10 chars |
| page | 8 bytes | 64-bit integer |
| revision | 8 bytes | 64-bit integer |
| last_modified | 8 bytes | Timestamp |
| metadata | ~60 bytes | Lambda-controlled; content type, and optionally software version |
| content | ~425 bytes | Compact JSON of all 21 counts: counts block ≈ 323 B + software_info and language ≈ 102 B |
| Total per row | ~520 bytes | |
The content figure is the serialised byte length of the JSON document shown above, with all 21 WikiStew feature keys present. The 21 keys average 7.9 characters, so a "key":value, entry costs ~15 bytes (13 B with single-digit counts, 17 B with five-digit ones) — the count magnitudes barely matter. Pretty-printing with spaces adds ~50 B; the numbers here assume compact JSON.
Volume by rollout scope (one row per page):
| Scope | Pages | ~520 B/row (all features) |
|---|---|---|
| enwiki, main namespace | ~7M | ~3.6 GB |
| All Wikipedias, main namespace | ~65M | ~34 GB |
| All wikis, all namespaces (not in scope) | ~690M | ~357 GB |
Growth
Growth is bounded by new-page creation, since existing pages reuse their partition. The all-wiki, all-namespace measurement in T427442: [Data Persistence Design Review] Editor count per page (Attribution API) is +4.4M to +6.3M new (wiki, page) pairs per month, which is an upper bound for the Wikipedia main-namespace subset here. Edits to existing pages do not add partitions; they replace the row (and leave a range tombstone).
Performance
| Metric | Target |
|---|---|
| P50 read latency (cache hit) | TBD |
| P95 read latency (cache hit) | TBD |
| P99 read latency (cache hit) | TBD |
| Read throughput (steady state) | TBD |
| Read throughput (peak) | TBD |
| Write throughput | TBD — one write per in-scope page change, plus cache misses |
What we know:
- Latency budget: the whole Attribution API round trip must be ≤ 400 ms. The reference count is one field inside that, so a cache hit must be comfortably inside it.
- Read shape: Read volume upper bound roughly tracks the edit rate, concentrated on recently edited and popular pages. Community tools and other reusers add a long tail.
- Cache miss cost: an HTML fetch plus a parse — hundreds of milliseconds or more, which does not fit the 400 ms budget. This is why every edit warms the cache, and why misses must be handled without blocking (T435557: Handling Flagged Revs for Reference Counts in Attribution API, T433607: Provide a way to query the LAC without triggering a compute job on a cache miss).
- Staleness tolerance: requirements allow counts up to 24 hours stale, and warming makes them near-real-time in practice.
- Write shape: steady rather than bursty, one write per in-scope page change.
Retention and expiration
- Only the ~current revision's counts are needed. Older revisions are range-deleted on each store, and are recomputable on demand.
- No fixed expiration date — this is an ongoing product signal tied to the Attribution API lifecycle.
Dependencies
- Upstream: MediaWiki REST API (HTML), MediaWiki JobQueue + PageLatestRevisionChangedEvent (warming), mwparserfromhtml (Research).
- Downstream: MediaWiki Attribution API → Wikimedia Enterprise, community tools and reusers.
- Degradation: if LAC or the lambda is unavailable, the Attribution API omits the field or returns null; Enterprise has a fallback path (counting citation identifiers themselves).
Decision brief
We will store the artifact in Cassandra on the RESTBase cluster, in the existing linked_artifacts keyspace used by LAC, and serve it through LAC's HTTP API (no Data Gateway). The table follows hoarde's fixed artifact schema:
CREATE TABLE linked_artifacts.page_feature_counts ( wiki text, page bigint, revision bigint, content blob, last_modified timestamp, metadata map<text,text>, PRIMARY KEY((wiki, page), revision) ) WITH CLUSTERING ORDER BY (revision DESC);
Plus the corresponding grants for the linked_artifacts role (puppet/modules/cassandra/templates/users/linked_artifacts.cql.erb) and a hoarde.tables entry in helmfile.d/services/linked-artifacts/values.yaml pointing at the lambda — staging first.