Jump to content

Data Platform/Data Lake/Traffic/API requests

From Wikitech

The following tables contain enriched and pre-aggregated datasets of traffic to Wikimedia public APIs. The data is filtered from webrequest, keeps only logs related to API requests, and further enriched with additional columns of interest that are regularly used for API-related analyses and metrics. All of the data access is currently internal only, and can be queried if you have access to the Data Lake.

Datasets

Currently, we have the following datasets in this regard:

api_requests_refined

Table
wmf_traffic.api_requests_refined
Description
API requests filtered from webrequest, and enriched with additional columns of interest. This intermediate table is recommended to be used for analyses related to API traffic, as it is 10x smaller than webrequest. This not a pre-aggregated table, each row represents an individual API request.[1]
Table schema
DataHub
Generation code
Ownership
Technical: Data Platform Engineering
Data stewardship: Product Analytics

mrt_api_requests_hourly

Table
wmf_traffic.mrt_api_requests_hourly
Description
This table contains pre-aggregated metrics of API requests, built from api_requests_refined. It is aggregated to hourly granularity, over pre-defined set of dimensions for the three primary metrics of interest: number of requests, response size total (in bytes), and time to first byte total (in seconds). The data is produced and partitioned hourly. This table is equivalent to wmf.pageview_hourly.
Table schema
DataHub
Generation code
dbt-jobs: mrt_api_requests_hourly
Ownership
Product Analytics

mrt_ratelimit_class_daily

Table
wmf_traffic.mrt_ratelimit_class_daily
Description
This table contains pre-aggregated API requests, built from api_requests_refined, primarily keyed on ratelimit_class. While it is conceptually similar to mrt_api_requests_hourly, it is aggregated to daily granularity, with a much fewer set of dimensions, which significantly reduces the dataset size. It is suitable to be queried using Presto on Superset.
Table schema
DataHub
Generation code
dbt-jobs: mrt_api_requests_hourly
Ownership
Product Analytics

mediawiki_api_request

Table
event.mediawiki_api_request
Description
It is an event logging table, containing api.php request data. The benefit of these logs is that they include internal API requests not routed through the Varnish servers, and detailed data on the content of POST API requests. However, the data is limited to the Action API only and doesn't contain other metdata that is usually present in webrequest (bot scores, X-analytics etc.). In future, this maybe folded in webrequest, depending on the technical feasibility, or merged with api_requests_refined.
Please refer to mediawiki_api_request for the schema and additional details.

Usage notes

While wmf_traffic.api_requests_refined and wmf_traffic.mrt_api_requests_hourly are significantly downsized compared to webrequest, however they're still not small enough to be queried using Presto on Superset, especially not suitable for building any dashboards based on them. We're considering further pre-aggregation at daily granularity to address those needs. However, they are quite manageable and beneficial for relevant analyses when queried with Spark from stat machines.

The hourly and daily pre-aggregated datasets are usually better for analyses that slice and dice the primary metrics: request count, response size and time to first byte), with various dimensions such as API families, cache statuses, ratelimit class, compliance etc. Whereas api_requests_refined, where each row represents a specific request, is helpful for analysing behaviours of specific clients, request patterns, analysis on dimensions that are not pre-aggregated due to high cardinality etc.

Glossary

For the above datasets, the respective DataHub link provides the most up-to-date table information. Additionally, here are the details of dimensions that frequently appear across datasets related APIs (apart from ones directly passed down webrequest):

is_api_gateway_routed
Indicates whether a request has been routed through the Centralised API Gateway or not.
is_ats_bypass
Indicates whether an API Gateway routed request has an ATS (Apache Traffic Server) bypass, in which case regular ratelimits are not applied, and ratelimit_class is usually not determined (NULL in data).
api_family
A common label for a group of API endpoints, or in some cases also tracks a specific endpoint. The following families and endpoints are tracked:
user_agent_compliance
Compliance of the User-Agent with the WMF User-Agent policy. Possible values:
x_trusted_request
X-Trusted-Request
ratelimit_class
assigned API ratelimit class.
hap_known_client_action
if applicable, action taken for a known-client, derived from x_analytics_map.
hap_known_client_name
if applicable, name of a known-client, derived from x_analytics_map.

Sample queries

Top non-compliant User-Agents by requests to Action API

SELECT
    user_agent,
    COUNT(*) AS request_count
FROM wmf_traffic.api_requests_refined
WHERE hour >= TIMESTAMP '2026-08-01 00:00:00'
  AND hour < TIMESTAMP '2026-08-08 00:00:00'
  AND api_family = 'action'
  AND user_agent_compliance = 'non_compliant'
GROUP BY user_agent
ORDER BY request_count DESC
LIMIT 5;

Distinct IPs by ratelimit class

SELECT
    ratelimit_class,
    COUNT(DISTINCT ip) AS distinct_ip_count
FROM wmf_traffic.api_requests_refined
WHERE hour >= TIMESTAMP '2026-08-01 00:00:00'
  AND hour < TIMESTAMP '2026-08-08 00:00:00'
GROUP BY ratelimit_class
ORDER BY distinct_ip_count DESC;

Daily request count by API family

SELECT
    CAST(hour AS DATE) AS request_date,
    api_family,
    http_status,
    SUM(request_count) AS request_count
FROM wmf_traffic.mrt_api_requests_hourly
WHERE hour >= TIMESTAMP '2026-08-01 00:00:00'
  AND hour < TIMESTAMP '2026-08-08 00:00:00'
GROUP BY CAST(hour AS DATE), api_family, http_status;

Average response size by API family

SELECT
    hour,
    api_family,
    SUM(request_count) AS request_count,
    SUM(response_size_bytes_total) / SUM(request_count) AS avg_response_size_bytes
FROM wmf_traffic.mrt_api_requests_hourly
WHERE hour >= TIMESTAMP '2026-08-01 00:00:00'
  AND hour < TIMESTAMP '2026-08-08 00:00:00'
  AND http_status IN (200, 206)
GROUP BY hour, api_family;

Cache behaviour by API families

SELECT
    api_family,
    cache_status_normalized,
    SUM(request_count) AS request_count,
    SUM(response_size_bytes_total) AS response_size_bytes_total
FROM wmf_traffic.mrt_api_requests_hourly
WHERE hour >= TIMESTAMP '2026-08-01 00:00:00'
  AND hour < TIMESTAMP '2026-08-08 00:00:00'
  AND http_status IN (200, 206)
GROUP BY api_family, cache_status_normalized
ORDER BY api_family, request_count DESC;

Changes and known issues

please use this section to document any future changes and issues encountered when working with these datasets.

See also

  1. ↑ For range requests, HTTP-206, each response will have a different row in the table.