Persistent HTTP connections: handling multiple requests on one connection
A persistent connection lets multiple HTTP request/response exchanges reuse one network connection. HTTP/1.1 uses persistence by default, avoiding repeated TCP setup. It is not a permanent connection or a guarantee that a request will succeed: servers and networks can close connections at any time.
A persistent connection lets multiple HTTP request/response exchanges reuse one network connection. HTTP/1.1 uses persistence by default, avoiding repeated TCP setup. It is not a permanent connection or a guarantee that a request will succeed: servers and networks can close connections at any time.
HTTP/1.1 default
Unless told otherwise, HTTP/1.1 keeps a connection open after a response. An endpoint that plans to close it can send Connection: close.
GET /first HTTP/1.1
Host: api.example
HTTP/1.1 200 OK
Content-Length: 2
OK
GET /second HTTP/1.1
Host: api.example
HTTP/1.1 200 OK
Content-Length: 2
OKThis simplified example shows sequential requests on one connection. Clients usually manage connection pools, and whether a request uses the same connection depends on the runtime and concurrency. Applications generally do not need to set Connection: keep-alive on every request.
Message boundaries matter
For reuse, both sides must know where every message ends. HTTP/1.1 message bodies need explicit framing, such as Content-Length or Transfer-Encoding. A server that responds before consuming the entire request body must close the connection, or leftover bytes could be mistaken for the next request. Similarly, a client must consume the whole response body before reusing the connection, or close it.
After a connection failure, it may be unclear whether the server processed the request. Do not retry every request blindly. A non-idempotent operation may already have happened, causing duplicate effects. Follow the API’s idempotency policy, consider an idempotency key, and understand automatic retries by the client library or pool.
HTTP/2 is different
HTTP/2 connections are persistent too, but concurrent streams multiplex requests and responses. That differs from sequential reuse in HTTP/1.1. HTTP/2 does not use the HTTP/1.1 Connection header. Clients can open replacement connections, and servers may close idle ones. A GOAWAY frame helps identify streams that might not have been processed during shutdown.
Persistence describes the transport connection; it does not make HTTP application stateful. A server does not automatically remember application state between requests, and a persistent connection is not the same as a login session or database transaction.
Check client pool settings, proxy/load-balancer idle timeouts, retry and idempotency policy, and whether bodies are fully consumed or the connection discarded. Reuse can avoid connection setup costs, but actual gains depend on protocol, network and deployment limits.
HTTP/1.1 example
GET /first HTTP/1.1
Host: api.example
HTTP/1.1 200 OK
Content-Length: 2
OK
GET /second HTTP/1.1
Host: api.example
HTTP/1.1 200 OK
Content-Length: 2
OKSources
[RFC 9112 §9.3 Persistence](https://www.rfc-editor.org/rfc/rfc9112.html#section-9.3)
[RFC 9113 §9.1 Connection Management](https://www.rfc-editor.org/rfc/rfc9113.html#section-9.1)
[MDN Connection management in HTTP/1.x](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Connection_management_in_HTTP_1.x)