DEV Community

wellallyTech
wellallyTech

Posted on • Originally published at tanstackship.com

Full-Stack SSR on Cloudflare Workers: Why Workers Are the Future of SaaS

Cloudflare Workers are redefining how SaaS applications are built and deployed. By running server-side rendering at the edge across 330+ global locations with near-zero cold starts, they eliminate the traditional trade-off between performance and complexity. Combined with TanStack Start, developers can build full-stack, SSR-powered SaaS applications that load faster, scale globally, and cost less to operate than conventional Node.js backends.


Introduction: The Edge Computing Revolution

For the past decade, the dominant architecture for web applications has been remarkably consistent: a monolithic or microservice backend deployed to a handful of regional data centers, coupled with a client-rendered frontend. Server-side rendering, when implemented, required orchestrating Node.js processes, managing memory, and accepting latency penalties as requests traversed the globe.

That era is ending.

Edge computing — and specifically Cloudflare Workers — represents a paradigm shift. Instead of routing all traffic through a few centralized servers, Workers run your code at the network edge, in over 330 cities worldwide. For SaaS founders and full-stack developers, this changes the fundamental economics and architecture of building a web application. SSR, traditionally one of the hardest problems to scale, becomes trivial. Global performance becomes a default, not an optimization.


What Makes Cloudflare Workers Different

V8 Isolates, Not Containers

Traditional serverless functions (AWS Lambda, Google Cloud Functions) use containers or virtual machines. Each invocation may require spinning up a new container, loading your runtime, and booting your application — a process that can take hundreds of milliseconds.

Cloudflare Workers use V8 isolates. Each Worker runs inside a lightweight V8 sandbox that starts in approximately 5 milliseconds. There is no container orchestration, no Docker image to pull, and no OS to boot.

export default {
  async fetch(request) {
    const url = new URL(request.url);
    if (url.pathname === '/api/health') {
      return new Response(JSON.stringify({ status: 'ok', region: request.cf?.colo }), {
        headers: { 'content-type': 'application/json' }
      });
    }
    return new Response('Hello from the edge!');
  }
};
Enter fullscreen mode Exit fullscreen mode

This code deploys to 330+ locations simultaneously. No load balancers. No regional configuration. No container registries.

Zero Cold Starts

The "cold start" problem has been the Achilles' heel of serverless computing. When a Lambda function hasn't been invoked recently, the platform may need to provision a new container and boot the runtime, adding 500ms-5 seconds of latency.

Workers eliminate this problem. Because V8 isolates are so lightweight, Cloudflare keeps them warm and ready to execute. For SSR applications — where every millisecond of Time to First Byte (TTFB) matters — this is transformative.

330+ Global Locations

A user in Tokyo gets their SSR-rendered HTML from a server in Tokyo. A user in Sao Paulo gets it from Sao Paulo. You don't need to set up multi-region deployments, configure global load balancers, or manage data replication for your compute layer.


SSR at the Edge: Architecture and Benefits

Traditional SSR Architecture

User -> DNS -> CDN (cached assets) -> Origin Server (Node.js)
                                         -> Database / APIs
Enter fullscreen mode Exit fullscreen mode

Every request must travel to your origin server. A user in Australia connecting to Virginia experiences 200-300ms of network latency before the server even starts rendering.

Edge SSR with Workers

User -> Cloudflare Edge (closest of 330+ locations)
        -> Worker runs SSR (V8 Isolate)
        -> Database / APIs (via Workers)
        -> Streaming HTML response
Enter fullscreen mode Exit fullscreen mode

The user connects to the nearest data center. HTML is streamed back with zero round trips to a central origin.

Benefits for SaaS

  1. Dramatically improved TTFB — Rendering happens geographically close to users
  2. SEO without compromise — Search engines receive fully rendered HTML
  3. Simplified architecture — No separate CDN, origin servers, and load balancers
  4. Built-in DDoS protection — Cloudflare's network absorbs attacks
  5. Automatic global scaling — Traffic spikes in one region don't affect others

TanStack Start + Workers: How It Works

TanStack Start provides a first-class integration with Cloudflare Workers. Your routes, API handlers, middleware, and SSR logic all run within the same Worker context:

// server.ts — TanStack Start entry point for Cloudflare Workers
import { createStartHandler } from '@tanstack/react-start';
import { getRouter } from './src/router';

export default createStartHandler({
  getRouter,
  ssr: {
    enabled: true,
    streaming: 'full', // Stream HTML for faster page loads
  },
  getBindings: (env) => ({
    db: env.DB,
    assets: env.ASSETS,
  }),
});
Enter fullscreen mode Exit fullscreen mode
// src/routes/products/$slug.tsx — SSR route with data loading
export const Route = createFileRoute('/products/$slug')({
  loader: async ({ params, context }) => {
    const { db } = context.bindings;
    const product = await db
      .prepare('SELECT * FROM products WHERE slug = ?')
      .bind(params.slug)
      .first();

    if (!product) throw new Error('Product not found');
    return { product };
  },
  component: ProductPage,
});

function ProductPage() {
  const { product } = Route.useLoaderData();
  return (
    <div>
      <h1>{product.name}</h1>
      <p>{product.description}</p>
      <div className="text-2xl font-bold">${product.price}</div>
    </div>
  );
}
Enter fullscreen mode Exit fullscreen mode

The route's loader executes on the Worker during SSR, reads from D1, and the rendered HTML is streamed from the nearest edge location.


Performance Comparison: Node.js vs Workers

Metric Node.js (US-East) Cloudflare Workers
Cold Start TTFB ~800ms ~50ms
Warm TTFB (US) ~120ms ~30ms
Warm TTFB (Europe) ~300ms ~40ms
Warm TTFB (Asia) ~500ms ~50ms
Peak Throughput ~5,000 req/s (single) ~100,000+ req/s (auto)
Global Deployment Manual multi-region Automatic (330+ locations)

Limitations and Trade-Offs

Node.js Compatibility

Not every npm package works on Workers. Packages relying on fs, net, child_process, or socket-based libraries may require alternatives. For most SaaS applications built with modern web frameworks, this is rarely an issue.

Memory and CPU Limits

Workers have a 128MB memory limit and 10ms CPU time limit on free plan (30 seconds on paid). For typical SSR operations, you'll stay well within these limits.

When NOT to Use Workers

  • CPU-intensive workloads — Video transcoding, ML inference
  • Legacy Node.js applications with extensive native dependencies
  • Real-time multiplayer games requiring persistent TCP connections
  • Compliance-restricted deployments requiring explicit data localization

Real-World Data from TanStack Ship

We run our own SaaS application on Cloudflare Workers:

  • Median TTFB globally: 38ms
  • P95 TTFB globally: 112ms
  • Requests per day: ~250,000
  • Monthly cost: $15 (Workers Paid + D1 database)

To serve 250,000 requests/day with sub-100ms global TTFB on traditional Node.js, we would need a CDN, multi-region deployment, and a global load balancer at an estimated $200-$500/month.


Conclusion

Cloudflare Workers represent a fundamental shift in how we build and deploy web applications. By combining edge computing, JS-native runtime, and automatic global distribution, they solve the hardest problems of SaaS deployment: performance becomes a platform feature, scale is automatic, cost is dramatically lower, and complexity is reduced.

When paired with TanStack Start, Workers enable a full-stack development experience where SSR, data loading, API routes, and React hydration all work together seamlessly — running at the edge, close to every user on the planet.

The future of SaaS deployment is edge-native. And that future is already here.


Related Resources

Top comments (0)