Skip to content
BIASED
Back to topic

Optional

Review workload before deployment

All confusion counts, costs and bounds are stipulated. The 130/day capacity comparison assumes daily arrivals reproduce this 1,000-item mix. Sequential per-request bounds can add; separate p95s cannot generally add.

Version
v2
Minutes
~20
Evidence
Self-check in the notebook

Until platform auto-check exists, compare cell output with the expected numbers in the notebook. This is not a debt and does not affect mastery.

Download .ipynb

Download the notebook and run it locally. Its environment requirements are listed inside.

Notebook contents

Readable on your phone. The code below has not been executed in the browser; download the notebook to run it.

Review workload before deployment / Работа проверяющего до выпуска

Optional practice; Python standard library only. The core lesson does not require running code. No downloads, network, accounts, models, user data or actual deployments.

Необязательная практика; только стандартная библиотека Python. Для основной темы запуск кода не требуется. Без загрузок, сети, аккаунтов, моделей, пользовательских данных или реальных деплоев.

Authored for the Fedor Pakhurov project with Codex assistance. Case functions and fictional inputs come from the independently reviewed first-party note and fixture at published revision 82b6cb07167b37710c6a786a3a41878a4e928483. New packaging and exact-arithmetic self-checks are added here. No exclusive copyright guarantee is asserted.

Note: https://github.com/fpakhurov/fpakhurov.com/blob/82b6cb07167b37710c6a786a3a41878a4e928483/src/content/notes/mlops/ml-system-design.mdx

Fixture: https://github.com/fpakhurov/fpakhurov.com/blob/82b6cb07167b37710c6a786a3a41878a4e928483/scripts/notes/mlops-renewal-cases.py

The note retains primary conceptual citations; no external source-specific dataset, model output, figure or code is included.

Inputs and limits / Входы и границы

All confusion counts, costs and bounds are stipulated. The 130/day capacity comparison assumes daily arrivals reproduce this 1,000-item mix. Sequential per-request bounds can add; separate p95s cannot generally add.

Все числа ошибок, стоимости и границы заданы. Сравнение с ёмкостью 130/день предполагает дневной поток того же состава и размера 1 000. Складывать можно последовательные границы каждого запроса; отдельные p95 в общем случае не складываются.

import hashlib
import itertools
import json
import math
 
def design():
    # A reviewer spends two minutes; an undetected bad preview costs twelve.
    rows = []
    for name, true_positive, false_positive in [("rule", 48, 92), ("candidate", 68, 52)]:
        false_negative = 80 - true_positive
        true_negative = 920 - false_positive
        reviews = true_positive + false_positive
        rows.append({"name": name, "tp": true_positive, "fp": false_positive,
                     "fn": false_negative, "tn": true_negative, "reviews": reviews,
                     "accuracy": (true_positive + true_negative) / 1000,
                     "precision": true_positive / reviews, "recall": true_positive / 80,
                     "minutes": 2 * reviews + 12 * false_negative})
    assert rows[1]["minutes"] == 384 < rows[0]["minutes"] == 664
    return {"documents": 1000, "bad_previews": 80, "review_all_minutes": 2000,
            "accept_all_accuracy": 0.92, "options": rows,
            "latency_budget_ms": {"decode": 18, "features": 12, "queue": 25,
                                  "score": 35, "response": 10},
            "latency_bound_ms": 100, "daily_reviews_limit": 130}
result = design()
print(json.dumps(result, indent=2, allow_nan=False))

Check independently / Независимая проверка

The checks below use conservation, exact arithmetic or boundary cases in addition to the case function. Passing them establishes these declared examples, not production reliability.

Ниже проверяются сохранение, точная арифметика или граничные случаи сверх функции примера. Их прохождение устанавливает эти заданные примеры, а не надёжность продакшена.

from fractions import Fraction
rule, candidate = result["options"]
assert all(r["tp"] + r["fn"] == 80 and r["fp"] + r["tn"] == 920 for r in result["options"])
assert candidate["reviews"] == 120 <= result["daily_reviews_limit"] < rule["reviews"]
assert candidate["minutes"] == 2 * 120 + 12 * 12 == 384
assert math.isclose(candidate["precision"], float(Fraction(17, 30)))
assert sum(result["latency_budget_ms"].values()) == result["latency_bound_ms"]
print("Self-checks passed: populations, queue counts, work and sequential bounds agree.")

Change one assumption / Измените одно предположение

Change the recovery cost of a missed defect. Can the candidate stop reducing work relative to the rule for any nonnegative recovery cost? Hold the two confusion tables fixed so only the cost assumption changes.

Измените стоимость исправления пропущенного дефекта. Может ли кандидат перестать уменьшать работу относительно правила при какой-либо неотрицательной стоимости исправления? Сохраните две таблицы ошибок, чтобы менялась только стоимость.