How Cloudflare Cut Cold Starts 10x: From TLS Pre-Warming to Consistent Hash Sharding
Cloudflare Workers started with 5ms cold starts that were hidden behind TLS handshakes. As Workers grew to support full applications (10 MB scripts, 400ms startup budgets), cold starts outgrew TLS - and the original trick stopped working. This post covers both generations of their solution: the TLS SNI pre-warming trick and the consistent hash ring sharding system that ultimately cut eviction rates 10x and pushed warm request rates to 99.99%.
Key takeaways
- Generation 1: Cloudflare pre-warms Workers during the TLS handshake by reading the SNI hostname from the ClientHello - hiding the cold start behind latency the client already has to wait for.
- Generation 2: As Workers grew larger (scripts up to 10 MB, startup CPU up to 400ms), cold starts outgrew TLS handshakes - so Cloudflare instead routes requests to servers that already have the Worker loaded.
- A consistent hash ring maps Worker script IDs to “shard servers.” Requests are forwarded there (<1ms overhead) rather than cold-starting a new instance on whichever server received the request.
- When a shard server is overloaded, it uses Cap’n Proto’s distributed capability model to return the client’s own lazy Worker reference - short-circuiting the proxy loop without an extra round trip.
- Sharding just 4% of traffic reduced global eviction rates by 10x, pushing warm request rates from 99.9% to 99.99% - thanks to power law distributions where a small number of high-traffic Workers dominate total request volume.
Why this comes up in interviews
Serverless cold starts, consistent hashing, and load shedding are all recurring system design topics. This post gives you a real production example of consistent hashing applied to something other than caches, plus a concrete case study in how to reason about optimistic vs. pessimistic request handling under overload.
What’s a cold start and why does it hurt?
A cold start is everything that must happen before a serverless function can serve its first request: fetching the script from storage, compiling the source code, executing the top-level module (running initialization logic), and finally invoking the function to handle the incoming request. For Cloudflare Workers - which run inside V8 isolates rather than full containers - this was originally measured in single-digit milliseconds. Containers on other platforms can take full seconds to spin up a new process. V8 isolates share a single process, skipping OS-level overhead, so startup is dramatically cheaper. But even 5ms adds up when you have millions of low-traffic Workers that are frequently evicted and re-instantiated.
Interview angle
When asked about serverless tradeoffs, cold starts are the canonical downside. Know the spectrum: containers (seconds), VMs (minutes), isolates (milliseconds). The follow-up is always “how do you mitigate them?” - which leads directly into the rest of this article.
Generation 1: Pre-warming during the TLS handshake
The first technique exploited a timing window that already exists in every HTTPS request. Before a client can send an HTTP request, it must complete a TLS handshake with the server. The very first message the client sends - the ClientHello - includes the SNI (Server Name Indication): the hostname the client is connecting to. For a Worker, that hostname is enough information to identify which script needs to run. Cloudflare’s insight: the time the server spends completing the handshake (certificate exchange, key agreement) is time the client is already waiting for. If the cold start finishes before the handshake does, the request sees zero latency from it. In 2020, Worker cold starts were ~5ms and average network round-trip times exceeded that - so reading the SNI from the ClientHello and immediately starting to warm the Worker in the background made cold starts effectively invisible.

Interview angle
“Work you do during unavoidable waiting time is free” is a powerful optimization pattern. TLS handshake pre-warming is one example; speculative execution in CPUs is another. Interview question: what are the failure modes? Answer: if cold start > handshake duration, you’ve helped but not eliminated the delay. If the Worker changes between ClientHello and request arrival, you’ve wasted work.
Why the trick stopped working: Workers grew up
The TLS pre-warming technique depended on one assumption: cold starts finish faster than TLS handshakes. That assumption eroded over time as Cloudflare relaxed platform limits to support real applications. Compressed script size limits went from 1 MB to 10 MB for paid users. Startup CPU time limits went from 200ms to 400ms. Users took full advantage - deploying complex bundled applications that previously would have lived on origin servers. Cold starts for these Workers now exceeded TLS handshake durations, especially with TLS 1.3 (which only needs a single round trip, making the pre-warming window even shorter). The result: any optimization to cold start speed itself was a losing battle. Instead of making cold starts faster, Cloudflare needed to make them rarer.
Interview angle
This is a classic “assumptions drift” problem. An optimization that works at one scale breaks when the system’s parameters change. Interview signal: when an interviewer describes a technique that “used to work,” probe what assumption changed. Here it was: cold start duration < handshake duration. The corrective insight - reduce frequency instead of duration - is the kind of lateral thinking that distinguishes strong candidates.
The core insight: route to warm Workers instead of starting new ones
Consider a Worker that receives one request per minute, spread evenly across 300 servers in a data center. Each server receives that Worker’s traffic roughly once every five hours. Workers are evicted after inactivity to free memory for other Workers - so with five-hour gaps between requests, the Worker is almost always cold. Cold start rate approaches 100%. Now imagine routing all of that traffic to a single server. The Worker receives one request per minute on that one server - a short enough interval to stay warm indefinitely. Memory usage drops by 99.7% (one instance instead of 300). The forwarding cost? Less than one millisecond for an in-datacenter proxy hop. That’s always cheaper than a cold start. Cloudflare calls this “Worker sharding” - the idea that each data center now has one logical pool of Workers, sharded across servers, rather than each server maintaining an independent set.
Interview angle
The key numbers: <1ms proxy overhead vs. potentially hundreds of milliseconds for a cold start. Coalescing traffic to warm instances is almost always the right call. Secondary benefit: memory efficiency creates a virtuous cycle - fewer evictions means other Workers also stay warm longer. In interviews, model this as a cache hit rate problem: the goal is to minimize cold start (cache miss) rate, and routing is your lever.
Consistent hash ring: deterministically finding the shard server
To route requests to the server that already has a Worker loaded, every server needs to agree on which server “owns” a given Worker. Cloudflare uses a consistent hash ring. Both Worker script IDs and server addresses are hashed onto a single number line whose ends wrap around (a ring). To find a Worker’s home server, hash its script ID, find that position on the ring, then take the next server address clockwise - that’s the shard server. The elegance is in how it handles servers joining and leaving. With a naive hash table (script_id → server_index), adding or removing any server rehashes every Worker, causing a global cold start wave. With a consistent hash ring, only the Workers that were “owned” by the changed server need to be re-homed - all others are unaffected. In practice, a server leaving or crashing only displaces a fraction of Workers.

Interview angle
Consistent hashing is the most commonly tested distributed systems concept in system design interviews. Most candidates apply it to caches (CDN, Memcached). This is a rarer but equally valid application to compute routing. Know the two failure modes: server churn causes re-homing (acceptable), and hash skew can make one server own too much (fixed with virtual nodes - worth mentioning).
Handling overload: optimistic sharding and graceful load shedding
Workers are live compute, not static files. A single high-traffic Worker may need dozens of instances to handle its load - so Cloudflare can never guarantee a Worker lives on exactly one server. The shard server must be able to refuse requests when overloaded, and the shard client (the server that received the request and forwarded it) must handle refusals gracefully. Cloudflare chose optimistic sending: just forward the request without asking permission first. The alternative - a round-trip “may I?” before sending - costs one extra RTT of latency, and since the vast majority of sharded requests succeed, that cost is almost always wasted. When a shard server does need to refuse, it uses Cap’n Proto’s capability model: instead of sending a “go away” error, it returns the shard client’s own lazy Worker reference back to the client. The shard client’s RPC layer recognizes the returned capability as local, stops sending bytes to the shard server, and serves the request itself - no trombone effect, no extra RTT.

Interview angle
“Optimistic vs. pessimistic” is a fundamental distributed systems tradeoff. Optimistic is faster in the common case but requires a well-designed rollback/refusal path. The Cap’n Proto trick here is particularly elegant: the refusal mechanism is zero-cost for the common success case, and the fallback is handled automatically by the RPC layer without any application-level logic.
Workers invoking Workers: propagating context across machines
Many Cloudflare products involve chains of Worker invocations. Service Bindings let one Worker call another directly. Workers for Platforms runs a dispatch Worker that selects and invokes a user Worker, which may call an outbound Worker. Tail Workers collect traces. All of these can be sharded to different servers. The challenge: each invocation carries a context stack - ownership overrides, trust levels, resource limits, tail Worker configs, outbound Worker configs, feature flags. When everything ran on a single thread, this was manageable. For sharding to work, the context must travel with the request across machines. Cloudflare’s solution: serialize the context stack into a Cap’n Proto message and send it to the shard server. Cap’n Proto capabilities (live object references) are particularly useful here - a reportTraces() callback on the dispatch Worker’s home server can be embedded in the serialized context, and any shard server that ends up with a piece of the request chain can call it directly, without knowing where “home” is.
Interview angle
Distributed context propagation is the operational name for this problem - it’s the same challenge behind distributed tracing (OpenTelemetry, Jaeger), request-scoped auth tokens, and feature flag propagation across microservices. The pattern is always: serialize the context at the boundary, deserialize at the destination, use stable identifiers (not in-memory pointers) to refer to things that need callbacks.
Results: 10x fewer evictions, four nines of warm requests
After full rollout, only about 4% of enterprise traffic was sharded - meaning 96% of Workers already had enough concurrent traffic to require multiple instances. Yet that 4% drove a 10x reduction in global Worker eviction rates. The explanation is power law distributions: internet traffic is heavily skewed. A small number of high-traffic Workers account for the vast majority of requests. They were never a cold start problem. The long tail - a huge number of low-traffic Workers that receive rare, sporadic requests - caused nearly all the evictions. Sharding coalesces that long tail onto single instances, keeping them warm. The warm request rate for enterprise traffic improved from 99.9% (three nines) to 99.99% (four nines). Equivalently, cold start rate dropped from 0.1% to 0.01% of requests - a 10x decrease consistent with the eviction rate improvement.
Interview angle
Power law distributions appear constantly in systems: web traffic, database query frequencies, cache key access patterns, error rates. The key interview insight here is that optimizing the 4% of traffic that follows the power law tail can have disproportionate system-wide impact. When asked “would this optimization be worth it?”, the answer often depends on the distribution of your workload - uniform distributions rarely give this kind of leverage.
Key concepts
Cold Start
The latency incurred the first time a serverless function is invoked after a period of inactivity. Includes fetching script code, compiling it, executing initialization logic, and handling the first request. Subsequent requests to the same loaded instance are “warm” and skip all of this.
Like starting a car that’s been sitting in a cold garage vs. one with the engine already running. The warm car moves the instant you shift into drive.
V8 Isolate
A lightweight JavaScript execution context inside the V8 engine. Multiple isolates share a single OS process and V8 heap, so creating a new one skips the process-spawning overhead of containers. This is what gives Cloudflare Workers millisecond-scale cold starts instead of second-scale.
Like opening a new browser tab vs. launching a new browser. New tab: instant. New browser: takes a few seconds.
TLS SNI (Server Name Indication)
An extension to the TLS protocol where the client includes the target hostname in its very first message (the ClientHello). Allows servers to serve multiple certificates from one IP. Cloudflare exploits this to identify which Worker to pre-warm before the handshake completes.
Consistent Hash Ring
A data structure that maps both keys (e.g., Worker script IDs) and nodes (e.g., server addresses) onto a circular number line. Each key is “owned” by the next node clockwise. When nodes are added or removed, only keys adjacent to the change are affected - unlike a naive hash table where all keys must be remapped.
Like assigning postal routes on a circular road. If a delivery driver drops out, only the letters just before their stretch of road need to be reassigned to the next driver. Everyone else keeps their existing route.
Shard Client / Shard Server
In Cloudflare’s sharding model, the shard client is the server that receives the incoming request. The shard server is the server the hash ring designates as the Worker’s home - the one likely to already have it loaded. The shard client forwards the request to the shard server to avoid a cold start.
Load Shedding
Deliberately refusing or rerouting requests when a server is overloaded, to prevent cascading failure. The goal is graceful degradation - shedding excess load before it causes errors for all requests, not just the excess ones.
Cap’n Proto RPC
A serialization and remote procedure call framework that supports distributed object capabilities - references to live objects that can be passed across machines. Cloudflare uses it for all cross-instance Worker communication, including the load shedding refusal trick and context stack serialization.
Power Law Distribution
A statistical pattern where a small number of items account for a disproportionately large share of events. Web traffic follows a power law: a handful of Workers handle the majority of requests, while a long tail of Workers each handle very little traffic. This long tail is where cold starts concentrate.
“The rich get richer.” A few words like “the” and “and” appear thousands of times in any text; most words appear once or twice.
Check your understanding
Why did TLS pre-warming successfully hide cold starts in 2020 but not for larger Workers today?
- Cloudflare cached compiled Worker bytecode at every edge node, making cold starts instant for repeated scripts.
- Worker cold starts (~5ms) finished before TLS handshakes completed, but as Workers grew larger their cold starts began exceeding handshake duration.
- TLS 1.3 extended handshake duration to match Worker startup time, but browser adoption remained too low.
- Pre-warming was only available for Workers deployed to custom domains, not workers.dev subdomains.
Show answer
Worker cold starts (~5ms) finished before TLS handshakes completed, but as Workers grew larger their cold starts began exceeding handshake duration.
TLS pre-warming works only when the cold start finishes before the handshake does - the request then sees zero cold start delay. In 2020, 5ms cold starts easily beat handshake RTTs. But Cloudflare raised script size limits (up to 10 MB) and startup CPU limits (up to 400ms) so users could deploy full applications. Those cold starts now outlast TLS handshakes, especially with TLS 1.3’s single-round-trip handshakes.
What specific piece of information in the TLS ClientHello lets Cloudflare identify which Worker to pre-warm?
- The client’s IP address, which maps to a registered tenant in Cloudflare’s routing table.
- The list of supported cipher suites, which uniquely fingerprints the client application.
- The SNI (Server Name Indication) - the target hostname sent in the first TLS message.
- The TLS session ticket, which encodes the previously loaded Worker from the last connection.
Show answer
The SNI (Server Name Indication) - the target hostname sent in the first TLS message.
SNI (Server Name Indication) is an extension included in the very first TLS message the client sends - the ClientHello. It contains the hostname the client wants to connect to (e.g., myapp.workers.dev). Since a Worker is identified by its hostname, this gives Cloudflare enough information to start warming the Worker before the handshake even completes.
A low-traffic Worker receives 1 request per minute, evenly load-balanced across 300 servers. What happens to its cold start rate, and why?
- Cold start rate is low because Cloudflare’s autoscaler pre-allocates the Worker on all 300 servers during off-peak hours.
- Cold start rate approaches 100% because each server only receives the Worker’s traffic once every ~5 hours - long enough for the Worker to be evicted between requests.
- Cold start rate is around 50% because Cloudflare pins Workers to the 150 servers with the most available memory.
- Cold start rate is negligible because V8 isolate compilation is cached globally and reused across all servers.
Show answer
Cold start rate approaches 100% because each server only receives the Worker’s traffic once every ~5 hours - long enough for the Worker to be evicted between requests.
1 request/minute across 300 servers means each server receives that Worker’s traffic roughly once every 5 hours. Workers are evicted after inactivity to reclaim memory. Five hours of inactivity is far longer than any reasonable eviction TTL, so nearly every request triggers a fresh cold start. Sharding routes all traffic to one server, where 1 req/min is frequent enough to stay warm.
What is the key advantage of a consistent hash ring over a naive hash table when mapping Workers to servers?
- Consistent hashing guarantees perfectly equal distribution of Workers across servers, eliminating hot spots.
- The ring structure allows Workers to be simultaneously assigned to multiple servers for redundancy without coordination overhead.
- When a server is added or removed, only Workers adjacent to that server on the ring must be re-homed - all others are unaffected.
- Consistent hashing stores each Worker’s compiled bytecode at its ring position, making cold starts O(1) lookups.
Show answer
When a server is added or removed, only Workers adjacent to that server on the ring must be re-homed - all others are unaffected.
With a naive hash table of size N, adding or removing any server requires remapping nearly every Worker (keys rehash to different buckets). With a consistent hash ring, each server “owns” the Workers that land between it and the previous server on the ring. Only those Workers are displaced when a server leaves. This is critical for Cloudflare: a server crash shouldn’t trigger a global cold start wave.
Cloudflare chose optimistic sharding - forwarding the request immediately without asking the shard server for permission first. What is the main reason?
- Cap’n Proto RPC does not support request/response handshake patterns across servers in the same data center.
- The shard client cannot determine the shard server’s address until after the request bytes have already been sent.
- Overloaded shard servers are rare in practice, so adding a mandatory permission round trip would penalize the common success case.
- TLS encryption prevents the shard client from inspecting the shard server’s load metrics before forwarding.
Show answer
Overloaded shard servers are rare in practice, so adding a mandatory permission round trip would penalize the common success case.
If the shard client had to ask “can you take this?” before every forwarded request, every sharded request would incur one extra round trip of latency. Since the shard server accepts the vast majority of requests (Workers get evicted only after sustained inactivity), this would be wasted overhead almost every time. Optimistic sending pays a cost only on the rare overload case, which is the right tradeoff.
When a shard server is overloaded and needs to refuse a request, what does it return to the shard client - and why is this efficient?
- An HTTP 503 with a Retry-After header, prompting the shard client to wait and resend to the same server.
- The address of a less-loaded server, allowing the shard client to re-route without cold-starting locally.
- The shard client’s own lazy Worker capability, which the RPC layer recognizes as local - stopping further byte transmission to the shard server.
- A serialized snapshot of the Worker’s heap state, allowing the shard client to resume execution without a full cold start.
Show answer
The shard client’s own lazy Worker capability, which the RPC layer recognizes as local - stopping further byte transmission to the shard server.
This is the Cap’n Proto capability trick. The shard client included a handle to a lazy local Worker instance in its original request. Instead of returning “go away,” the overloaded shard server returns that same handle. The shard client’s RPC layer sees a local capability - recognizes it doesn’t need to send any more bytes through the shard server - and short-circuits, serving the request locally. No extra round trip, no “trombone effect” of bytes bouncing back.
A Workers for Platforms setup has a dispatch Worker, a user Worker, and an outbound Worker - all potentially sharded to different servers. What does serializing the “context stack” into a Cap’n Proto message accomplish?
- It compresses the Worker chain’s combined JavaScript source code so it can be transmitted to the shard server faster.
- It lets each shard server in the chain independently verify the request’s authentication without contacting the origin.
- It carries context (trust levels, resource limits, tail Worker config, callbacks) across machine boundaries so each shard server has the full execution context it needs.
- It enables the outbound Worker to cache results and skip re-invoking the user Worker on subsequent requests with the same input.
Show answer
It carries context (trust levels, resource limits, tail Worker config, callbacks) across machine boundaries so each shard server has the full execution context it needs.
When a dispatch Worker invokes a user Worker that gets sharded to a different server, the new server needs to know the full execution context: trust overrides, resource limits, which outbound Worker to use, where to send traces, etc. Serializing this as a Cap’n Proto message and sending it to the shard server recreates the full context there. Cap’n Proto capabilities (like a reportTraces() callback) stay live and callable across machines without the shard server needing to know where “home” actually is.
Why must Cloudflare always support running multiple instances of the same Worker in a data center, even with sharding?
- Regulatory requirements mandate data locality, forcing Workers to run on servers in specific geographic zones.
- The consistent hash ring assigns each Worker to exactly two servers for fault tolerance.
- Workers run arbitrary code and can saturate a single instance under traffic bursts - sharding only routes to an already-loaded server, but high-traffic Workers still require multiple instances for horizontal scaling.
- Cap’n Proto RPC requires at least two Worker instances to establish the distributed capability protocol.
Show answer
Workers run arbitrary code and can saturate a single instance under traffic bursts - sharding only routes to an already-loaded server, but high-traffic Workers still require multiple instances for horizontal scaling.
HTTP assets are static - caching them scales linearly with their size. Workers are live compute that can run arbitrary code for up to 5 minutes of CPU per request. Under sufficient traffic, no single instance can keep up. Sharding reduces cold starts for low-traffic Workers, but high-traffic Workers will always need multiple instances. Cloudflare’s sharding design explicitly accounts for this: overloaded shard servers can shed load back to shard clients, which can cold-start additional instances.
Only 4% of enterprise traffic was sharded, yet global eviction rates dropped 10x. What best explains this disproportionate impact?
- Each sharded request prevented exactly 10 future cold starts through a cache-warming multiplier baked into the hash ring.
- The 4% of sharded requests belonged to Workers that were each 10x larger than average, accounting for 40% of memory pressure.
- Internet traffic follows a power law: a tiny number of Workers receive most requests and were never eviction-prone; sharding fixed the long tail of low-traffic Workers that caused nearly all evictions.
- Sharding triggered a global rebalancing of Workers across servers, reducing average memory pressure per server by 10x regardless of traffic distribution.
Show answer
Internet traffic follows a power law: a tiny number of Workers receive most requests and were never eviction-prone; sharding fixed the long tail of low-traffic Workers that caused nearly all evictions.
Power law distributions are common in internet traffic: a handful of Workers handle the majority of requests, have plenty of load to stay warm, and were never a cold start problem. The long tail - a huge number of low-traffic Workers that each receive sporadic requests - is where evictions concentrate. Sharding coalesces that long tail to single instances, keeping each one warm. Fixing the tail (4% of traffic) had an outsized effect on eviction rates (10x).
Cloudflare’s warm request rate improved from 99.9% to 99.99% after sharding. What does the remaining 0.01% represent, and why can’t it reach 0%?
- Requests served by free-tier Workers, which are excluded from sharding for cost reasons.
- The irreducible cold start rate from brand-new Worker deployments, script updates, and the first request after a shard server restart.
- Requests that exceeded the shard server’s 5-minute CPU limit and were terminated mid-execution.
- Traffic to Workers in Cloudflare data centers that haven’t yet received the sharding rollout.
Show answer
The irreducible cold start rate from brand-new Worker deployments, script updates, and the first request after a shard server restart.
Sharding routes requests to servers that already have a Worker loaded - but some cold starts are unavoidable. The very first request ever to a Worker, requests after a Worker’s code is updated (requiring a fresh load), and requests to Workers in data centers where all candidate shard servers have evicted the Worker all produce cold starts. No routing strategy can eliminate the first-ever instantiation of a Worker. Cloudflare’s blog hints at future work toward five nines.
Liked this? Engineer's Codex sends one deep dive and a link roundup every week.
No spam. Unsubscribe anytime.