KatInterview

Cutting Duplicate HTTP Calls in a curl-Driven Workflow

System DesignModel answer
MediumModel answerSystem Designobservabilityhttpcaching

Last updated

Instrument an HTTP client to count and attribute its calls, detect wasteful repeats, reduce them safely, and prove the change is correct and stays fixed.

You own a client that talks to a REST API through curl, either shell scripts or a thin wrapper library. One user-facing workflow (for example: load a dashboard, read account balances, submit a transfer, then poll until it settles) feels slow, and the API owners say your traffic is heavier than it should be.

Describe how you would handle this end to end:

  1. Measure. Work out how many HTTP requests the workflow actually makes and which endpoints they hit, using curl and light instrumentation.
  2. Attribute. Decide what identifiers to attach and log so that every call can be tied to both a single request and the overall workflow run.
  3. Detect. Explain how you would spot redundant or repeated calls in the logs.
  4. Reduce. Describe the changes you would make to the client (batching, caching, debouncing or coalescing, or others) and say which situation each suits.
  5. Verify and protect. Explain how you would confirm outputs are unchanged, quantify the improvement, and stop the problem from returning.

State the assumptions you make. A strong answer treats writes, such as payments, more carefully than reads.

Hints

Hint 1

Start by defining the workflow boundaries and a numeric goal, then record one structured line per call (method, normalized route, status, latency) so you can group and count.

Hint 2

Use two kinds of identifiers: a unique one per call to join with server logs, and a shared one per workflow run to count everything that run did. Collapse IDs in URLs into templates before counting.

Hint 3

Match the fix to the pattern: concurrent identical reads need in-flight sharing, repeated reads need TTL or ETag caching, N+1 needs a bulk endpoint, tight polling needs backoff. Never dedupe writes unless an idempotency key makes it safe.

Hint 4

For proof, compare final outputs before and after, assert that the POST count and idempotency keys are unchanged, inject 5xx/429/timeouts, and add a request-budget check to CI.