Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Resilient Ingestion Worker for Unreliable Producers

Configure timeouts, jittered retries, a 50-connection cap and circuit breakers so a worker pulling from flaky and slow producers stays up, keeps each producer's trouble to itself and never loses a change.

Problem statement

Design a worker that collects video metadata from seven outside producers and keeps working when they misbehave. Two producers fail often, four are slow (about 8 seconds at p99, so 1 answer in 100 takes longer than that), and one is reliable.

Write the worker's YAML configuration for timeouts, retries, a connection cap and circuit breakers, and explain how the worker uses it.

What the configuration must do. - A producer error, timeout or bad response never crashes the worker. - Every request to a producer times out after 3 seconds. - A failed request is retried at most 2 times, with a 500 ms backoff (the wait before a retry) and random jitter (randomness in that wait, so retries from many requests do not land at the same moment). - One worker never has more than 50 open connections. Work beyond that goes to another worker shard (another copy of the worker that owns different producers). - A circuit breaker (a switch that stops calls to a producer that keeps failing, then lets a few test calls through later) protects the worker from failing producers.

For this exercise, assume: - Each producer offers two read-only HTTP calls: a change list that returns up to 100 changed video ids after a cursor (a position marker the producer gives back), and a fetch that returns one video's metadata. Calling either one twice is safe.

- The worker stores each video's latest metadata in a database it owns, and runs as several identical instances. Each producer is read by one instance at a time. - A flaky producer may answer 429 (too many requests) with a Retry-After header (how many seconds to wait before trying again).

A 4xx answer other than 429 means the request itself is wrong.

Out of scope: downloading video files, transforming or searching the metadata, and how the worker authenticates to producers.

What to build

  1. The worker pulls every new or changed video from each producer and stores its latest metadata.
  2. A failing, slow or misbehaving producer delays only its own videos; the worker keeps running and the other producers stay current.
  3. After a worker crash, a restart or a producer outage, reading continues from where it stopped, so no change is skipped and a re-read never creates a second copy of a video.
  4. Operators set every producer's limits in one YAML file and can see each producer's breaker state, lag (how far behind the producer's newest change it is) and error rate.

At scale

  • Seven producers: two fail often, four are slow (about 8 seconds at p99) and one is reliable. Every request times out after 3 seconds and is retried at most 2 times, and one worker never has more than 50 open connections.
  • For this exercise, assume that at peak each slow producer reports up to 4 changed videos per second, each flaky producer up to 10 and the reliable producer up to 20.
  • For this exercise, assume typical answers take about 1 second from a slow producer (about 5% of its calls take longer than 3 seconds), 300 ms from a flaky one and 200 ms from the reliable one. A flaky producer fails about 1 call in 10, usually fast (an error answer within about 300 ms, not a hang), and sometimes goes down for minutes at a time.
  • For this exercise, assume a change should be stored within 1 minute while its producer is healthy, and after an outage of up to 1 hour a producer's backlog should be cleared within 30 minutes of its recovery.