Thomas Piacentini
← Atelier

Projet

Hedged Request Lab

Texte original · anglais480 min

Help client developers evaluate delayed duplicate requests for safe reads. Send a second attempt only after a configurable delay, accept the first valid response, and record cancellation, late completion and duplicate service work separately. Export a bounded HTTP client and a latency-versus-work report from controlled local endpoints.

Standard libraries only. Four stages, approximately eight hours. Go implementations are exercised by the grader.

Build it

  1. Measure safe-read latency
  2. Schedule delayed duplicate attempts
  3. Validate winners and account for late work
  4. Export latency and duplicate-work tradeoffs
bash
python3 scripts/project_test.py hedged-request-lab --init /tmp/hedged-request-lab-work
python3 scripts/project_test.py hedged-request-lab --stage 1 --path /tmp/hedged-request-lab-work --strict
python3 scripts/project_test.py hedged-request-lab --all --solution --strict

The fresh starter fails until you implement it. Reference-solution runs never grant learner completion certificates.

Run the controlled endpoint comparison

bash
cd projects/hedged-request-lab/solution
go run . --samples 3 --delay-ms 10 --out /tmp/hedge-report.json
python3 -c 'import json; r=json.load(open("/tmp/hedge-report.json")); print("call ratio",r["hedgedCalls"]/r["baselineCalls"],"server work",r["fixtureWork"])'

The terminating demo runs real loopback HTTP endpoints, with an 80ms primary and a 5ms secondary. It compares baseline and hedged winner latency, calls launched and server work. Service handlers deliberately keep working after client cancellation, so the completed counter demonstrates why a cancelled client request does not prove saved computation or billing.

Reuse Hedged for declared safe reads, or pass --primary URL --secondary URL to the CLI. Each endpoint must return HTTP 200 with JSON {value:"nonempty string"}. The caller is responsible for equivalent data versions and semantics between endpoints. The default client forbids redirects; the library accepts an explicitly supplied http.Client.

At most two GET attempts run per operation, response bodies are limited to 64KiB, each operation has a two-second ceiling and post-winner observation is bounded at 100ms. The version-1 receipt distinguishes winner latency, attempts, cancellation requests, observed cancellation, late observations and unobserved client attempts. Local percentiles are illustrative observations, not external service performance claims.

Go contexts, Go HTTP and HTTP safe methods define the library boundaries.

Completion evidence

bash
python3 scripts/project_test.py hedged-request-lab --all --path /tmp/hedged-request-lab-work --strict --report /tmp/hedged-request-lab-result.json

Local reports are unsigned, self-reported evidence. The editable figures calculate illustrative values; the CLI runs the actual implementation.

Code et livrables 23
Ce que vous en retenez

Enregistré dans votre carnet sur cet appareil.

Sources et limites

Les repères de lecture sont déclaratifs. Les résultats de tests sont enregistrés séparément ; ils valent pour les cas exécutés.

AI Engineering from Scratch · 3f9715c · MIT

Télécharger ce fichier ↓