Scrivio Interview library
ScenarioAdvanced7 min read · updated 12 November 2026

You must migrate 150 services from one HTTP client library to another over a year. How can the adapter pattern help, and how do you avoid leaving a permanent extra layer?

I would introduce a small internal interface that covers only the HTTP operations our services actually use, write one adapter over the old client and one over the new, and move call sites to the interface with automated refactoring. Each service then switches adapters by configuration, which allows canaries and instant rollback, while we compare error rates and latency between the two. To avoid a permanent extra layer, we set a removal date for the old adapter up front and decide explicitly whether the interface stays or services call the new client directly.

Why this question is asked

Library migrations across many services are among the slowest projects in an engineering organisation: 150 services means 150 owners, 150 release schedules and many subtle differences in timeouts, redirects and connection pooling. Done as a single cut-over, one difference becomes an outage; done without a plan, the migration never ends and leaves a wrapper nobody understands. Interviewers ask this to see whether we can use a pattern as a migration tool and also know when to take it away again. In this answer, we will recap the adapter idea for this case, design the interface, switch by configuration, compare the two clients during rollout, automate the code changes, and plan the end.

1A Quick Recap: Why an Adapter Helps

An adapter implements an interface a client expects and translates calls to another class underneath. Here the clients are our services, and we have two classes underneath, the old HTTP client library and the new one. If services depend on our interface instead of either library, switching libraries becomes a choice of which adapter to create, not a code change in 150 places at once.

The adapter also isolates the behaviour differences. Libraries differ in default timeouts, whether they follow redirects, how they pool connections, which exceptions they throw and how they encode headers. Each difference is handled once, inside the new adapter, instead of being rediscovered by each team.

2Designing a Small Internal Interface

The interface should cover what services actually do, which we find by searching the code for usages of the old client, not everything HTTP can do. In most code bases that is sending a request with a method, URL, headers and body, getting a status, headers and body back, and setting a timeout.

Java
public interface HttpTransport {
HttpResult send(HttpCall call);
}
public record HttpCall(String method, URI uri, Map<String, String> headers, byte[] body, Duration timeout) {}
public record HttpResult(int status, Map<String, List<String>> headers, byte[] body) {}
final class OldClientTransport implements HttpTransport { /* wraps the old library */ }
final class NewClientTransport implements HttpTransport {
private final HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(2))
.followRedirects(HttpClient.Redirect.NEVER) // match the old library's behaviour explicitly
.build();
public HttpResult send(HttpCall c) {
HttpRequest.Builder b = HttpRequest.newBuilder(c.uri()).timeout(c.timeout())
.method(c.method(), HttpRequest.BodyPublishers.ofByteArray(c.body()));
c.headers().forEach(b::header);
try {
HttpResponse<byte[]> r = client.send(b.build(), HttpResponse.BodyHandlers.ofByteArray());
return new HttpResult(r.statusCode(), r.headers().map(), r.body());
} catch (IOException e) {
throw new TransportException("call failed: " + c.uri().getHost(), e); // one exception type for both adapters
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new TransportException("interrupted", e);
}
}
}

Here the new client is the JDK's java.net.http.HttpClient as an example; the same shape works for any target library. Notice that both adapters throw the same TransportException, so service code handles failures one way no matter which library is underneath. A small interface also keeps the adapters short, which matters because short adapters are easy to delete later.

3Switching by Configuration, With Canaries and Rollback

Each service creates its HttpTransport from a configuration property, for example http.transport=old or new. A team changes the property, deploys to one canary instance, watches it, and then rolls out to all instances. If something goes wrong, it flips the property back without a code change or a new build, which takes minutes instead of hours.

Java
@Bean
HttpTransport httpTransport(@Value("${http.transport:old}") String which) {
return switch (which) {
case "new" -> new NewClientTransport();
case "old" -> new OldClientTransport();
default -> throw new IllegalArgumentException("unknown http.transport " + which);
};
}
// canary instance: http.transport=new, others still old
// rollback: set it back to old and restart or refresh
Step throughRolling one service to the new client
  1. Move call sites to HttpTransportautomated refactoring, no behaviour change yet
  2. Deploy with transport=new on one canary
  3. Error rate and p99 latency within limits?compared with the old adapter on the other instances
    YesRoll out to all instancesNoFlip back to old and investigate
  4. Run on new for two weeks
  5. Remove the old adapter from this serviceby the agreed removal date

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

A per-call-site switch, for example new for internal calls and old for a fragile partner API, is possible but adds complexity; per service is usually enough.

4Comparing the Two Adapters During Rollout

Because every call goes through our interface, both adapters can record the same metrics with a tag naming the adapter: request count, error count by type, and latency percentiles per target host. On the dashboard, the canary's new adapter sits next to the old adapter on the other instances, under the same traffic. Differences show up quickly: a higher p99 latency often means a smaller connection pool or no connection reuse, more timeouts often mean a different default timeout, and new 3xx errors mean redirects are handled differently.

We agree limits before rollout, for example error rate no more than 0.1 percentage points higher and p99 latency no more than 10 percent higher, so the decision to continue or roll back is not a debate each time.

5Automating the Code Changes

Moving call sites from the old library to HttpTransport is the bulk of the work, and doing it by hand in 150 services is slow and error-prone. A refactoring tool such as OpenRewrite can apply a custom recipe that rewrites the common call patterns across all repositories and opens pull requests automatically. The unusual call sites, perhaps 10 percent, are left for teams to convert by hand with a guide. The platform team runs the recipe and tracks which services are still on the old library.

6Avoiding a Permanent Extra Layer

Here is the trap: once everything works through the interface, nobody has a reason to remove the old adapter, and five years later there is a homemade HTTP abstraction that hides features of the new library. So the end is planned at the start. The old adapter has a removal date, for example three months after the last service moves, after which it is deleted from the shared library and its dependency dropped.

The interface itself needs an explicit decision. If it adds value, such as consistent tracing, auth headers and metrics, we keep it as a deliberate, owned part of the platform. If it was only a migration bridge, we use a second recipe to replace HttpTransport calls with direct calls to the new client, and delete the interface too. Both are fine; what is not fine is keeping it by accident.

7Follow-up questions

Why not just let each team migrate directly to the new client?

Because each team would rediscover the same behaviour differences, rollback would need a code change and a redeploy, and nobody could compare the two clients side by side. The adapter turns 150 risky rewrites into one carefully tested adapter plus a configuration flag per service.

What if some services use advanced features of the old client, such as custom interceptors?

List those uses first. Common ones become part of the interface or of the adapter's built-in behaviour, such as auth headers. Rare ones are handled by the team with direct use of the new client, documented as exceptions, so the interface does not grow to cover everything.

How do you decide the removal date?

Set it relative to measurable progress, for example three months after the last service reports transport=new in production, and publish it at the start so teams plan for it. Track the remaining services on a dashboard visible to everyone.

8Conclusion

In this answer, we used the adapter pattern to migrate 150 services between HTTP client libraries. A small internal interface covers the operations services need, with adapters for the old and new clients that hide their differences. Services switch by configuration, which allows canaries and quick rollback, while metrics compare error rates and latency between the adapters. Automated refactoring moves call sites, and a removal date for the old adapter plus an explicit decision about the interface keeps the bridge from becoming a permanent layer.

What to say in the interviewAbout 90 seconds aloud

Open with

I'd use the adapter as a migration bridge with a planned end. First, find what services actually do with the old client and define a small internal interface for just that, sending a request and getting status, headers and body, with one exception type.

Then, if they want more

Then write two adapters, one over the old library and one over the new, and make the new one reproduce the old behaviour explicitly, things like timeouts, redirects and connection pooling.

Moving call sites to the interface is done with an automated refactoring tool like an OpenRewrite recipe that opens pull requests across the repositories, with teams handling the unusual cases.

Each service then picks the adapter with a configuration property, so a team can put the new adapter on one canary instance, compare error rates and p99 latency against the old adapter under the same traffic with agreed limits, and either roll out or flip back in minutes.

To avoid a permanent layer, I'd publish a removal date for the old adapter at the start, say three months after the last service moves, and make an explicit decision about the interface: keep it as an owned platform component if it adds tracing and auth consistently, or run a second recipe to call the new client directly and delete it.

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 "You must migrate 150 services from one HTTP client library to another over a year. How...": https://scrivio-interview-library.netlify.app/java/structural-patterns/59fa6e0359/