Design a Livestream Ranking Serving API
Serve model-ranked live streams through a bounded REST API while preserving eligibility, latency, and honest fallback behavior.
Problem statement
For this exercise, assume a client opens a discovery surface and requests a ranked list of livestreams. An existing catalog supplies up to 200 candidate stream IDs and request-time context; an existing approved model scores those candidates. Design the REST serving API and its dependencies.
Return at most 20 eligible stream IDs in ranked order, with the model or fallback version and generation time. The API does not train the model or generate candidates.
A stream is eligible only when the catalog view marks it live and accessible to the requester. The view must be no more than 30 seconds old, and a stream already known to be ended or inaccessible must not appear in the response. The freshness bound does not promise instantaneous awareness of a source change.
Missing or older eligibility evidence produces an explicit unavailable outcome. When scoring fails but eligibility remains valid, the API may return an explicitly marked deterministic fallback order over the same eligible candidate set; otherwise it returns unavailable.
Use 10,000 peak requests per second, 100,000 live-stream metadata records, a maximum of 200 candidates per request, and a 200 millisecond p95 API response target as practice assumptions. Keep each response attributable to the candidate set, catalog-view version, and one model or fallback version.
Explain API validation, caching, bounded feature and scoring calls, authorization, observability, and recovery during ranker failure or stream churn.
Video delivery, candidate-generation algorithms, model training and evaluation, client UI implementation, and pagination across a long-lived ranking snapshot are outside scope.
What to build
- An authorized client can request and receive at most 20 eligible livestream IDs in ranked order, with explicit serving-version and generation-time metadata.
- Every normal or fallback result excludes streams known ended or inaccessible, using a catalog view no older than 30 seconds.
- The API returns a labeled deterministic fallback over the same eligible candidates when scoring fails, or an explicit unavailable result when eligibility cannot be established.
- Operators can attribute a response to its candidate-set identity, catalog-view version and one serving version, and observe latency, stale views, overload and fallback rates without logging sensitive request context.
At scalePractice assumption
- Support 10,000 ranking requests per second at peak over 100,000 live-stream metadata records, with at most 200 supplied candidates per request and at most 20 returned IDs.
- Meet a 200 millisecond p95 API response target, including dependency deadlines and any permitted fallback.
- Eligibility views are at most 30 seconds old; a known-ended or inaccessible stream is excluded even when a cached score remains available.
- Model or feature dependencies may time out and load may exceed capacity; return bounded, observable fallback, throttling or unavailability rather than queue requests indefinitely.