Jump to content

Duck

From Wikitech
Duck
A giant rubber duck
Lifecycle state Active WMF Development (in production)
SCROLL SCROLL: Duck
Type Service
Development Owner Wikifauna team
Config & Deployment Owner Wikifauna team
Incident Response Owner Wikifauna team
Product Management Owner Wikifauna team
Contact #wikimedia-wikifauna (IRC), #wikifauna (Slack)
Phabricator #wikifauna, #duck-service
Service catalogue Service catalogue entry
Repository gitlab.wikimedia.org/repos/wikifauna/duck
Discovery URL duck.discovery.wmnet
Health dashboard Duck (Grafana)
Runbook Runbook

Duck

Duck is an HTTP service that serves duck fun facts to readers and editors through the /duck.php endpoint. It is reached through the CDN and gives wiki pages a lighthearted duck fact on demand. It is owned by the Wikifauna team.

Overview

Duck serves duck fun facts as a standalone service, kept out of MediaWiki so it can be scaled and operated independently.

  • Read-heavy: the vast majority of requests are GETs for a fun fact, served from cache where possible.
  • Fresh facts come from a third-party API (ducklings.org) and are cached, so most requests never leave the cluster.
  • Not on the critical path: /duck.php is a leaf endpoint, so if Duck is slow or unavailable a page still renders, wikis are functioning properly
  • No personal data: a fact is just text, and there is no per-user state.

Interaction with MediaWiki

Duck sits outside MediaWiki and touches a single reader user flow: when a wiki page is viewed, it embeds a duck fact fetched from /duck.php through the CDN. The call is non-blocking, so the page renders whether or not Duck responds, and no editor, login, or save flow depends on it. There is no write path back into MediaWiki and no per-user state.

Ownership

Duck is in the Active WMF Development lifecycle state: it runs in production and is actively developed by the Wikifauna team. Following the WMF service ownership policy, a service has several distinct ownership roles rather than a single owner. For Duck, one team currently fills all of them:

RoleOwnerResponsibility for Duck
Development OwnerWikifauna teamWrites and reviews Duck's code, and triages bugs.
Configuration & Deployment OwnerWikifauna teamDeploys new versions via helmfile and reviews production config changes. Duck does not ride the MediaWiki train.
Incident Response OwnerWikifauna teamReceives Duck's paging alerts and drives any incident to resolution (see #Incident response).
Product Management OwnerWikifauna teamPrioritises Duck's feature work, and re-prioritises after incidents.

Architecture

Duck is a stateless service on Kubernetes, fronted by the CDN and running active/active in eqiad and codfw.

  • Requests arrive at /duck.php via the CDN edge and are routed through the discovery URL to a pool of pods.
  • Randmoly serves a fact on each request either:
   * from Memcached (via mcrouter) for a cached fact (if specific fact is requested).
   * or contacts the external ducklings.org API through the urldownloader proxies, caches the response, and returns it.
  • Stateless by design: all shared state lives in Memcached, so scaling means adding pods rather than coordinating replicas.

Graceful degradation:

  • If ducklings.org times out, Duck serves a cached fact.
  • If both Memcached and ducklings.org are unavailable, Duck serves a "precooked" fact that ships inside the container image, so a reader always gets something.
                  User
                   |
                   v
         +--------------------+
         |  CDN (cache_text)  |   /duck.php, cached for 5'
         +---------+----------+
                   |
           duck.discovery.wmnet
                   |
                   v
         +------------------+
         |       Duck       |
         |   k8s wikikube   |
         |  +  mcrouter     |
         +--------+---------+
                  |
       +----------+----------+
       v                     v
   +----------------+   +-----------------+
   |   Memcached    |   |  urldownloader  |
   | response cache |   +--------+--------+
   +----------------+            |
                                 v
                        +------------------+
                        |   ducklings.org  |
                        |  (external API)  |
                        +------------------+

(one DC shown; Duck runs active / active in eqiad and codfw)

Dependencies

  • Memcached (via mcrouter), response cache for facts;
 * on failure Duck falls back to calling ducklings.org directly
 * then to an in-process/precooked fact.
  • ducklings.org (external, required for fresh facts)
 * reached through the urldownloader proxies;
 * on failure Duck serves a cached or precooked fact rather than erroring.

Infrastructure

Duck runs on Kubernetes (wikikube) in both eqiad and codfw, active/active.

Traffic and networking

Duck takes traffic from the cache_text CDN tier at /duck.php.

  • Volume: roughly 800 req/s steady-state across both DCs, peaking near 2,000 req/s during "meme spikes".
  • CDN caching: VCL rule with TTL 5 minutes, vary on Accept-Language.
  • Discovery URL: duck.discovery.wmnet.
  • Depooling: either DC can be depooled without user-visible impact; a single DC has headroom for full traffic at under 40% CPU.
  • Rate limiting: 100 req/s per IP at the edge, plus an in-process load shedder that drops requests when the internal queue exceeds 500.

Monitoring and observability

Duck exports Prometheus metrics and ships structured JSON logs to Logstash.

  • Key metrics: request counts by status and route; request-duration histograms (p50/p75/p99); Memcached cache-hit ratio; business counters for fact like/dislike and category served.
  • Logs: find with service:duck in Logstash.
  • Grafana: Duck dashboard, request rate, error rate, latency percentiles, pod health, and Memcached hit ratio per DC; Memcached and ducklings.org health on the same board.
  • Logstash dashboard: logstash.wikimedia.org/app/dashboards/duck.
  • Cross-links: the Grafana dashboard links out to the /Runbook, the /SLO page, and the related Memcached and ducklings.org health boards.
  • Latency: per-endpoint p50/p75/p99 from Envoy.

Service level objectives

link to SLO work

Alerting

  • DuckTotalOutage (paging), fires when both DCs serve more than 10% 5xx for over 2 minutes. Response: see Runbook § "Total outage".
  • DuckHighErrorRate (team channel), fires when the 5xx rate exceeds 1% for 5 minutes.
  • DuckSLOBudgetBurn (team channel), fires on fast error-budget burn over a 1-hour or 6-hour window.
  • DuckMemcachedDown (team channel), fires when Memcached is unreachable from Duck.

Every alert carries a runbook annotation pointing to the relevant section of /Runbook.

Reliability

  • Health checks: /healthz (process is alive) and /readyz (readiness, including Memcached connectivity)
  • No SPOFs at the service layer: it runs multi-replica and multi-DC.
  • Dependency handling: Memcached is best-effort, with fallback to an in-process LRU and ultimately a precooked fact; calls use a 50 ms timeout with no retry.
  • Failover: handled via the discovery URL.
  • Scaling: each pod requests 200m CPU and 256Mi memory
  • Bus factor: 3 engineers can each deploy and operate Duck end-to-end.


Deployment

  • Source: Wikifauna duck repository, main branch.
  • Image: each merge produces docker-registry.wikimedia.org/repos/wikifauna/duck, with the version pinned in the helmfile values.
  • Rollout: codfw first, then eqiad, with smoke tests after each step and a documented rollback via helmfile.
  • Watch out for: cold caches at the CDN edge are the most likely launch-day failure; the error budget is watched on the "Duck SLO burn rate" panel during every deploy.

Smoke tests

Run after each rollout step, against each DC, before continuing:

  • Liveness
curl -sS https://duck.discovery.wmnet:4321/healthz
  • Readiness
curl -sS https://duck.discovery.wmnet:4321/readyz
  • Serves a fact
curl -sS https://duck.discovery.wmnet:4321/duck.php
  • Cache works: call /duck.php twice; the second response should be a cache hit (the hit-ratio metric ticks up).
  • Through the edge: returns a fact via the CDN.
 curl -sS https://en.wikipedia.org/duck.php

Testing

Unit tests and integration tests (against a Memcached fixture) run in GitLab CI on every merge request.

Maintenance

  • No scheduled jobs: Duck has no maintenance scripts (mw-script) or cron jobs (mw-cron); the fun-facts payload ships with the container image, so there is nothing scheduled to verify.
  • Capacity: reviewed once per quarter against current traffic and projected feature work.

Incident response

The Incident Response Owner for Duck is the Wikifauna team: it receives Duck's paging alerts and is responsible for driving any incident to resolution, escalating to the other owners (see #Ownership) when needed. The on-call rotation and contact channels are listed in the infobox; alert response procedures live in the runbooks below.

Escalation

Only the DuckTotalOutage alert pages on-call; everything else routes to the #Wikifauna team channels during working hours. Out of hours, paging for a total outage falls through to SREs.

Runbooks

The full runbook lives at /Runbook. It covers:

  • Depooling a data centre.
  • Rolling back to the previous image.
  • The response procedure for each alert.
  • A short "gotchas" list.