Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

Dozens of Dropwizard services call each other with hand-built clients. Design a standard client library for them.

I would build one small internal library, a configuration class plus a builder, that turns a few lines of YAML into a client with safe defaults: bounded timeouts and pools, retries only for idempotent calls, W3C trace context and correlation id propagation, per-client metrics, a circuit breaker and bulkhead, and one standard mapping from HTTP status codes to exceptions. It is versioned through the platform BOM so every service upgrades the same way.

Why this question is asked

When dozens of teams each hand-build their HTTP clients, every outage teaches the same lesson again: one client had no read timeout, another retried a payment, a third dropped the trace header so nobody could follow the request. A shared library fixes those problems once. Interviewers ask this to see whether we can turn incident experience into a design that teams actually adopt. In this answer, we will look at what goes wrong with hand-built clients, design the configuration and builder, add tracing and metrics, add resilience, define error mapping, and plan versioning and adoption.

1What Goes Wrong With Hand-Built Clients

A Dropwizard service already has the dropwizard-client module, which can build an Apache HttpClient or a Jersey client from a configuration object. The problem is not the lack of a tool. It is that each team fills in that configuration differently, adds its own retry loop, and forgets the parts that only matter on a bad day.

When we audit such an estate we usually find the same pattern: some clients with no read timeout at all, retry loops that retry POST requests, clients that do not forward the trace header so the distributed trace stops at that hop, and error handling where one service throws on 404 and another returns null. Each of these is small, but together they decide how far one slow service can spread its trouble.

2Designing the Configuration Class and Builder

The heart of the library is a configuration class that services embed in their own Dropwizard configuration, and a builder that turns it into a ready client. The defaults are the important part, because most teams never change them.

Java
# order-service config.yml
customers:
baseUrl: https://customers.internal
timeout: 1s # read timeout
connectTimeout: 200ms
poolWaitTimeout: 100ms # connectionRequestTimeout
maxConnectionsPerRoute: 64
retry: { maxAttempts: 2, backoff: 100ms } # applied only to idempotent methods
circuitBreaker: { failureRate: 50, window: 100, openFor: 30s }
bulkhead: { maxConcurrent: 32 }
// in OrderApplication.run()
PlatformClient customers = PlatformClients.builder(environment, "customers")
.config(config.getCustomers())
.build();
Customer c = customers.get("/customers/{id}", Customer.class, 42); // GET, may retry once

Notice that every value has a default, so a team that writes only baseUrl still gets a 1 second timeout and a bounded pool. The builder takes the Dropwizard Environment so it can register metrics and lifecycle hooks: the underlying pool is closed when the service stops.

The retry rule deserves care. A retry is safe only when sending the request twice has the same effect as sending it once. GET, HEAD, PUT and DELETE are idempotent by definition, POST is not. So the library retries only idempotent methods by default, and a POST is retried only when the caller supplies an idempotency key header that the server honours. Retries also respect the time budget: two attempts of 1 second each are not allowed if the caller only has 1.5 seconds left.

3Tracing, Correlation and Metrics Built In

Every outgoing call copies the current trace context into the W3C traceparent header (and tracestate when present), so tools such as an OpenTelemetry backend can join the spans of all services into one trace. The library also forwards our correlation id header, which logs use, so a support engineer can search one id across all services.

For metrics, the library registers a timer and counters per client and per status class, with names like client.customers.requests and tags or name parts for method and outcome. With dozens of services using the same names, one dashboard and one alert definition work everywhere. This is a large part of the value: the platform team can see every dependency in the estate in the same shape.

Step throughLayers inside one platform client call
  1. Service codecustomers.get("/customers/{id}", Customer.class, 42)
  2. Error mappingstatus code -> typed exception
  3. Circuit breaker and bulkheadResilience4j, settings from YAML
  4. Retry with budgetidempotent methods only
  5. Tracing and metricstraceparent, correlation id, timers
  6. Pooled HTTP clienttimeouts, pool limits, TLS

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

Each concern lives in one layer, so teams get all of them by calling the builder.

4Resilience: Circuit Breakers and Bulkheads

The library wraps each client in a circuit breaker and a bulkhead, for example from Resilience4j. A circuit breaker watches recent calls and, when too many fail, opens and rejects calls immediately for a while, which gives the struggling service room to recover. A bulkhead limits how many calls to this one dependency can be in flight, so a slow dependency can use at most 32 of our threads instead of all of them.

The settings live in the same YAML block as the timeouts, so changing them is a config change, not a code change. The breaker's state is exported as a metric, which makes an open breaker visible on the shared dashboard instead of hidden in one service's logs.

5A Standard Mapping From Status Codes to Exceptions

Callers should not parse status codes by hand. The library maps them once: 400 and 422 to a ClientRequestException carrying the problem details body, 401 and 403 to an AuthorizationException, 404 to NotFoundException or an empty Optional for methods that declare one, 409 to ConflictException, 429 and 503 to a RetryableException that honours Retry-After, and other 5xx to a RemoteServerException. A timeout or an open breaker becomes a DependencyUnavailableException.

The benefit is that a resource method can let these exceptions propagate, and a shared Jersey exception mapper turns them into sensible responses for our own caller, for example 503 for an unavailable dependency rather than a generic 500. Every service then reports partner failures the same way.

6Versioning and the Upgrade Path

The library ships as part of the platform BOM (bill of materials), the Maven or Gradle file that pins compatible versions of Dropwizard, Jackson, the client library and its dependencies. A service imports the BOM once and gets matching versions of everything, which avoids the classic conflict where two Jackson versions end up on the classpath.

Changes follow semantic versioning: new options with safe defaults in minor versions, breaking changes only in major versions with a migration note and, where possible, an automated rewrite recipe such as an OpenRewrite rule. For adoption, we migrate two or three busy services first, publish the before and after incident numbers, and make the library the default in the service template. Teams move because it is easier, not only because they are told to.

7Follow-up questions

Should the library hide the underlying Jersey or Apache client completely?

Mostly, yes, but with an escape hatch. A narrow API keeps defaults and instrumentation in place, because teams cannot bypass them by accident. A documented method that gives access to the underlying client for rare cases, such as streaming uploads, prevents teams from forking the library when they hit a gap. Usage of that escape hatch is worth tracking, since it shows which features the library still lacks.

How would you roll out new defaults, such as a shorter timeout, without breaking services?

We ship the new default behind a version bump with a release note, and first apply it in shadow: the library logs when a call would have exceeded the new limit without failing it. After a week of data we know which clients need an override, set those explicitly, and then switch the default. That turns a risky global change into a measured one.

Why not use a service mesh for all of this instead?

A mesh can handle timeouts, retries, mutual TLS and some metrics at the network level, and that is a fine complement. But it cannot map errors into typed exceptions, decide which calls are idempotent from business meaning, or propagate application context such as correlation ids reliably. In practice the library and the mesh share the work, and the library must avoid retrying on top of mesh retries, which multiplies attempts.

8Conclusion

In this answer, we designed a shared client library for Dropwizard services. A configuration class and builder give every client safe defaults for timeouts, pools and retries, with retries limited to idempotent calls. Tracing headers, correlation ids and per-client metrics are built in, a circuit breaker and bulkhead come configured from YAML, and one mapping turns status codes into exceptions. The platform BOM versions it, and a clear upgrade path and early wins make teams adopt it.

What to say in the interviewAbout 80 seconds aloud

Open with

I'd build a thin platform library rather than let each team configure clients by hand. Services embed one configuration class in their YAML and call a builder that takes the Dropwizard environment, so they get safe defaults without thinking: a one second read timeout, a short connect and pool wait timeout, bounded pools, and retries only for idempotent methods, or for POST with an idempotency key, always within the caller's time budget.

Then, if they want more

The builder propagates W3C traceparent and our correlation id header and registers per-client timers and status counters with the same names everywhere, so one dashboard covers every dependency. It wraps calls in a Resilience4j circuit breaker and bulkhead configured from the same YAML block.

Errors are mapped once: 404 to not found, 409 to conflict, 429 and 503 to a retryable exception that respects Retry-After, timeouts and open breakers to dependency unavailable, and a shared exception mapper turns those into proper responses for our own callers.

The library is versioned in the platform BOM with semantic versioning and migration notes, and I'd drive adoption by migrating a few busy services first, showing the incident numbers, and making it the default in the service template.

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 official documentation for the version you use. 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 "Dozens of Dropwizard services call each other with hand-built clients. Design a standard...": https://scrivio-interview-library.netlify.app/java/dropwizard/a2cecdafde/