The Web FrontendDeeper

Kayavak / The Web Frontend / FE·31 Frontend Deployment / Deeper

Deeper · The Web Frontend

Frontend Deployment

The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.

Why does this exist?

Deploying a website once meant copying files to a server over FTP, overwriting them one by one while visitors were loading pages. Content delivery networks (Akamai, 1998) moved copies close to users to cope with traffic spikes and distance. Two ideas then reshaped frontend deployment. First, cache-busting by filename: if every asset's name includes a hash of its contents, it can be cached forever, and a new version simply has a new name. Second, platforms that deploy a whole build atomically to a CDN and switch a pointer, popularised around 2015–16 under the label "Jamstack" by Netlify and others, with a preview URL for every branch.

Server rendering brought servers back into frontend deployment, now in several shapes: long-running Node servers, serverless functions, and edge runtimes that run code in many CDN locations.

The mental model

Try it yourself first: write your own model in the Mental Model Explorer, then compare.

A deploy is a switch from one complete, immutable version to another. Hashed assets never change; HTML points to the current set of them; old assets stay available for pages already open.

Question Answer
What is it? Getting built frontend assets (and any server code) onto the internet and switching users to them safely
Problem it solves Releasing often without breaking users mid-session or serving a mixture of versions
Parts Static hosting and CDN, cache headers, server runtimes, atomic switches, previews, canaries, configuration
How it works Upload a complete version, then flip traffic to it; roll back by flipping back
Assumptions Assets are immutable and named by content; HTML is never cached long
When they change Long-cached HTML points to deleted assets; overwritten files mix versions in one page
Where it fails Open tabs running old code call a changed API; feature flags and backward-compatible APIs handle that
Related ideas HTTP caching (ch19); service workers (ch29); deployment strategies (Production Deployment)

What if?

What if you deleted the previous version's assets on every deploy?

Reason it through, then open

Anyone with the app already open would request a lazily loaded chunk that no longer exists and get a 404 in the middle of using it: blank screens and "ChunkLoadError" reports right after every release. Keeping old hashed assets for a while (they cost little) lets open tabs finish their session; the HTML for new visitors points to the new set.

What if HTML were cached for a day at the CDN?

Reason it through, then open

A deploy wouldn't reach users for up to a day, and rollbacks wouldn't either. Worse, different edge locations would serve different versions. HTML is the pointer to everything else, so it's served with revalidation (no-cache) or a very short CDN cache that the deploy purges, while the files it points to are cached for a year.

Where the boundary is

Aspect Static hosting + CDN Server-rendered (Node, serverless, edge)
Runs your code Only in the browser On servers too
Cost and scaling Very low, scales with the CDN Per request or per instance
Failure modes Mostly cache configuration Cold starts, timeouts, distance to data
Rollback Switch a pointer Redeploy or shift traffic

How sure are we?

Claim How it's known Where from
Content-hashed assets can be cached for a year with immutable Convention HTTP caching specifications and practice
Atomic deploys avoid mixed-version pages Model True for new loads; open tabs still run old code
Edge rendering is faster Measured, conditionally Only when the data it needs is also near the edge

Still open

How far to push code to the edge is unsettled: it helps when data is replicated nearby and hurts when every request must go back to one database. Platform lock-in, as hosting features become framework features, is a practical worry.

What would change your mind? If edge databases made data local everywhere at reasonable cost, edge rendering would be the obvious default. Consistency trade-offs make that hard (Distributed Systems).

Recall

Why name assets by a hash of their content?

They can be cached forever; a changed file gets a new name, so there's nothing to invalidate.

Why keep old assets after a deploy?

Open tabs still load chunks from the version they started with.

Why must HTML not be cached long?

It points to the current assets; caching it delays deploys and rollbacks and mixes versions.

What makes a deploy atomic?

The whole new version is uploaded first, then traffic switches to it at once.

Reflect

Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.