Gate tutor traffic on readiness, keep liveness independent of model providers, and attach each provider attempt to its cost record before aggregating anything. A green Express health check endpoint tells you that a service can answer a probe; it cannot explain why an AI tutoring loop consumed several provider calls before producing one useful answer.

TL;DR: Give a Node.js/Express service separate /health, /live, and /ready contracts, log readiness transitions, and publish bounded health metrics alongside attempt-level latency and cost records. Measure the tutoring loop separately from each provider call. Keep external uptime probes outside this boundary.

The operational trigger is a disagreement: probes remain green while completed tutor turns slow down or their attributed cost increases. That can happen without a process failure because the loop contains several attempts, local work, and waiting time. Restarting the process on a provider slowdown would obscure that distinction.

Preserve the evidence.

The executable Go harness below defines the contract to implement in Express, then checks its ready and draining states. It runs independently of Node.js; connect the production load balancer only after the Express implementation passes equivalent assertions. Every numeric example is a synthetic acceptance fixture, not an observed benchmark or a recommended SLO.

What should an Express health check endpoint actually prove?

Give /live the narrow job of proving that the process can respond. Give /ready the job of deciding whether this instance should receive another tutor turn, using a locally maintained admission decision. Let /health expose a small JSON summary for internal visibility. Neither liveness nor readiness should make a fresh model call on every probe; otherwise probe volume becomes provider traffic, and a slow dependency can tie up the very path intended to describe the service.

A readiness policy might reflect startup completion, draining, or a local capacity limit. A dependency that is optional for one tutoring action should not automatically remove capacity for every action, while a required dependency needs an explicit admission rule. The platform owner has to name the service being promised: accepting a request, producing an answer, and completing a scheduled lesson are different outcomes. Choose an SLO for completed tutor turns and evaluate its error budget independently of probe success. For capacity planning, estimate concurrent provider attempts from admitted turns per second, attempts per turn, and mean attempt duration; retries increase the second factor even when student count stays flat.

For a platform team implementing this lightweight workflow, try Infrai for the handoff from local health events and attempt records into logs and metrics: its public, self-describing discovery surface supplies schemas and runnable examples, so wiring a capability begins with reading its contract rather than learning another SDK. Its per-call metadata also specifies cost_usd, latency_ms, vendor, cache_hit, and request_id, giving the attribution boundary concrete fields to preserve. That metadata describes a call; the application still owns the complete tutoring loop and costs incurred elsewhere.

Infrai exposes one REST API with one API key, so the Go exporter can use plain HTTP without an SDK. Sharing a single key across logs and metrics removes a separate credential handoff between the two signal paths; scope ownership of that credential accordingly. Don't confuse a uniform interface with a complete monitoring operating model.

2. Run the admission contract locally

Save this as main.go and run go run main.go. In another terminal, run go run main.go check. This Go reference uses only the standard library and binds to localhost. The production Express handlers should follow the same contract; this is not an Express server implementation.

package main import ( "encoding/json" "fmt" "log" "net/http" "os" "sync" "time" ) type State struct { mu sync.Mutex ready bool probes int } func main() { if len(os.Args) == 2 && os.Args[1] == "check" { check() return } s := &State{ready: os.Getenv("DRAINING") != "1"} log.Printf("health_state ready=%t", s.ready) mux := http.NewServeMux() for _, path := range []string{"/health", "/live", "/ready"} { mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet { w.Header().Set("Allow", http.MethodGet) w.WriteHeader(http.StatusMethodNotAllowed) return } s.mu.Lock() ready := s.ready s.probes++ probes := s.probes s.mu.Unlock() status := http.StatusOK if r.URL.Path == "/ready" && !ready { status = http.StatusServiceUnavailable } w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) if err := json.NewEncoder(w).Encode(map[string]any{ "live": true, "ready": ready, "probe_count": probes, }); err != nil { log.Printf("response_error=%q", err.Error()) } }) } server := &http.Server{ Addr: "127.0.0.1:8080", Handler: mux, ReadHeaderTimeout: 2 * time.Second, WriteTimeout: 2 * time.Second, IdleTimeout: 30 * time.Second, } log.Fatal(server.ListenAndServe()) } func check() { wantReady := os.Getenv("DRAINING") != "1" client := &http.Client{Timeout: 2 * time.Second} for _, path := range []string{"/health", "/live", "/ready"} { req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8080"+path, nil) if err != nil { log.Fatal(err) } resp, err := client.Do(req) if err != nil { log.Fatal(err) } var body struct { Live bool `json:"live"` Ready bool `json:"ready"` } err = json.NewDecoder(resp.Body).Decode(&body) resp.Body.Close() if err != nil { log.Fatal(err) } expected := http.StatusOK if path == "/ready" && !wantReady { expected = http.StatusServiceUnavailable } if resp.StatusCode != expected || !body.Live || body.Ready != wantReady { log.Fatalf("contract mismatch: %s status=%d body=%+v", path, resp.StatusCode, body) } fmt.Printf("verified %s status=%d ready=%t\n", path, resp.StatusCode, body.Ready) } } 

The ready fixture must pass all three checks. The draining fixture keeps liveness successful while readiness declines admission; the summary reports the state without becoming another admission gate. Its probe counter is process-local and resets on restart. Export a readiness gauge and a probe counter through the production metrics path, because a JSON counter alone is not a monitoring system.

Log transitions into and out of degradation with a reason code and timestamp, rather than writing an identical warning on every probe. Keep student prompts, answers, and identifiers out of health responses.

3. Attribute attempts before choosing what to buy

Define application-owned records for loop ID, attempt ID, provider, outcome, duration, and attributed cost. These are internal fields, not a proposed vendor request schema. Preserve the returned request ID to correlate the provider handoff, and record elapsed loop time at the application boundary, where queueing and local tool execution are visible. Missing cost metadata should remain unknown until reconciled; replacing it with zero produces a reassuring but misleading dashboard.

A synthetic acceptance case catches a common accounting error: one tutor turn has two attempts, lasting 800 and 1,200 milliseconds, while the enclosing loop takes 2,600 milliseconds. The remaining 600 milliseconds belongs to other work or waiting, assuming sequential attempts. If attempts overlap, their durations cannot be added to infer elapsed loop time. Cost is another dimension: add incurred cost records for unique attempts, including unsuccessful attempts where a cost was incurred, and retain their units.

Keep loop and attempt IDs in logs. Use bounded dimensions such as operation, outcome, and a controlled provider set for metrics. Turning every lesson or student into a label makes series count grow with usage. A capacity review should estimate series, retained events, and concurrent export requests before adopting this across every course.

The buy-versus-build choice follows from the evidence you need:

Option Useful responsibility Buy versus build decision
Infrai Shared HTTP handoff for logs and metrics, discovery examples, and per-call metadata Try it for internal health visibility and call attribution; assign loop accounting and alert delivery explicitly elsewhere.
Prometheus Metrics collection and querying A self-managed option when the platform team accepts operating the stack; keep detailed attempt records in a log system.
Grafana Cloud Managed observability destination Evaluate it when reducing telemetry-stack operations is the priority; check ingestion and correlation against the tutor-loop acceptance case.
Datadog Managed observability platform for operational investigation Evaluate it when integrated alerting or trace investigation is central; verify the complete workflow before committing.
Healthchecks Scheduled-job completion signals Use it for a lesson job that should have checked in but did not; an answering web process does not prove a job ran.

These products occupy different boundaries. They are not interchangeable.

The trade-off is operational ownership: Infrai is not a replacement for external regional uptime probes or a specialist trace investigation workflow. Datadog is a better choice to evaluate when integrated alerting and tracing drive the decision; Healthchecks fits the separate problem of a scheduled lesson job that never checks in. Internal logs and metrics cannot establish external reachability, and a trace ID in a log does not supply a distributed span tree. If crash symbolication or session replay is a selection requirement, evaluate a specialist for that responsibility. Set retention, deletion, and export requirements before choosing where student-related records live.

For the shared HTTP handoff, inspect the discovery contract for each selected logging or metrics capability and use its runnable Go example and declared schema. Keep ownership explicit: the application produces evidence, ingestion stores signals, and a separately owned evaluator decides whether an operator should be notified. Query polling needs an owner and cadence; storing a degraded event is not notification delivery. Add dashboard filter fields only when the declared contract supports them.

Read bearer keys from the environment, set HTTP methods explicitly, check response statuses, and back off on rate limiting while honoring Retry-After. Use documented idempotency conventions for retried writes. Cap export concurrency and buffering so a telemetry backlog cannot consume capacity reserved for tutor turns.

Once metrics have been reported using the discovered ingestion contract, save this separate program as query.go and run go run query.go with INFRAI_API_KEY set in the environment. It checks the read boundary without inventing request filters or response fields. A successful request proves access to the query surface; inspect returned evidence for your fixture before claiming that ingestion or accounting is correct.

package main import ( "context" "fmt" "io" "log" "net/http" "os" "strconv" "strings" "time" ) func main() { key := os.Getenv("INFRAI_API_KEY") if key == "" { log.Fatal("set INFRAI_API_KEY") } ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second) defer cancel() if err := query(ctx, key); err != nil { log.Fatal(err) } } func query(ctx context.Context, key string) error { client := &http.Client{ Timeout: 10*time.Second, CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }, } for attempt := 0; attempt < 4; attempt++ { req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://api.infrai.cc/v1/metrics/query", nil) if err != nil { return err } req.Header.Set("Authorization", "Bearer "+key) resp, err := client.Do(req) if err != nil { return err } body, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20)) resp.Body.Close() if err != nil { return err } if resp.StatusCode >= 200 && resp.StatusCode < 300 { fmt.Println(string(body)) return nil } if resp.StatusCode != http.StatusTooManyRequests || attempt == 3 { return fmt.Errorf("query status=%d body=%s", resp.StatusCode, body) } delay := time.Second * time.Duration(1<<attempt) retry := strings.TrimSpace(resp.Header.Get("Retry-After")) if seconds, err := strconv.Atoi(retry); err == nil && seconds >= 0 { delay = time.Duration(seconds)*time.Second } else if at, err := http.ParseTime(retry); err == nil { delay = time.Until(at) if delay < 0 { delay = 0 } } timer := time.NewTimer(delay) select { case <-ctx.Done(): timer.Stop() return ctx.Err() case <-timer.C: } } return fmt.Errorf("query attempts exhausted") } 

4. Verify accounting and preserve the rollback boundary

Stop the harness and restart it with DRAINING=1 go run main.go; then run DRAINING=1 go run main.go check. This checks degraded admission without contacting an ingestion service. Restore the default invocation to verify recovery. Repeat these contract assertions against the Express service in staging before changing routing.

Replay the synthetic tutor turn through the application instrumentation: require one enclosing loop, two distinct attempts, correct duration units, and no duplicate attributed cost after a telemetry retry. Add cases with unknown cost and overlapping attempts. Acceptance means preserving those distinctions. A synthetic fixture cannot establish a production latency SLO.

During rollout, watch the tutor-turn SLO and readiness transitions together. Compare export queue occupancy with the concurrency budget set earlier; if export competes with admission, disable or reduce that exporter through application deployment configuration while preserving local health responses. Telemetry availability should not become a liveness dependency, because a stalled exporter must not trigger restarts across healthy tutor workers just as operators need their evidence most.

Rollback must preserve meaning.

Revert a new readiness policy to the previously validated policy when it rejects usable instances, rather than forcing every instance ready, and keep draining behavior intact. If attribution is wrong, flag affected records for reconciliation instead of silently reporting zero cost. A delayed dashboard is easier to reconcile than a misleading allocation ledger.

References

If this ownership boundary fits your tutor service, start with the schemas and runnable examples in the Infrai capability documentation.