API Clients, Servers, and Network Boundaries Explained
Understand what API clients and servers each own, how network boundaries fail, and how timeouts, retries, and trust boundaries shape reliable integrations.
API clients and servers communicate across a network that can lose requests or replies at any hop. This guide maps responsibilities across clients, gateways, and servers, then explains how deadlines, cancellation, bounded retries, and idempotency handle partial failures. It also covers proxy-header trust, server-side authorization, and tracing across service boundaries. Apply these practices to build integrations that fail clearly and recover without duplicating work.
API Clients, Servers, and Network Boundaries Explained
Introduction
An API call crosses a boundary between independently running programs. The client sends a request; the server checks it, performs the work, and returns a response. A reply can disappear after the server finishes. The client then knows only that no response arrived; it cannot tell whether the operation succeeded.
Treat a request as several network steps rather than one infallible function call. For HTTP mechanics, see the HTTP and HTTPS protocol guide.
What belongs on each side
Each side has different responsibilities, and only the server can enforce rules against an untrusted caller.
| Component | Owns | Trust boundary |
|---|---|---|
| Client | Collects input, sends requests, handles timeouts, and presents results | Treat all client input and client-side checks as untrusted |
| Gateway | Routes requests, applies shared limits, and forwards validated proxy metadata | Trust forwarded headers only when a configured proxy sets or sanitizes them |
| Server | Authenticates callers, authorizes resource access, validates input, and applies business rules | Enforce permissions and data rules even when the client already checked them |
Client validation can make a form easier to use, but it cannot protect server data. The server must repeat validation and make the final authorization decision for every request.
A write can commit after the caller gives up
Consider a POST /orders request with an eight-second overall budget and a three-second per-attempt deadline. These times are illustrative; production deadlines should come from the operation’s latency needs and measurements. The order service commits the database transaction, but the first response is lost:
sequenceDiagram
participant C as Client
participant G as Gateway
participant S as Order service
participant D as Database
C->>G: POST /orders (attempt: 3 s, overall: 8 s, key: K-42)
G->>S: Forward request with remaining budget
S->>D: Insert order
D-->>S: Transaction committed
S-->>G: 201 Created
Note over G,C: Response is lost; attempt 1 times out after 3 s; 5 s remain overall
G--xC: Client stops waiting; outcome is unknown
C->>G: Retry POST with the same key K-42
G->>S: Forward retry within remaining overall budget
S->>D: Find K-42; do not insert another order
D-->>S: Return the original result
S-->>G: 201 Created (original order)
G-->>C: 201 Created (original order)
The retry is safe only if this API stores and enforces the idempotency key. Without that behavior, a repeated POST can create a second order. The client knows the response did not arrive; it cannot tell from the timeout whether the database commit happened. When the API does not support safe replay, check the operation’s status or reconcile before trying the write again. HTTP defines idempotent methods separately from non-idempotent ones; see RFC 9110, Section 9.2.2.
Propagating deadlines across service hops
A per-hop timeout limits one operation; an end-to-end deadline limits how long the caller waits for the whole request. A gateway and each downstream service should not each start a fresh full-duration timer. Later hops need to use the remaining budget, including time already spent on earlier work.
Pass the deadline or remaining time through trusted service calls. When the budget expires, the caller stops waiting; cancellation can tell downstream work to stop where the framework and application support it. Cancellation does not undo a database transaction that has already committed, and the application must handle cancellation for work it started. A retry must fit within the caller’s remaining overall budget; once that budget expires, surface the uncertain result instead of silently extending the wait. For gRPC-specific deadline and propagation behavior, see the gRPC deadlines guide.
When to use and when not to use
Use the client-server model for interactive applications, partner integrations, and services where a caller needs a direct answer. Use asynchronous messaging when the sender should not wait for downstream work or when consumers need independent processing. Avoid hiding network calls behind APIs that look like local, infallible function calls; make timeout and error behavior visible in the client code. For a tiny in-process operation, a network API adds needless latency and failure modes.
Trade-Off Table
| Choice | Strength | Cost |
|---|---|---|
| Synchronous HTTP request | Simple request and immediate result | Caller waits and inherits dependency availability |
| Async job with status resource | Decouples long-running work | Requires polling or callback lifecycle |
| Retry with backoff | Recovers from transient faults | Can amplify load if many clients retry together |
| Circuit breaker | Stops repeated calls to a failing dependency | Needs thresholds and careful recovery behavior |
Implementation snippet
A client should use a deadline, a bounded retry policy, and retry only requests that are safe or protected by idempotency:
async function fetchOrder(id: string, signal: AbortSignal) {
const response = await fetch(`/api/orders/${encodeURIComponent(id)}`, {
headers: { Accept: "application/json" },
signal,
});
if (!response.ok) throw new ApiError(response.status, await response.json());
return response.json();
}
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 3_000);
try {
return await fetchOrder("ord_803", controller.signal);
} finally {
clearTimeout(timer);
}
For writes, reuse a stable idempotency key only when the API implements deduplication for that key. Use exponential backoff with jitter for transient errors and stop at the caller’s overall deadline. Do not blindly retry 4xx validation or authorization failures.
Production failure scenarios and mitigations
A slow dependency ties up all application workers. Apply per-hop timeouts, concurrency limits, and load shedding. Clients retry together after a regional outage and create a traffic spike; use jitter, retry budgets, and Retry-After. A gateway forwards a spoofed X-Forwarded-For header from an untrusted network; trust forwarding headers only from known proxies. A network timeout follows a committed write; make the operation idempotent and offer a way to query its result.
Observability checklist
- Measure client-visible latency and server processing time separately.
- Trace requests across gateway, service, and dependencies with a correlation ID.
- Record timeout, cancellation, retry, and circuit-breaker outcomes.
- Alert on saturation and dependency error rates, not only server exceptions.
Security and Compliance Notes
TLS protects data in transit but does not establish that a caller is authorized for a resource. Authenticate and authorize every request at the server, and check permissions against the specific resource being accessed. Validate forwarded host and client IP values only when they come through a trusted proxy that replaces or sanitizes those headers. Keep secrets out of URLs and logs; rotate credentials and scope them to the integration. For regulated or personal data, minimize what crosses the boundary, encrypt it in transit and at rest where stored, and apply access and retention rules to request logs.
Common Pitfalls / Anti-Patterns
- Unlimited retries can multiply load during an outage; set a deadline, retry budget, and jitter.
- Retrying a non-idempotent write can duplicate its effect. Use naturally idempotent operations or an idempotency key.
- Client-side validation improves usability but cannot protect server data; validate and authorize again on the server.
- Trusting
X-Forwarded-Foror host headers from arbitrary callers lets them spoof request metadata. Accept them only from configured proxies. - Treating a timeout as proof that no change happened can trigger duplicate work. Query the operation result or safely replay it with the same idempotency key.
Quick Recap Checklist
- Set connection and request deadlines that fit the user-facing operation.
- Retry only transient failures, with a bounded budget and jitter.
- Protect retried writes with idempotent behavior or an idempotency key.
- Enforce authorization on the server and correlate calls with request IDs and traces.
Interview Questions
Further Reading
- Retries, Timeouts, Backoff, and Circuit Breakers — build bounded retry behavior around deadlines.
- Google SRE: Addressing Cascading Failures — How overload, retries, and dependency failures can spread through a system.
- W3C Trace Context — A standard for propagating trace context across service boundaries.
- MDN: Forwarded header — Standardized proxy metadata and client address forwarding.
Conclusion
The network may return no answer even after a write succeeds. Set deadlines, bound retries, and enforce trust and idempotency on the server. Continue with Idempotency, Deduplication, and Safe Replays to design the server behavior that makes a repeated write safe.
Category
Related Posts
Consistent Hashing for Load Balancing
Learn how consistent-hash rings, virtual nodes, and bounded-load policies reduce reassignment, and when sticky sessions still make sense.
Forward and Reverse Proxies: Routing, Trust, and Use Cases
Learn how forward and reverse proxies handle HTTP traffic, CONNECT tunnels, TLS termination, caching, routing, trusted headers, and production failures.
Network Ports and Firewalls
Learn how TCP and UDP ports, listening sockets, and firewall rules shape backend reachability, with practical examples for safer production deployments.