Page MenuHomePhabricator

[SPIKE] Review of REST framework cacheing and how it applies to Attribution API needs
Closed, ResolvedPublic3 Estimated Story Points

Description

Description

A primary reason for creating a single REST endpoint for retrieving attribution information is that we know this API will be hit hard, and REST endpoints are cacheable. We believe that returning cached responses for all callers will reduce the overall infrastructure impact of introducing this endpoint and recommending attribution signals to key partners and community tools.

Conditions of acceptance

  • Determine how much caching support works out of the box for MediaWiki cache control
  • Investigate/implement cache purging, particularly for "out of the box" REST caching within MediaWiki
  • Make a recommendation for implementing a memcache vs longer-lived REST cache
  • Determine if/how the cache can continue being hit, even if the caller is logged in (which normally circumvents the cache for most API requests)
  • Audit data refresh rates and current performance consideration to understand how long data should be cached
NOTE: This work may be affected by learnings from T419467: [SPIKE] Attribution API MVP performance & latency investigation

Event Timeline

HCoplin-WMF set the point value for this task to 5.Mar 10 2026, 3:38 PM

Estimation notes:

  • Check the layers of cacheing; we are getting some data that is already cached, such as from parser & object caches
  • Timebox this work -- if there is massive complexity/blackholes, then take a step back and check with team to reassess needs.
  • Expected output of this investigation includes notes on this ticket; depending on the learnings, we can have a separate follow up task for creating a technical design document for how we might implement this for the Attribution API.
HCoplin-WMF changed the point value for this task from 5 to 3.Mar 10 2026, 3:42 PM

How much caching support works out of the box for MediaWiki cache control

Within Core, without extra infrastructure we get:

  • Http Caching
    • Core supports Cache-Control headers for REST responses from the Base Handler with the key headers being Cache-Control, Etag and Last Modifiesd: See ConditionalHeaderUtil. As already mentioned in the ticket description logged in users bypass this CDN caching as responses are marked private and no-cache

Conclusion: Out-of-the-box caching exists but must be explicitly enabled and tuned for each endpoint. And only anonymous requests are reliably cached at the edge.

Cache purging
Core supports purge events via action=purge when a page is edited or when related content changes. CDN layers like Varnish can be purged via http PURGE requests and cache tags if configured.

Options for REST cache purging
Manual purge hooks
Use page content change hooks like PaseSaveComplete, RevisionRecordInserted to trigger internal cache validation and cdn purge via HTTP PURGE
CDN-level purge
Send explicit purge requests.
Conclusion: For the attribution dependent on page content, reuse existing purge triggers and existing purge workflows. For the CDN layer combine event-driven purge(where possible) with TTL fallback for safety

Memcache v/s long lived REST cache
Memcache is fast and good for expensive computations and backend aggregation. However it is not shared across clients and doesn't reduce traffic to application layer. CDN level caching on the other hand reduces traffic that hits servers and is ideal for high traffic endpoints but requires careful headers and cache invalidation strategies.
Conclusion on what to go with: Use both
CDN to handle majority of traffic and memcache for expensive backend computations with a TTL longer than CDN. This combines low latency, reduced backend load and high scalability

Caching for logged in users
Logged in users usually include cookies, and trigger Cache-Control private or no-cache and bypass CDN. Options to have them cacheabe are:
Make endpoint explicitly public
Mark response as Cache-Control: public with Vary: Accept-encoding avoiding Vary: Cookie and Session-dependent logic
Strip cookies at CDN layer
Configure endpoint to ignore authentication if data is public
Separate endpoint
Have 2 separate endpoints the public cacheable one and the user authenticated one

Data refresh rates and TTL Strategy.
Balance between freshness and cache efficiency, aligning cache TTL with how often attribution change. Is stale data a legal threat.
Rarey changes: 1- 24hours
Moderate 5-15 minutes
High 1-5 minutes
Conclusion: Start with CDN and memcache, measure cache hit rate then adjust based on traffic load and data freshness/staleness

Closing out MW-Interfaces-Team (MWI-Sprint-29 (2026-03-10 to 2026-03-24)); marking everything from that sprint as resolved.

https://phabricator.wikimedia.org/project/board/8573/