Health checks на собеседовании системного аналитика

Готовься к собесу аналитика как в Duolingo
10 минут в день — SQL, Python, A/B, метрики. 1700+ вопросов в Telegram
Открыть Карьерник в Telegram

Карьерник — Duolingo для аналитиков: 10 минут в день тренируй SQL, Python, A/B, статистику, метрики и ещё 3 темы собеса. 1500+ вопросов в Telegram-боте. Бесплатно.

Зачем health checks

Auto-detect unhealthy instances → remove from LB / restart.

Без health checks — broken pod продолжает receive traffic, errors propagate.

Liveness vs readiness

Liveness. Is the service alive (or hung)?

GET /healthz → 200 OK

If fail многократно → restart container.

Should be lightweight. Just verify process responsive.

Readiness. Is the service ready принимать traffic?

GET /ready → 200 если can serve.

If fail → remove из LB pool. Не restart.

Checks dependencies (DB, cache, downstream).

@app.get("/ready")
def ready():
    if not db.is_connected():
        return Response(status=503)
    if not redis.ping():
        return Response(status=503)
    return Response(status=200)

Startup probe

k8s 1.16+. Для slow-starting apps.

startupProbe:
  httpGet:
    path: /startup
    port: 8080
  failureThreshold: 30
  periodSeconds: 10  # 5 min total

Disables liveness / readiness пока startup succeeds. Prevents premature kills.

Готовься к собесу аналитика как в Duolingo
10 минут в день — SQL, Python, A/B, метрики. 1700+ вопросов в Telegram
Открыть Карьерник в Telegram

Deep vs shallow

Shallow. Just service responding.

Deep. Check critical dependencies.

/health/shallow: just returns 200.
/health/deep: checks DB + Redis + downstream API.

Trade-off.

  • Deep — accurate readiness, но cascade failures (one slow downstream → all unhealthy).
  • Shallow — может мiss real issues.

Compromise. Readiness — deep. Liveness — shallow (just process check).

Implementation patterns

Cache health for short period. Если check expensive — cache 1-5 sec.

Different ports. Health на admin port, не main API.

Don't include in main metrics. Separate health requests.

Fail fast on critical deps. No DB → not ready.

Don't fail на optional deps. Cache miss → still ready (degraded).

Связанные темы

FAQ

Это официальная информация?

Нет. Статья основана на k8s docs и Microsoft / Google practices.


Тренируйте системный анализ — откройте тренажёр с 1500+ вопросами для собесов.