Quick revision
The short answer
We redesign the library so that its HTTP client stops being every service's problem. It should have as few transitive dependencies as possible, using the JDK's own java.net.http.HttpClient or a small pluggable transport interface, and it should keep third-party types out of its public API so the implementation can change or be shaded. Its versions should follow the company's platform BOM instead of pinning its own, its releases should use semantic versioning with the previous major maintained for a while, and every release should pass consumer compatibility tests first.
What to remember
In this answer, we saw that the library breaks services because its private choice of HTTP client becomes part of every service's classpath, and sometimes of every service's code. The redesign removes that coupling: the JDK HttpClient or a pluggable transport instead of a pinned dependency, only the library's own types in its public API, versions taken from the platform BOM, semantic versioning with API checks and a supported previous major, and consumer tests before every release.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We redesign the library so that its HTTP client stops being every service's problem. It should have as few transitive dependencies as possible, using the JDK's own java.net.http.HttpClient or a small pluggable transport interface, and it should keep third-party types out of its public API so the implementation can change or be shaded. Its versions should follow the company's platform BOM instead of pinning its own, its releases should use semantic versioning with the previous major maintained for a while, and every release should pass consumer compatibility tests first.
Why this question is asked
A shared client library is meant to save effort, but when every upgrade breaks some service it does the opposite: teams pin old versions, security fixes stall and the platform team spends its time on support. Interviewers ask this design question at senior level because the answer is less about HTTP and more about how to design a dependency that many teams can live with. In this answer, we will see why the current design causes conflicts, then go through each part of the redesign: fewer dependencies, a clean public API, alignment with the platform BOM, versioning and support, and compatibility testing before release.
1Why the Current Library Breaks Services
The library depends on a specific version of a popular HTTP client, say Apache HttpClient 5.2 or OkHttp 4. That client becomes a transitive dependency of every service that uses the library. Many services also use the same HTTP client directly, or through other libraries, at their own versions. The build tool must choose one version for the whole service, so each library upgrade can silently change the HTTP client version for the service, or the service's own choice can change it for the library. Either way, something compiled against one version runs against another.
It gets worse if the library's public methods take or return the HTTP client's types, for example accepting a configured CloseableHttpClient or returning its response object. Then the services' own code is compiled against those types too, and an upgrade of the HTTP client inside the library is a breaking change for every caller.
- Service codeuses the library and sometimes the HTTP client directly
- Internal client library 3.xpublic API returns the HTTP client's response type
- Popular HTTP client, pinned versionpulled in transitively by every service
- One version chosen per serviceby nearest-wins in Maven or highest-wins in Gradle
4 layers, from the top down. Step through them one at a time.
The library's private choice of HTTP client becomes every service's classpath problem.
2Minimise Transitive Dependencies
The cheapest dependency to manage is the one we do not have. Since Java 11, the JDK includes java.net.http.HttpClient, which supports HTTP/1.1 and HTTP/2, synchronous and asynchronous calls, and timeouts. For most internal clients it is enough, and it cannot conflict with anything, because it comes with the JVM.
If some services genuinely need a different transport, for example because they use Spring's RestClient with its observability and its own configured HTTP client, we make the transport pluggable. The library defines a small interface for sending a request, ships a default implementation on the JDK client, and lets consumers supply their own. Optional adapters for other clients live in separate modules, so a service only pulls in the adapter it chooses.
Notice that the library's core module now has no HTTP client dependency at all. The same thinking applies to JSON: if the library parses responses, either use the version the platform BOM manages or keep the parsing behind the library's own types.
3Keep Third-Party Types Out of the Public API
The public API is everything a caller can see: method parameters, return types, exceptions and annotations. If all of these are the library's own types, such as records like TransportRequest and exceptions like TransportException, then the library can change its HTTP client, upgrade it, or even shade and relocate it without breaking any caller's code. The callers never compiled against it.
In Gradle, this split is explicit: the java-library plugin separates api dependencies, which leak to consumers' compile classpath, from implementation dependencies, which do not. Keeping the HTTP client in implementation means consumers cannot accidentally write code against it. In Maven there is no such separation, so we enforce it with review and with architecture tests, for example an ArchUnit rule that public classes in the library's API package do not depend on org.apache.hc or okhttp3.
4Align With the Platform BOM
Many companies keep a platform BOM, a bill of materials that fixes the versions of common libraries for all services, often built on Spring Boot's own dependency management. A shared library should not fight it by pinning its own versions of Jackson, Netty or an HTTP client. Instead, it should build and test against the BOM's versions and declare its dependencies without versions, so that when the platform moves, the library moves with it.
So a library release is tested against the current BOM, and the BOM release notes say which library versions it supports. Services then upgrade one thing, the BOM, and get a consistent set where the library and its dependencies were already tested together.
5Versioning and Supporting the Previous Major
Semantic versioning gives every number a meaning: a patch release fixes bugs, a minor release adds features without breaking callers, and a major release may break them. That only helps if we honour it, so we use a tool such as japicmp or revapi in the library's build to compare the API with the previous release and fail if a minor release contains a breaking change.
When a major release is unavoidable, we keep the previous major alive for a fixed period, for example six months of security and critical fixes, and publish a migration guide. That gives service teams time to plan the upgrade instead of being forced into it by a CVE.
6Test Consumers Before Releasing
The final safeguard is to find breakage before the services do. Before each release, a CI job builds a set of representative consuming services, or all of them if the company's build system allows, against the candidate version of the library and runs their tests. Consumer-driven contract tests, such as those written with Spring Cloud Contract or Pact, also help when the library wraps a remote API: the consumers' expectations are checked automatically.
If a consumer breaks, we learn it in the library's pipeline, where the change is still small and fresh, instead of in a service team's pipeline weeks later.
- Build the library against the platform BOMno pinned versions of shared libraries
- API compatibility check against the last releasejapicmp or revapi
- Breaking change in a minor release?Yesfail the buildNocontinue
- Build representative consumers with the candidaterun their tests and contract tests
- Release and update the BOMservices upgrade one thing
5 steps in order. Play them, or step through them one at a time.
7Follow-up questions
Why not shade the HTTP client inside the library and be done?
Shading removes the version conflict, and it can be a good short-term step. But it makes every service carry its own copy, it hides the client from vulnerability scanners that match on coordinates, and the platform team must re-release the library for every HTTP client security fix. It also only works if the client's types are not in the public API. Removing the dependency or making it pluggable fixes the cause instead.
How do you migrate existing services that use the old API?
We release the new design as a new major version alongside the old one. We can provide an adapter module that implements the old API on top of the new one, publish a migration guide with before and after code, and, where possible, offer an OpenRewrite recipe that rewrites the common calls automatically. We keep the old major supported for an agreed period and track adoption.
What would you do if a team insists on using a specific HTTP client?
That is exactly what the pluggable transport is for. The team plugs its client in through an adapter, either one we ship as an optional module or one they write against the small Transport interface, and the library itself stays independent of that choice.
8Conclusion
In this answer, we saw that the library breaks services because its private choice of HTTP client becomes part of every service's classpath, and sometimes of every service's code. The redesign removes that coupling: the JDK HttpClient or a pluggable transport instead of a pinned dependency, only the library's own types in its public API, versions taken from the platform BOM, semantic versioning with API checks and a supported previous major, and consumer tests before every release.
Open with
The root problem is that the library's HTTP client becomes a transitive dependency of every service, and if its types appear in the library's API, every service is compiled against it too.
Then, if they want more
So I would redesign around coupling. First, minimise dependencies: use the JDK's java.net.http.HttpClient by default, which cannot conflict with anything, and define a small Transport interface so teams that need RestClient or another client can plug in an adapter from an optional module.
Second, keep third-party types out of the public API, using our own request, response and exception types, so the implementation can change or be shaded freely; in Gradle I would keep the client as an implementation dependency, and I would add an ArchUnit rule to enforce it.
Third, stop pinning versions in the library and build it against the company's platform BOM, so services upgrade one BOM and get a tested set. Fourth, use semantic versioning with an API compatibility check such as japicmp in the build, and support the previous major for, say, six months with a migration guide.
Finally, before each release, build representative consumer services against the candidate and run their tests and contract tests, so breakage shows up in the library's pipeline rather than theirs.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 11
- 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.
- Official documentation
- Apache Maven guides, Gradle user manual
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 "Your company's services all embed the same internal client library, which itself depends...": https://scrivio-interview-library.netlify.app/java/dependency-and-supply-chain/1f735efa3c/