Skip to content
Engineering Networking AI Platforms November 9, 2026

Standardize the Network,
Not the HTTP Client

Why OkHttp is a strong default on the JVM, how it compares with Apache HttpClient 5, Netty, HTTPX and aiohttp, and why a platform of many services should standardize timeouts, retries and tracing rather than one library.

By Serverless Ventures

Published: November 9, 2026  ·  Read time: ~8 minutes

Share Link copied

The short version

  • OkHttp is not just fast. It handles the hard parts of HTTP reliably and the same way every time: connection pooling, HTTP/2, recovery from common network failures, interceptors and streaming.
  • The right client depends on the language. On the JVM, OkHttp is an excellent default. In Python, start with HTTPX. In Go, use the standard net/http. Reach for Netty only when you are building networking infrastructure.
  • For a multi-service AI platform, standardize the behaviour, not the library. Timeouts, retries, circuit breakers, tracing, auth and streaming matter more than OkHttp versus HTTPX.
  • Never blindly retry a POST or an agent action. It may already have run. Use idempotency keys and explicit retry policies.

Why would anyone choose OkHttp?

Picture an AI platform with twenty services talking to each other. Between them they make thousands of HTTP requests: agent-to-agent calls, model inference requests, streamed responses, calls to outside APIs, file uploads and downloads, and long-running connections.

Every one of those requests pays an overhead before any useful work happens. A good HTTP client's job is to pay as little of it as possible, as rarely as possible.

The six steps of an HTTP request, and what a good client skips A cold request runs all six steps: DNS resolution, TCP connect, TLS handshake, send request, receive response, then close or reuse. A request on a pooled connection skips the first three. With HTTP/2 multiplexing, many concurrent requests share one already-open connection. New connection every step, every time 1DNS 2TCP connect 3TLS handshake 4Send request 5Receive 6Close or reuse Pooled connection connection pooling steps 1 to 3 skipped: already connected 4Send request 5Receive 6Back to pool HTTP/2 multiplexing one connection, opened once many requests in flight at once, one connection
The six steps of an HTTP request. Green steps are the useful work; everything else is overhead. When a new connection is unavoidable, TLS session resumption also shortens step 3.

OkHttp optimizes several of these steps, and adds the features you end up building yourself otherwise:

FeatureWhy you care
Connection poolingYou stop paying for DNS, TCP and TLS on every request
HTTP/2 multiplexingMany requests share one connection
Modern TLSConnections are secure and efficient, with sensible defaults
Automatic recoveryIt recovers quietly from common connection problems, such as trying a host's other addresses
InterceptorsAuthentication, logging and metrics live in one place
StreamingLarge responses are read in pieces, not loaded into memory all at once
WebSocketsPersistent, two-way connections
Response cachingIt skips network calls the cache can answer

HTTP/2 multiplexing deserves a special mention. Instead of opening twenty connections to talk to one service, OkHttp can send twenty concurrent requests over a single HTTP/2 connection. That means fewer handshakes, fewer sockets and better use of the connections you already have.

What are the alternatives?

These are the clients worth considering, across the languages an AI platform tends to use:

HTTP clientLanguageMain strengthBest fit
OkHttpJava, KotlinConnection management, HTTP/2JVM and Android applications
Apache HttpClient 5JavaDeep HTTP configurationEnterprise Java systems
Java HttpClientJavaBuilt into the JDKStandard Java applications
Ktor ClientKotlinMultiplatform, coroutine-firstKotlin applications
NettyJavaAsynchronous networking frameworkHigh-performance network software
HTTPXPythonSync and async in one APIPython services
aiohttpPythonAsync client and serverHigh-concurrency Python services
RequestsPythonSimplicityStraightforward API integrations
net/httpGoStandard library, HTTP/2 built inGo microservices
reqwestRustAsync HTTP on TokioRust applications

OkHttp against its closest competitors

OkHttp vs. Apache HttpClient 5

Both are mature JVM clients. The difference is in how much they ask of you.

DimensionOkHttpApache HttpClient 5
HTTP/2YesYes, in the async client
Connection poolingYesYes
AsyncYes, with callbacks (enqueue) beside the blocking executeYes
ConfigurationRelatively simpleExtensive
InterceptorsYesYes
AndroidExcellentNot its focus
Enterprise customizationGoodExcellent
ComplexityLowerHigher

Our preference: OkHttp for straightforward, efficient HTTP. Apache when you need deep enterprise networking customization.

OkHttp vs. Netty

These are not really competitors. Netty is a lower-level asynchronous networking framework; OkHttp is an HTTP client.

DimensionOkHttpNetty
AbstractionHTTP clientNetworking framework
HTTP handlingBuilt inAssembled from codecs and handlers
Connection managementBuilt inMore control, more of your code
Custom protocolsLimitedExcellent
Development effortLowerHigher

Our preference: do not use Netty when all you need is an HTTP client. Use it when you are building networking infrastructure or a custom protocol.

HTTPX vs. aiohttp

Most agent and model code is Python, so this comparison often matters more than any JVM one.

DimensionHTTPXaiohttp
SynchronousYesNo, async only
AsynchronousYesYes
HTTP/2Yes, with the httpx[http2] extraNo, HTTP/1.1 only
API designClose to RequestsIts own
StreamingYesYes
WebSocketsThrough add-ons such as httpx-wsBuilt in, client and server
Also a web serverNoYes
Ease of adoptionExcellentGood

Our preference: HTTPX for general-purpose Python. aiohttp when you specifically want its async client and server together, or its built-in WebSockets.

What we would use across an AI platform

Across a platform like the ones we build, with agent apps, media services, a model runtime and Go infrastructure, we would not standardize everything on OkHttp. We would standardize the networking behaviour and pick the natural client for each language.

ComponentClientWhy
Agentic applications (Python)HTTPXAsync APIs and streaming
Content and media applicationsHTTPXExternal APIs and media services
Agent and tool runtimeWhatever its language usesAgent and tool calls follow the shared standard
Model runtimeHTTPX or the serving stack's native clientModel-serving APIs
Infrastructure services (Go)net/httpNative, efficient networking
JVM servicesOkHttpConnection management and HTTP/2
Kotlin servicesOkHttp or KtorKotlin-friendly networking

One more consideration for LLM work: streaming and server-sent events (SSE) support matter a lot. You do not want to buffer a whole generated response before handing tokens to the application. Whatever client a service uses, check that it can read a response body incrementally and that nothing in the path (a proxy, a gateway, an interceptor) quietly buffers it.

Standardize the network, not the library

Rather than mandate one HTTP library, set one networking standard that every service meets, in whatever language:

1
Connection pooling and reuse, with limits per host
2
Timeouts for connect, read and the whole request, never "wait forever"
3
Retries with exponential backoff and jitter, under an explicit policy
4
Circuit breakers, so one slow dependency does not take everything down
5
Distributed tracing, with trace context passed on every hop
6
Authentication and credentials handled in one place, never per call
7
Streaming support end to end, for tokens, media and large files
8
Request-level observability: latency, status and size for every call

These are bigger architectural decisions than OkHttp versus HTTPX. Write them down once, ship them as a thin shared SDK or wrapper per language, and every new service gets them for free.

A caution on retries

Do not blindly retry POST requests or agent operations. A request that timed out may still have run, and retrying it can create a duplicate job, a second payment or an agent that takes the same action twice. GET, PUT and DELETE are idempotent by definition; POST is not. Give non-idempotent operations an idempotency key that the server checks before doing the work again, and make retry policies explicit per operation rather than a global "retry three times".

The verdict

  • Building JVM services? OkHttp is an excellent choice.
  • Building Python services? Start with HTTPX.
  • Building Go services? Use the standard net/http.
  • Building a high-performance networking framework? Look at Netty.

For a platform of many services, invest in a shared networking SDK and a written standard, not a mandate that every service use the same HTTP client. The client is the easy part to change. Missing timeouts, unsafe retries and invisible requests are what cause incidents. For more on building agent platforms, see Build the Environments, Not the Workforce.

Sources: project documentation for OkHttp, Apache HttpClient 5, Netty, HTTPX, aiohttp, Go net/http and reqwest; idempotent methods as defined in RFC 9110. Recommendations are our own and reflect how we build. Library features change between versions, so check the current docs before you commit.

Share this post Link copied