Skip to content

Jamstack as an Architecture Style for Web Applications

Jamstack describes an architecture style with a pre-rendered frontend and decoupled services. This post puts the original building blocks JavaScript, APIs and Markup into context as of 2021.

≈ 11 min readSoftwareArchitecture

You can’t pull Jamstack into a project with npm install, and you can’t buy it anywhere either. It is an architecture style for web applications that emphasizes pre-rendering and decoupling the UI from services.

That is why the decision is also made one level above the choice of the next framework. That is exactly where Jamstack comes in.

The name was originally formed from JavaScript, APIs and Markup. Matt Biilmann and Chris Bach coined it at Netlify; Biilmann made it publicly known in 2015/2016. As early as 2021, Jamstack was used more broadly than the acronym. Two principles have remained: pre-rendering and decoupling. Instead of generating fresh HTML on the server for every request, markup is built in advance and delivered via a CDN; dynamic parts access APIs separately.

The paradigm shift: classic SSR versus Jamstack#

To understand why this matters, it is worth looking at the classic model. With server-side rendering in the traditional sense, the same thing happens on every page view: the browser sends a request, an application server receives it, queries a database, assembles HTML from it and sends it back. Every single visitor triggers this chain again. That is proven, but it ties up server capacity per request and makes the app server both the bottleneck and the attack surface.

Jamstack reverses this order. The work no longer happens per request but once, at build time. A static site generator pulls content from data sources, renders finished HTML pages from it and stores them as static files. These files land on a CDN and are delivered from there globally, close to the user. Whatever has to be dynamic – a shopping cart, a login, a search – is loaded afterwards on the client side via APIs.

flowchart LR
  subgraph Classic["Classic SSR"]
    B1["Browser"] -->|"Request"| S1["App server"]
    S1 --> DB[("Database")]
    DB --> S1
    S1 -->|"HTML per request"| B1
  end
  subgraph Jam["Jamstack"]
    B2["Browser"] -->|"static page"| CDN["CDN<br/>(pre-rendered)"]
    B2 -->|"dynamic parts at runtime"| API["APIs /<br/>Serverless"]
  end

A clarification that regularly gets lost in discussions: Jamstack doesn’t forbid server-side rendering. It shifts the default case. Instead of “every page per request on the server”, it’s “every page once in the build” – and where it is really needed, I can still use server-side rendering selectively. That is exactly what the next section is about.

Static site generators and hybrid rendering#

The engine of Jamstack is the static site generator. In the simplest case, it is a process that reads content and writes HTML from it. A deliberately reduced example makes the principle tangible – Markdown in, HTML out:

import { loadMarkdown, renderToHtml, writeFile } from "./ssg";

for (const post of loadMarkdown("content/**/*.md")) {
  const html = renderToHtml(post);
  writeFile(`dist/${post.slug}/index.html`, html);
}

In practice, mature tools take care of this. Gatsby, for example, is a React-based generator with a GraphQL data layer and a large plugin ecosystem. Next.js – currently at version 12, released at the end of October 2021 with a new, much faster Rust compiler based on SWC – offers several rendering modes side by side. And SvelteKit, which has been in public beta since spring 2021, takes the same route with an adapter concept. SvelteKit should deliberately still be considered young; it is pre-1.0 and in beta, but the direction is already clearly visible.

The decisive point of modern generators is that I don’t set the rendering globally but decide per page or route. Next.js is a good example for sorting this out:

  • SSG (Static Site Generation) via getStaticProps and getStaticPaths renders the page in the build; afterwards it is pure markup from the CDN.
  • SSR (Server-Side Rendering) via getServerSideProps generates the page per request on the server, for truly dynamic content.
  • ISR (Incremental Static Regeneration), available since version 9.5 from 2020, rebuilds a static page in the background based on time or events.
  • CSR (Client-Side Rendering) via hooks and data libraries such as SWR loads the data only in the browser.

A typical SSG pattern with a touch of ISR looks like this:

export async function getStaticProps() {
  const posts = await fetchFromCMS();

  return {
    props: { posts },
    revalidate: 3600, // ISR: regenerate at most once per hour
  };
}

The revalidate is the transition from purely static to hybrid: the page stays static and CDN-fast but doesn’t go stale, because it renews itself after the specified time. In my experience, this mix – static where possible, server-side or client-side where necessary – is the realistic normal case, not the pure doctrine.

CDN and performance#

Why all the effort? Because pre-rendered assets from the CDN often reach the user faster. Instead of a computation chain of server and database, a nearby edge location delivers a finished file. That can improve time to first byte (TTFB) significantly. For interactivity, though, finished markup alone isn’t enough: a lot of JavaScript and expensive hydration can eat the advantage up again. That’s why I measure delivery and interactivity separately instead of crediting both to pre-rendering.

Then there is the effect on SEO. With pre-rendered markup, search engines immediately see the complete content without depending on client-side loading. For content-driven sites – blogs, documentation, marketing – that is a real advantage I wouldn’t subordinate to pure loading speed.

I want to clear up a common misunderstanding here: the CDN delivers the static assets, not the APIs. The dynamic data still comes via API requests – either directly from the frontend or via an upstream frontend API. So the CDN speeds up delivery of the skeleton, while the dynamic parts are served separately.

Decoupling and API orchestration#

That brings us to the second big principle: decoupling. In Jamstack, delivering the frontend and dynamic data access are separate. The backend can still be one cohesive application or consist of several services; what matters is that the frontend accesses it via APIs during the build or at runtime. Authentication can be handled by an external service, content can come from a headless CMS, and your own business logic can live in serverless functions. These are common building blocks, not a definition of the architecture.

The exciting question then is where all these APIs come together. Two ways have become established. Either I orchestrate directly in the frontend, with the components querying the endpoints they need themselves:

import useSWR from "swr";

const fetcher = (url) => fetch(url).then((res) => res.json());

function Cart() {
  const { data, error } = useSWR("/api/cart", fetcher);
  if (error) return <p>Failed to load</p>;
  if (!data) return <p>Loading…</p>;
  return <CartView items={data.items} />;
}

Or I put a frontend API in front – often via GraphQL, for example with AWS AppSync or the GraphQL endpoint of a headless CMS. The frontend then makes a single, consolidated request, and orchestrating the services behind it happens one layer deeper. For larger applications with many data sources, I prefer this route because it relieves the frontend of detailed knowledge about every single backend.

The serverless functions themselves are deliberately lean and stateless. A handler in Netlify or Lambda style typically looks like this:

exports.handler = async (event, context) => {
  const { name } = JSON.parse(event.body);

  return {
    statusCode: 200,
    body: JSON.stringify({ message: `Hello ${name}` }),
  };
};

The economic appeal behind this can be the billing model: pay-per-execution. Depending on the platform, base fee and load profile, you pay more for actual invocations and compute time than for permanently provisioned servers. The provider also largely takes care of scaling within its limits. Runtime limits, distributed failures, quotas and the cost of individual invocations still remain architecture questions.

Build and CI: the Git push as the trigger#

The pre-rendering has to happen at some point, of course. Often a Git push starts a CI pipeline – for example via GitHub Actions – that runs the static site generator and puts the result on a CDN. Many specialized platforms publish these artifacts atomically and versioned, so that a new version becomes active as a whole and can be rolled back. That is a property of the chosen deployment system, not automatically of every Jamstack build.

flowchart LR
  Dev["git push"] --> CI["GitHub Actions<br/>(CI)"]
  CI --> SSG["Static Site Generator<br/>(Build)"]
  SSG --> Deploy["atomic deploy"]
  Deploy --> CDN["CDN<br/>(global edge)"]
  CDN --> User["User"]
  SSG -.->|"large catalog"| Shard["Sharding /<br/>parallel builds"]
  Shard --> Deploy

A simple workflow that does exactly this is quickly written down:

name: build-and-deploy
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: "16"
      - run: npm ci
      - run: npm run build
      - run: npx netlify deploy --prod --dir=dist

For small sites, the build is done in seconds. For large catalogs with many thousands of pages, the build time itself becomes an issue – sharding helps here, splitting the build into parallel subprocesses. That is also a good transition to the limits I address further below.

Security and operational benefits#

A side effect of the architecture that is easily overlooked concerns security. If no application server is hit per request at runtime, the attack surface shrinks considerably. No monolithic server that runs database queries on every request and becomes vulnerable in the process. What gets delivered are static files, and the dynamic parts sit in clearly delimited APIs that can each be secured individually. All in all, this yields a handy list of benefits:

  • TTFB can drop because pre-rendered markup comes straight from the edge; interactivity additionally depends on the JavaScript delivered.
  • For static pages, there is no application server per read; the APIs remain an attack surface of their own.
  • CDN and platform can take over a large part of the scaling, each within their quotas and runtime limits.
  • Pay-per-execution can save costs with a fitting load profile, but it isn’t inherently cheaper.
  • The developer experience benefits from clear separation, Git-based deploys and fast rollbacks.

Three case studies from practice#

So this doesn’t stay theoretical, here are three scenarios that I almost read as maturity levels in this order.

The first is the static blog or portfolio. This is where Jamstack plays to its strengths: content is rendered in the build, there is hardly any dynamic behavior, and the CDN can deliver it without an application server. For this class of projects, pure SSG is often already the complete answer.

The second scenario is B2C e-commerce. As soon as sessions, shopping carts and transactions come into play, purely static is no longer enough. Product pages can be pre-rendered statically very well and delivered via the CDN, while the cart, checkout and user account are served on the client side via APIs. That is the classic hybrid case, where ISR additionally helps keep product data up to date without rebuilding every page per request.

The third scenario is B2B, SaaS and IoT applications. Dashboards, personalized views and real-time data dominate here. A static skeleton can contribute to a fast initial delivery; protected areas can be rendered on the client, on the server or hybrid, depending on the product. A GraphQL frontend API can also make sense if several data sources really do have to be bundled for the UI.

Where Jamstack hits its limits#

As convincing as the model is, I stay honest about the edges. Pure SSG doesn’t scale indefinitely. With a few thousand pages, build time slowly becomes relevant; with millions of pages, pre-rendering everything simply becomes impractical. This is exactly where the tools already mentioned come in: ISR only re-renders what really changes; hybrid rendering allows server-side generation for rarely visited or highly dynamic routes; and sharding spreads large builds across parallel processes.

Sobriety also pays off when choosing tools. SvelteKit is promising at the end of 2021 but still in beta. Azure Static Web Apps has only been generally available since May 2021 and is therefore also quite young, but it integrates Azure Functions directly as a backend. Fast build building blocks such as esbuild by Evan Wallace speed up the pipeline enormously but are themselves still pre-1.0. If you build here, you choose deliberately between established and up-and-coming.

Conclusion#

To me, Jamstack is less a technology than a stance on architecture. It moves suitable work from the request into the build and separates delivering the frontend from dynamic data access. Whether an enterprise application, several services or serverless functions sit behind it is a separate decision. Fast delivery via the CDN, a smaller runtime surface and simple deployments can follow from it if the application and platform fit.

What matters is that Jamstack stays open to technology. It doesn’t prescribe a framework but a way of thinking, within which I can use Next.js, Gatsby or SvelteKit just as well as Netlify, Vercel or Azure. And it isn’t dogma: pure SSG for the blog, hybrid for the shop, server-side plus API orchestration for the SaaS platform. With this gradation, the architecture decision is made where it belongs – one level above the framework.

Further reading#

Revised and translated from German with the help of AI.