Instrument and Optimize Client HTTP Requests for a Workflow
Context
You have a client that performs a defined workflow against an HTTP API (for example: authenticate, list resources, fetch details, perform an action). The goal is to:
-
Measure how many HTTP requests are made and which endpoints are called during the workflow.
-
Add request IDs and correlation IDs for traceability across requests.
-
Detect redundant or repeated calls.
-
Reduce unnecessary traffic by batching, caching, and/or debouncing where appropriate.
-
Verify correctness, quantify improvements, and prevent regressions with tests and metrics.
Assume you can run the client locally and you can modify the client code. Use curl and lightweight code instrumentation; avoid heavy proxies or network sniffers.
Tasks
-
Baseline measurement
-
Using curl and/or lightweight instrumentation around the client’s HTTP layer, record all requests made during a single workflow run. Capture method, URL/path, status code, latency, and response headers.
-
Traceability
-
Add a per-request Request-ID and a per-workflow Correlation-ID. Log both, and include them as HTTP headers.
-
Redundancy detection
-
Identify repeated requests (same method + URL + query and, if relevant, body) within the workflow and flag redundant patterns (e.g., N+1, in-flight duplicates, re-fetches).
-
Optimizations
-
Modify the client to reduce unnecessary calls using one or more of:
-
Batching (if API supports batch endpoints).
-
Caching (in-memory TTL, ETag/If-None-Match, cache-busting rules).
-
Debounce/throttle (e.g., for type-ahead or rapid UI events).
-
In-flight de-duplication (coalesce identical concurrent requests).
-
Validation and metrics
-
Explain how you will verify correctness (functional equivalence, header presence) and measure improvement. Define metrics, budgets/thresholds, and tests to prevent regressions.
Deliverables
-
A short write-up or scripts showing:
-
Baseline counts and endpoints called.
-
Logging format with Request-ID and Correlation-ID.
-
Detected redundancies and chosen fixes.
-
Code changes for batching/caching/debouncing.
-
Verification steps, tests, and metrics with before/after results.