Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

Would you publish shared HTTP interface client libraries for each service so consumers just add a dependency? Discuss the coupling and versioning consequences.

Shared client libraries remove duplicated code and give every consumer the same defaults, but they tie consumers to the provider's release cycle and can hide a breaking API change behind what looks like a routine library upgrade. Consumer-owned clients, often generated from the provider's OpenAPI spec, keep teams independent at the cost of some duplication. If I did publish shared clients, I would keep them thin (the interface and DTOs only), version them semantically, avoid pulling in framework dependencies, and still require contract tests, because a shared library does not prove the two sides agree.

Why this question is asked

When a company has dozens of services, the same client for the orders API gets written five times, each with slightly different DTOs and timeouts. Publishing an official client per service looks like the obvious fix, and it often is a good one, until a library upgrade breaks three consumers or forces them onto a new Spring version. Interviewers ask this design question because it is really about coupling between teams, and the right answer depends on how the organisation releases software. In this answer, we will recap what a shared client library is, look at what it gives us and what it costs, compare it with consumer-owned and generated clients, and then design a shared library that keeps the benefits while limiting the coupling.

1A Quick Recap: What Is Being Shared

With Spring's HTTP interface clients, a client for a service is an annotated Java interface plus the classes for its requests and responses, the DTOs (data transfer objects, plain classes or records that mirror the JSON). The provider team, the team that owns the orders service, could publish these as a Maven artifact such as orders-client 2.3.0. Consumers add the dependency, create the proxy, and call methods instead of writing URLs and JSON mapping themselves.

Coupling here means how much a change on one side forces work on the other. Every API has some coupling, because both sides must agree on the contract. The question is whether we add more through a shared binary: its release schedule, its transitive dependencies and its compiled types.

2What a Shared Client Gives Us

The benefits are real. The provider knows its API best, so its client has the right paths, the right DTOs and sensible defaults: a 2 second timeout that matches the service's latency, retries only on the idempotent methods, the correct header for tenant id. Consumers do not repeat that work, and a fix to the client reaches everyone on their next upgrade. Onboarding a new consumer takes minutes, and the IDE shows every operation the API offers.

3What It Costs: Coupling and Hidden Breaking Changes

The costs appear over time. The first is release coupling. A consumer that needs a new field must wait for the provider to release a new client version, and the provider must think about every consumer when it releases one. The second is hidden breaking changes. Suppose the provider renames a JSON field and releases orders-client 3.0.0 with the updated DTO. Consumers who upgrade compile fine if they did not use that field, but consumers still on 2.x now fail at runtime against the new service. The API broke, but because it arrived as a library upgrade, nobody treated it as an API change.

The third is dependency weight. If the client library depends on a specific Spring Boot version, Resilience4j and a logging setup, every consumer inherits them. When two shared clients need different Spring versions, the consumer faces a version conflict it did not create, often called dependency hell.

Java
// orders-client 2.x DTO, compiled into the consumer
public record Order(String id, BigDecimal total) {}
// Provider renames "total" to "amount" in the API and ships orders-client 3.0.0.
// Consumer still on 2.x, service already on the new API:
Order o = ordersClient.get("A-17");
System.out.println(o.total()); // null: the JSON now has "amount", and Jackson left total unset

Notice that nothing failed loudly. The library made the consumer believe its contract was the provider's contract, and the drift showed up as wrong data. A contract test would have caught it before release.

4Comparing the Options

There are three main ways to give consumers a client, and each moves the cost to a different place.

Ways to give consumers a client
ApproachGainsCosts
Provider-published client libraryone correct client, shared defaultsrelease coupling, transitive dependencies
Consumer-owned handwritten clientfull independenceduplicated effort, drifting defaults
Generated from the provider's OpenAPIshared contract, own dependenciesgenerator quirks, spec must stay accurate
Thin shared library (interface + DTOs)shared types, little baggagestill versioned; needs discipline

Generated clients sit in the middle. The provider publishes an OpenAPI spec, a machine-readable description of every endpoint and schema, and each consumer generates its own client from it at build time, choosing its own versions of Spring and Jackson. The contract is shared, but the binary is not. The duplication is generated rather than handwritten, so it costs little to maintain.

5Designing a Thin Shared Library

If we choose to publish shared clients, we keep the library as small as possible. It contains the @HttpExchange interface and the DTOs, nothing else. It does not create beans, configure timeouts or choose an HTTP library; the consumer builds the proxy from its own RestClient, so it controls timeouts, metrics and authentication. Its only dependencies are spring-web for the annotations and, if needed, Jackson annotations, both declared as provided or compile-only so they do not force versions on the consumer.

We version it semantically: a patch for fixes, a minor version for additions such as a new optional field or endpoint, and a major version only when the API itself breaks. Breaking API changes go through a new API version, such as /v2, with the old one kept alive for a published period, so consumers can upgrade on their schedule. DTOs are tolerant readers: they ignore unknown JSON properties, so the provider can add fields without breaking old clients.

Java
// orders-client: the whole library
@HttpExchange("/v2/orders")
public interface OrdersClient {
@GetExchange("/{id}") Order get(@PathVariable("id") String id);
}
@JsonIgnoreProperties(ignoreUnknown = true) // new fields from the provider do not break old clients
public record Order(String id, BigDecimal amount, String status) {}
// Consumer side: its own RestClient, its own timeouts
OrdersClient orders = HttpServiceProxyFactory
.builderFor(RestClientAdapter.create(myRestClient)).build()
.createClient(OrdersClient.class);

6Contract Tests Are Still Necessary

A shared library proves that consumers compiled against some version of the contract. It does not prove that the running provider still honours it. So we keep contract tests either way. In consumer-driven contract testing, with tools such as Pact or Spring Cloud Contract, each consumer records the requests it makes and the responses it relies on, and the provider's build verifies every recorded contract before release. The renamed field from earlier would fail the provider's build, before any consumer saw null.

My choice for most organisations is generated or thin shared clients, plus consumer-driven contract tests, plus a policy of additive changes and versioned APIs. That keeps the convenience without letting a library upgrade become a silent API break.

7Follow-up questions

Should the shared client include retries and circuit breakers?

I would not put them in the library. The right retry and fallback depend on the consumer's use case and deadline: a batch job can wait, a checkout page cannot. The library can document recommended settings, but the consumer configures them on its own RestClient or around its calls.

What do you do when a consumer is stuck on an old client version?

That is a sign the provider coupled too much into the library. With additive API changes and tolerant DTOs, an old client keeps working against a new provider, so being behind is safe. For real breaking changes, we keep the old API version alive for an announced period and track which consumers still call it through access logs or metrics.

How do generated clients fit with HTTP interface clients?

OpenAPI generators can produce Spring HTTP interface style interfaces as well as other client styles, depending on the generator and its options, so check your generator version. The consumer then builds the proxy exactly as with a handwritten interface.

8Conclusion

In this answer, we saw that shared client libraries reduce duplication and give consistent defaults, but couple consumers to the provider's releases and dependencies and can hide a breaking API change inside a library upgrade. Consumer-owned clients, ideally generated from the OpenAPI spec, keep teams independent at the cost of some duplication. If we share, we keep the library thin, with only the interface and tolerant DTOs, version it semantically, leave configuration to the consumer, and keep consumer-driven contract tests, because only they prove that the running provider still matches what consumers expect.

What to say in the interviewAbout 80 seconds aloud

Open with

I see the appeal: the provider knows its API, so a published client gets paths, DTOs and defaults right, and nobody writes the same client five times. But a shared library couples teams in two ways.

Then, if they want more

Consumers wait for the provider's releases to get changes, and the library drags in its dependencies, so two clients needing different Spring versions create conflicts the consumer did not cause. Worse, a breaking API change can arrive disguised as a library upgrade: if the provider renames a field, consumers on the old version silently get nulls.

The alternative is consumer-owned clients, ideally generated from the provider's OpenAPI spec, which share the contract but not the binary. If we do share, I would keep the library thin: only the @HttpExchange interface and DTOs that ignore unknown properties, no bean configuration, no timeouts, no transitive framework versions, with the consumer building the proxy from its own RestClient.

Version it semantically, make API changes additive, and put real breaks behind a new API version that stays alive for a while. And either way I would keep consumer-driven contract tests, with Pact or Spring Cloud Contract, verified in the provider's build, because a shared library proves the code compiles, not that the running service still matches.

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 "Would you publish shared HTTP interface client libraries for each service so consumers...": https://scrivio-interview-library.netlify.app/spring-boot/http-clients/cb97cf35a1/