Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

Design a shared HTTP client library used by many teams for calling internal services. What defaults and features do you build in?

The library makes the safe settings the default: explicit connect, request and pool acquisition timeouts; retries only for idempotent requests, with exponential backoff, jitter and a cap; and a circuit breaker and bulkhead per downstream service. It adds trace headers, metrics per host and status, and structured logs without secrets, and it takes TLS settings and trust stores from central configuration. Teams can override any setting per client or per call, but they must do so explicitly, so the easy path is the safe one.

Why this question is asked

In a company where many teams call internal services, each team configuring its own HTTP client means each team rediscovers the same failures: infinite timeouts, retry storms, connection pools exhausted by one slow dependency, and logs with access tokens in them. A shared client library fixes these once. Interviewers ask this design question to see whether we know which defaults prevent incidents, and how to build a library people want to use rather than work around. In this answer, we will set the goals, design the timeouts, the retry policy, the circuit breaker and bulkhead, the observability and the TLS handling, and finish with how overrides work.

1Goals and Shape of the Library

The library has one goal: a team that writes the minimum code should get a client that behaves well when a downstream is slow or failing. That means safe defaults, consistent telemetry and central security settings, without hiding the underlying engine so much that teams cannot debug it. In a Spring company, the natural shape is a thin layer over Spring's RestClient and an engine such as Apache HttpClient 5, delivered as a starter that auto-configures a builder per downstream service from configuration.

Java
# application.yaml in a consuming service
acme.http.clients:
inventory:
base-url: https://inventory.internal
# nothing else needed: library defaults apply
pricing:
base-url: https://pricing.internal
request-timeout: 800ms # explicit override, visible in review
// Code
@Bean InventoryApi inventory(AcmeHttpClients clients) {
return clients.forService("inventory").createProxy(InventoryApi.class); // @HttpExchange interface
}
Step throughInside the shared client
  1. Service APItyped @HttpExchange interface per downstream
  2. Resiliencedeadline, retry policy, circuit breaker, bulkhead
  3. Telemetrytrace headers, metrics per host and status, redacted logs
  4. TransportRestClient over a pooled engine with explicit timeouts
  5. Securitycentral TLS settings, trust stores, client certificates

5 layers, from the top down. Step through them one at a time.

2Timeouts: Three of Them, Always Set

There are three separate waits in an HTTP call, and each needs its own limit. The connect timeout limits establishing a connection; on an internal network a healthy connect takes milliseconds, so a default around 1 second is generous. The request or read timeout limits the wait for the response; the default should reflect internal service objectives, for example 2 seconds, and teams override it per downstream. The pool acquisition timeout limits waiting for a free connection from the pool; when a downstream slows down and the pool is full, this one turns a hidden queue into a fast failure, so a short default such as 250 to 500 milliseconds works well.

We also support a deadline that spans retries: if the caller has 3 seconds in total, the library never starts an attempt that cannot finish in the remaining time. And the pool itself has explicit limits, for example 50 connections per downstream host, so one service cannot take every connection.

3Retries Only When They Are Safe

Retries rescue requests from brief failures, but done carelessly they multiply load on a service that is already struggling. The library retries only idempotent requests, those that can be repeated without changing the outcome: GET, HEAD, PUT and DELETE by default, and POST only if the caller marks it safe and sends an idempotency key header that the server uses to detect repeats. It retries only on failures likely to be temporary, connection errors, 502, 503 and 504, and 429 when the server sends Retry-After, never on 400 or 500 errors caused by the request itself.

Java
// Default retry policy
maxAttempts = 3 // the first try plus two retries
baseDelay = 100 ms
maxDelay = 2 s // cap on any single wait
delay(attempt) = random(0, min(maxDelay, baseDelay * 2^attempt)) // exponential backoff with full jitter
// attempt 1 -> wait 0..200 ms, attempt 2 -> wait 0..400 ms
retryBudget = 10% of requests per downstream per minute // beyond this, stop retrying

Backoff spaces the retries out, and jitter, a random part of the delay, stops thousands of clients retrying at exactly the same moment. The retry budget is the protection against retry storms: if a downstream is failing broadly, retries stop adding load once they reach 10 percent of traffic. And the library never retries on top of another retrying layer, so we document that services should not add their own retry loops.

4Circuit Breaker and Bulkhead per Downstream

A circuit breaker watches the failure rate to one downstream. When failures cross a threshold, for example 50 percent of the last 100 calls, it opens and fails calls immediately for a cooling period, say 30 seconds, then lets a few trial calls through to check recovery. That protects both sides: the downstream gets room to recover, and our threads stop waiting on calls that will fail anyway. A bulkhead limits concurrent calls to each downstream, for example 100, so a slow pricing service cannot occupy every thread and connection that the inventory calls also need. We implement both with a mature library such as Resilience4j, configured per service name.

Step throughOne call through the library
  1. Circuit open for this downstream?
    Yesfail fast: CallNotPermittedNocontinue
  2. Bulkhead permit available?
    YescontinueNofail fast: too many concurrent calls
  3. Send with connect, pool and request timeoutstrace header added, metrics recorded
  4. Success?
    Yesreturn the responseNocheck the retry policy
  5. Idempotent, retryable error, budget and deadline left?
    Yeswait backoff with jitter, send againNoreturn the error

5 steps in order. Play them, or step through them one at a time.

5Observability Without Leaking Secrets

Every call carries trace context headers, the W3C traceparent header through Micrometer Tracing or OpenTelemetry, so a request can be followed across services. Every call records metrics tagged with the downstream service, method, URI template, status code and outcome, using the template such as /items/{id} rather than the real path, because real ids would create millions of metric series. Logs are structured, with the same tags and the trace id, and the library redacts sensitive data by default: Authorization and Cookie headers, query parameters named like token or key, and request bodies unless explicitly enabled at debug level in non-production environments.

6Central TLS and Overrides

TLS settings come from the platform, not from each team. The library loads trust stores and client certificates for mutual TLS from a standard location that the platform rotates, enforces a minimum TLS version of 1.2 with 1.3 preferred, and never offers a switch to disable certificate validation in production configuration. When certificates rotate, clients pick up the new ones without code changes. Spring Boot's SSL bundles are a good mechanism for this in Spring applications.

Finally, everything is overridable, because downstreams differ: a reporting service may legitimately need a 30 second timeout, and a payment call may need no retries. Overrides are explicit, per client in configuration or per call through a small options object, and visible in code review and in a startup log that prints each client's effective settings. The rule is simple: the defaults are safe, and changing them is a deliberate, visible act.

7Follow-up questions

Why not let each team pick its own settings from scratch?

Because the defaults of most HTTP engines, such as unlimited read timeouts or small pools, are exactly what cause cascading failures, and each team would discover that in production. A shared library spreads one tested set of defaults and one set of telemetry, so incidents look the same everywhere and fixes reach everyone.

How do retries interact with the circuit breaker?

Retries happen inside the breaker's view: each attempt counts as a call, and when the breaker opens, retries stop immediately because further attempts fail fast. The retry budget and the deadline also cap the total, so the two never combine into a storm.

How do we roll out a change to the defaults?

Version the library, publish the change with release notes, and roll it out through the normal dependency update process with the effective settings logged at startup. For risky changes such as a shorter timeout, ship it first as an opt-in flag, watch the metrics in a few services, then make it the default.

8Conclusion

In this answer, we designed a shared HTTP client library whose defaults prevent the usual incidents: explicit connect, request and pool acquisition timeouts with a deadline across retries, retries only for idempotent requests with exponential backoff, full jitter, a cap and a retry budget, and a circuit breaker and bulkhead per downstream. It adds trace headers, metrics per host and status and redacted structured logs, manages TLS and trust stores centrally, and allows explicit, visible overrides per client or per call.

What to say in the interviewAbout 90 seconds aloud

Open with

I would build it as a thin starter over Spring's RestClient and a pooled engine like Apache HttpClient, configured per downstream service by name, so a team only declares a base URL and an @HttpExchange interface.

Then, if they want more

The defaults are where the value is. Timeouts: always three of them, a connect timeout around one second, a request timeout around two seconds that teams tune per downstream, and a short pool acquisition timeout, a few hundred milliseconds, so a full pool fails fast instead of queueing. Plus a deadline across retries and a per-host pool limit.

Retries only for idempotent requests, GET, PUT, DELETE, or POST with an idempotency key, only on temporary failures like connection errors and 503, with exponential backoff, full jitter, a cap of about two seconds, at most three attempts, and a retry budget of around 10 percent so a failing downstream does not get a retry storm.

Then a circuit breaker and a bulkhead per downstream, with Resilience4j, so one slow service cannot take every thread. For observability, trace headers on every call, metrics tagged by service, method, URI template and status, and structured logs that redact Authorization headers and tokens.

TLS versions, trust stores and client certificates come from central platform configuration with rotation, and there is no switch to disable validation. Everything can be overridden per client or per call, but explicitly and visibly, and the effective settings are logged at startup.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Design a shared HTTP client library used by many teams for calling internal services....": https://scrivio-interview-library.netlify.app/java/networking/138e43d935/