How to Use Domain Sharding for Parallel Requests
Split assets across hostnames to bypass HTTP/1.1 connection limits, know when sharding now hurts, and what replaces it on HTTP/2 and HTTP/3.
On this page
Introduction
On HTTP/1.1 a browser opens at most six connections to any single hostname. A page referencing sixty images through one origin therefore loads in ten sequential waves of six, no matter how idle the network is. Domain sharding breaks that ceiling by spreading assets across several hostnames, static1.example.com through static4.example.com, each with its own six-connection budget. Fifteen years ago this was standard practice at every large property, and the traces of it survive in codebases today. The technique now lives in a narrower niche: HTTP/2 multiplexes unlimited streams over a single connection, so on modern protocol versions sharding is actively harmful, adding handshakes and fragmenting prioritization. This tutorial covers the original problem, the correct implementation when the constraint genuinely applies, the reasons it inverts on HTTP/2, and the retirement path for systems still carrying shards from the era when they helped.
The problem sharding solved
The per-hostname limit exists to protect servers from browsers that would otherwise open hundreds of connections, and it was set when pages had a few dozen subresources. Modern pages have more, and on HTTP/1.1 the queue forms at the browser: requests beyond the sixth wait for a free socket, in strict connection order, so a slow image at the head of a wave blocks everything queued behind it on that connection, a per-connection head-of-line block that sharding sidesteps by giving the browser more parallel lanes. The second cost of the era was request latency itself: each connection pays TCP and TLS setup, and serialized waves meant setup overlapped poorly with transfer. Sharding attacked both: more lanes meant more parallel transfers, and connections to different shards set up concurrently. The technique was so effective that browsers eventually retaliated with per-IP and total-connection caps, since four shards times six connections is twenty-four sockets to one server rack from one user, which is the load-shaping concern that still caps the useful shard count today.
Implement sharding correctly
Where the constraint applies, legacy intranets on HTTP/1.1, unusual embedded clients, or single-connection intermediaries, the implementation has three rules. Keep the shard count small: two to four. Each shard is a full TLS handshake plus DNS resolution plus a fresh congestion window, so beyond four the setup cost eats the parallelism gain. Make shards cookie-less: assets on a shard should carry no session cookies, both for the byte savings and because a cookie-less hostname broadens caching options. Assign deterministically: hash the asset path to a shard so a given asset always maps to the same shard, keeping CDN caches warm and making debugging predictable.
const SHARDS = ['https://static1.example.com', 'https://static2.example.com',
'https://static3.example.com', 'https://static4.example.com'];
export function shardUrl(path: string): string {
let h = 0;
for (let i = 0; i < path.length; i++) {
h = (h * 31 + path.charCodeAt(i)) | 0;
}
const shard = Math.abs(h) % SHARDS.length;
return SHARDS[shard] + path;
}
The certificate must cover all shard names, a wildcard or SAN list, or every shard pays an extra validation failure. DNS should resolve shards to the same infrastructure, since the shards are names, not servers.
Why HTTP/2 inverts the tradeoff
HTTP/2 multiplexes many streams over one connection with header compression and per-stream prioritization. The six-connection limit becomes irrelevant: the browser issues sixty requests on one TCP connection as sixty concurrent streams. In that world sharding strictly subtracts value. Each shard is its own TLS handshake, its own congestion window starting from slow start, and its own header-compression state, so four shards mean four times the setup and four cold windows instead of one warm one. Worse, the connection owns prioritization: the browser sees one priority queue per connection, so an urgent image on static3 cannot overtake a low-priority script on static1, because they live in different queues on different connections. The priority information that HTTP/2 exists to exploit is fragmented across the shards. Studies of the migration era consistently showed page loads improving when properties collapsed shards to one origin on HTTP/2, which is the rare case of a performance technique whose retirement made things faster.
What replaced sharding
The problems sharding addressed have dedicated solutions now. Parallelism: HTTP/2 and HTTP/3 multiplexing, which is the direct replacement and the reason to retire shards. Setup cost: TLS session resumption, connection coalescing where one connection serves multiple origins with overlapping certificates, and 0-RTT in TLS 1.3 shrink the per-origin handshake penalty that shards multiplied. Prioritization: the priority signaling in HTTP/2 and HTTP/3 lets the browser express which streams matter, information that sharding destroyed. Payload volume, the deeper cause of request counts: HTTP/2 header compression shrinks per-request overhead on the wire, and bundling decisions should be revisited per asset class rather than applied globally, since multiplexing changed the economics of many-small-requests in favor of small, but caching granularity still favors unbundled assets. The remaining legitimate modern use of multiple hostnames is isolation, not parallelism: separating cookies, certificate boundaries, or security postures, such as serving untrusted user uploads from a separate origin with no credentials.
Retiring legacy shards
Codebases still emitting sharded URLs should retire them with a migration plan, not a flag flip. Inventory first: crawl the rendered pages or instrument template helpers to list every hostname referenced, because shards tend to accrete extra names over the years. Then collapse: change the shard function to return the single canonical origin, and keep the old shard hostnames alive as redirects, or better, keep serving them directly with long immutable caching so old HTML and old CDN caches resolve without a round trip to the redirect. Fingerprinted asset URLs make this painless, since the content behind an old URL never changes and the redirect target is only needed for cold caches. Watch for mixed-protocol hazards during the window where both shapes exist, and confirm the CDN treats the collapsed origin with the same cache key policy the shards had, or the migration silently evicts every cached asset. A retirement is finished when the shard hostnames no longer receive meaningful traffic, which DNS logs and CDN request metrics answer directly.
Test and measure the decision
Whether adding or removing shards, the claim is about connection-level behavior, so measure at that level. In the browser, the Network panel with the Protocol and Connection columns visible shows exactly which requests shared a socket and which protocol version each used; a waterfall with six-abreast waves on HTTP/1.1 is the constraint in its visible form. In the lab, request timing percentiles for pages with many same-origin assets, compared across one origin and several, settle the question for the actual client mix. Server-side, connection counts and handshake rates at the edge show what sharding costs in setup traffic. Because the protocol version is negotiated per connection, measure the real distribution: an HTTP/2-fronted CDN with HTTP/1.1 clients behind old proxies may still justify a shard for the tail, and only the connection-level data, not the era of the technique, decides that.
curl -sI --http2 https://static1.example.com/app.js | grep -iE '^(HTTP|alt-svc)'
Common pitfalls
- Sharding on HTTP/2. The limit is gone; shards now add handshakes and fragment priorities, the exact inverse of the intent.
- Too many shards. Each is a handshake and a cold window; past four, setup cost dominates.
- Cookies on asset shards. Session bytes ride every asset request; shards exist to be cookie-less.
- Random shard assignment. Assets bounce between hosts across sessions and bust CDN caches; hash deterministically.
- Certificates that miss shard names. Every miss is a failed validation and a visible error.
- Retiring by flag flip. Old URLs must resolve through redirects or continued serving during a long cache-tail window.
Conclusion
Domain sharding is a precise answer to a precise constraint: the six-connection-per-hostname ceiling of HTTP/1.1. Where that constraint genuinely applies, implement it with two to four cookie-less shards, deterministic path-to-shard assignment, and certificates that cover every name. Where HTTP/2 or HTTP/3 reaches clients, the constraint dissolves and the technique inverts, multiplying handshakes, fragmenting prioritization, and slowing pages, so the correct action is retirement: collapse to one origin, keep old shard URLs resolving through long caches or redirects, and verify the CDN cache keys survive the change. The modern reason to run multiple hostnames is isolation, not parallelism. Measure at the connection level to know which world you are in, because the calendar alone does not decide it.
Sources: MDN: Connection management in HTTP/1.x, Cloudflare: HTTP/2 multiplexing, RFC 7540: HTTP/2.
FAQ
- How many connections does a browser allow per origin?
- Six for HTTP/1.1 in most browsers, historically ranging from two to eight. The limit exists per hostname, which is exactly why sharding worked, and per connection on HTTP/2, which is why it stopped being needed.
- Does sharding help on HTTP/2 or HTTP/3?
- No, it hurts. Multiplexing carries many streams over one connection, so shards add TLS handshakes and split the prioritization view the connection has, usually making pages slower.
- Should shards be cookie-less?
- Yes, when serving static assets. Each cookie byte travels on every request to that hostname, so a 2 kilobyte session cookie multiplied across dozens of asset requests is pure waste on a shard built for assets.
Report a problem with this articleOpens a pre-filled issue on GitHub.