Cloudflare Workers 00:00:01 A match preview travels to the edge A football supporter in Sydney asks for a match preview. Much of the page can be assembled close to the spectator using a Worker, but one missing fact may live at a distant origin. Count the journeys separately. During connection setup the edge can use the requested host to prepare the appropriate code. Do not assume that every invocation starts a fresh process. The request calls fetch in the isolate. The flag comes from a copy of KV nearby. Only what is missing is fetched from far away. This wait is not CPU time. The response can finish while permitted background work continues through the execution context's extension mechanism. It has bounded lifetime, so use durable delivery when an event must survive. Network waiting can dominate the viewer's delay without consuming the same amount of CPU time. Choose what is safe to cache and what must be read from its authoritative source. 00:01:04 A warm isolate forgets its souvenirs A second preview reaches a location that already has the application loaded. Reusing an isolate can make startup inexpensive. Now consider an in-memory count of how many fans have visited. a, b and c each get an isolate in the same process. a is asked again. Its isolate is there, so nothing is loaded. In the illustrated memory-pressure example, one isolate is evicted. The exact eviction order is not an application contract. When its code is loaded into a new isolate, the local counter does not inherit the discarded state. An isolate may be replaced, and multiple isolates or locations can handle requests. Never treat a global variable as the authoritative match attendance. Reuse memory for safe optimizations whose disappearance is acceptable. 00:01:58 The score changes in Paris before Sydney hears The score display reads a value of ten in Sydney. A writer in Paris publishes twelve. Suppose Sydney has a cached copy. Predict whether the very next Sydney read must return twelve. The example assumes a locally cached value of ten with a sixty-second cache interval. Paris writes 12. Sydney reads its copy: 10. After the relevant cache and propagation delay in this trace, the Sydney reader sees twelve. Treat the illustrative interval as an example, not a global delivery deadline. Workers KV is eventually consistent across locations. Positive and negative cache entries and configured cache behavior can affect visibility. It works well for many read-heavy settings, while a claim for the final match ticket needs a stronger authority. 00:02:51 Two fans post to the same match room Ana and Kim each submit a message to room forty-two. They reach different nearby Workers, but the room needs one coherent sequence. Both requests use the same Durable Object identity. Ana and Kim post. Each reaches a Worker nearby. Both Workers ask for the object named 42, which is one object in one place. In the illustrated serialized update, Ana receives sequence one and Kim receives sequence two. Broadcast the stored order to connected clients. A reconnecting client can use sequence numbers to detect a gap. The object can assign and persist the example sequence using a correctly coordinated storage operation. Account for asynchronous interleaving and connection failures. A room identifier supplies a coordination boundary, not automatic correctness for arbitrary application code. 00:03:47 Where should the preview actually run? Try two placements. Running near the spectator gives a fast first hop but requires three long trips to a database. Running near the data trades one longer trip for three local ones. 5 ms to the Worker, then three long trips: 5 + 840 = 845 ms. One long trip, then three short ones: 280 + 6 = 286 ms. A request served entirely with nearby data pays only the illustrated five-millisecond access cost. Other network and processing costs can differ in production. The illustrated totals are eight hundred forty-five versus two hundred eighty-six milliseconds. When no database access is needed, the near-user path wins this comparison. Follow the actual round trips before choosing where to place the match preview.