Quick revision
The short answer
Remote proxies make a network call look like a local method call, which hides latency, partial failure and timeouts from the person reading the code, and that has led to chatty designs, remote calls inside loops and remote calls inside database transactions. My guidelines for declarative HTTP clients are: name them clearly as remote clients and keep them in an integration layer, require explicit timeouts, retry only idempotent operations, add circuit breakers, model remote failure explicitly in return types and errors, and review call graphs for remote calls in hot paths.
What to remember
In this answer, we saw that remote proxies, from RMI stubs to declarative HTTP clients, make network calls look local and hide latency, partial failure and timeouts. That has led to chatty interfaces, remote calls in loops and remote calls inside database transactions. The guidelines put the reality back: clearly named clients in an integration layer, explicit timeouts, retries only for idempotent operations, circuit breakers, return types and errors that model remote failure, and reviewing call graphs and traces for remote calls in hot paths.
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.
Remote proxies make a network call look like a local method call, which hides latency, partial failure and timeouts from the person reading the code, and that has led to chatty designs, remote calls inside loops and remote calls inside database transactions. My guidelines for declarative HTTP clients are: name them clearly as remote clients and keep them in an integration layer, require explicit timeouts, retry only idempotent operations, add circuit breakers, model remote failure explicitly in return types and errors, and review call graphs for remote calls in hot paths.
Why this question is asked
Every generation of Java has had a technology that made remote calls look local: RMI stubs, EJB remote interfaces, SOAP clients generated from WSDL, and now declarative HTTP clients such as Spring's @HttpExchange interfaces and OpenFeign. Each time, the convenience was real and the incidents followed the same pattern. Interviewers ask this at a senior level to see whether we recognise the pattern and can turn it into practical rules for teams using today's tools. In this answer, we will recap what a remote proxy is, look at what it hides and the design failures that follow, and then write the guidelines with code.
1A Quick Recap: What a Remote Proxy Is
A remote proxy is a local object that implements an interface and turns each method call into a network request to another process, then turns the response back into a return value. The caller writes inventory.reserve(sku, 2), exactly as it would call a local service. RMI generated stubs that did this over Java's own protocol; EJB remote interfaces did it through the application server; declarative HTTP clients do it from an annotated Java interface.
This is a good tool. The problem is not the code generation; it is that the call site reads like a cheap, reliable, local call, and it is none of those.
2What the Local-Looking Call Hides
A local method call takes nanoseconds, either returns or throws, and never half-succeeds. A remote call takes milliseconds, often 5 to 50 within a data centre and much more under load. It can fail in ways a local call cannot: the request may never arrive, or it may arrive and succeed while the response is lost, so the caller does not know whether the reservation happened. And without a timeout, it can wait almost forever, holding a thread and everything that thread holds.
These are the classic fallacies of distributed computing, such as assuming the network is reliable and latency is zero. A remote proxy makes them easy to forget, because nothing in the code reminds the reader.
| Property | Local method call | Remote call through a proxy |
|---|---|---|
| Latency | Nanoseconds | Milliseconds, more under load |
| Outcomes | Returns or throws | Returns, throws, times out, or unknown |
| Partial failure | Not possible | Request done, response lost |
| Cost of 100 calls in a loop | Negligible | 100 round trips, seconds |
| Looks like at the call site | client.stock(sku) | client.stock(sku), the same |
3The Design Failures That Follow
Three patterns appear again and again. The first is chatty design: an interface with fine-grained methods, such as getName(), getPrice() and getStock() for one product, that would be fine locally but costs three round trips remotely. The second is remote calls inside loops: code that calls stock(sku) for each of 200 items in a cart takes 200 times 20 ms, four seconds, where a single batch call would take 30 ms.
The third is the most dangerous: a remote call inside a database transaction. The transaction holds row locks and a database connection while waiting for the network. If the remote service slows from 20 ms to 5 seconds, every transaction now holds its connection 250 times longer, the connection pool runs out, and our own service fails because of someone else's latency. And if the transaction rolls back after the remote call succeeded, the two systems now disagree.
The fix is to keep remote calls outside transactions: reserve first, then write locally in a short transaction, or write an outbox record in the transaction and call the remote service after commit.
4Guidelines: Make Remote Calls Visible
The first group of guidelines is about readability. Remote clients are named for what they are, InventoryClient or InventoryRemote, never InventoryService, which suggests a local bean. They live in an integration or adapter layer, and the domain depends on a domain interface that the adapter implements, so it is obvious where the network boundary is. Interfaces are designed for the network: coarse-grained, with batch operations such as stock(List<String> skus), rather than mirroring a local object's getters.
5Guidelines: Resilience and Explicit Failure
The second group is about failure. Every client has an explicit connect and read timeout set in its configuration; no defaults, because library defaults are often very long or infinite. Retries are allowed only for idempotent operations, or with an idempotency key for operations like reserve, and are limited with backoff. A circuit breaker stops calling a failing dependency for a while so we fail fast.
Return types and errors model remote failure. Instead of letting a library's exception leak out of the adapter, the adapter translates it into domain errors such as InventoryUnavailable, or returns a result type with an explicit unavailable case, so the caller must decide what to do: degrade, queue the work, or fail the request with a clear message.
Notice that the switch must handle Unavailable, so remote failure is part of the code a reader sees, not an exception someone forgot.
6Guidelines: Review Call Graphs and Hot Paths
Finally, we look at what the code really does at run time. Distributed tracing shows, per request, how many remote calls happen and where; a trace with 40 calls to the same client is a loop that should be a batch call. In design and code review, we check for remote calls inside @Transactional methods and inside loops, and an architecture test can flag classes in the transactional service layer that depend directly on remote client types. A dashboard of calls per request for each endpoint catches regressions before they become incidents.
7Follow-up questions
Are declarative HTTP clients a bad idea, then?
No. They remove boilerplate and keep request mapping consistent. The guidelines simply put back what the local-looking call hides: clear naming, a boundary layer, timeouts, careful retries and explicit failure types.
How do you handle the case where the response is lost and the outcome is unknown?
Design the operation to be idempotent, usually with an idempotency key the caller generates, so it can safely be retried and the server returns the original result. Where that is impossible, record the unknown state and reconcile it later, for example by querying the remote service for the reservation.
What timeout would you choose?
One based on the dependency's measured latency and the caller's own deadline, for example a little above the dependency's p99 and well below the caller's overall budget. If the caller must respond within 1 second and makes two sequential calls, each needs a timeout well under 500 ms.
8Conclusion
In this answer, we saw that remote proxies, from RMI stubs to declarative HTTP clients, make network calls look local and hide latency, partial failure and timeouts. That has led to chatty interfaces, remote calls in loops and remote calls inside database transactions. The guidelines put the reality back: clearly named clients in an integration layer, explicit timeouts, retries only for idempotent operations, circuit breakers, return types and errors that model remote failure, and reviewing call graphs and traces for remote calls in hot paths.
Open with
The core problem with remote proxies, from RMI stubs and EJB remote interfaces to today's declarative HTTP clients, is that the call site looks like a local method call, but the call has milliseconds of latency, can time out, and can partially fail, where the request succeeded but the response was lost.
Then, if they want more
Because readers don't see that, we got chatty interfaces with fine-grained methods, remote calls inside loops, which turn 200 items into 200 round trips, and worst of all, remote calls inside database transactions, where a slow dependency holds our locks and connections and exhausts the pool.
My guidelines for declarative clients would be: name them as clients, like InventoryClient, never as services, and keep them in an integration layer behind a domain interface; design them to be coarse-grained with batch operations; set explicit connect and read timeouts on every client; retry only idempotent operations or ones with an idempotency key, with backoff and limits; add circuit breakers; and translate library exceptions into domain errors or a result type with an explicit unavailable case, so callers have to handle remote failure.
Remote calls stay out of transactions, using an outbox if needed. And in review and with tracing, we look at call graphs for remote calls in loops and hot paths.
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 "Remote proxies, such as RMI stubs, EJB remote interfaces and declarative HTTP clients...": https://scrivio-interview-library.netlify.app/java/structural-patterns/b847509119/