Streaming SSR Implementation for Web Application

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Implementing Streaming SSR for a web application

Classic SSR blocks: server waits for all data, renders full HTML, sends it. Until the slowest database request finishes — browser receives nothing. Streaming SSR breaks this block: HTML is sent to browser as parts become ready, via HTTP chunked transfer encoding.

Browser starts parsing and displaying HTML immediately. Slow parts appear later. User sees something on screen in 100–200ms even if full render takes a second.

Mechanics of Streaming SSR

HTTP/1.1 supports Transfer-Encoding: chunked — server sends data in parts without Content-Length header. React and Vue use this for streaming:

Client receives:
[Chunk 1 — 50ms] <html><head>...</head><body><header>...</header>
[Chunk 2 — 120ms] <main><nav>...</nav><div id="products-suspense"><!--$?--><template id="B:0">...skeleton...</template>
[Chunk 3 — 340ms] <div hidden id="S:0"><ul><li>Product 1</li>...<!-- Data ready --></ul></div><script>$RC("B:0","S:0")</script>
[Chunk 4 — 890ms] <aside><!-- Recommendations --></aside></main></body></html>

Browser renders each chunk immediately. $RC is React script replacing skeleton with real content.

Implementation in React 18 + Next.js

// app/catalog/page.tsx
import { Suspense } from 'react';

// Intentionally slow component — simulates external API request
async function FeaturedProducts() {
  // Slow external service — 800ms
  const products = await fetch('https://api.example.com/featured', {
    next: { revalidate: 300 }
  }).then(r => r.json());

  return (
    <ul>
      {products.map((p: Product) => (
        <li key={p.id}>{p.name}</li>
      ))}
    </ul>
  );
}

async function Categories() {
  // Fast internal request — 50ms
  const cats = await db.category.findMany();
  return <nav>{cats.map(c => <a key={c.id} href={`/catalog/${c.slug}`}>{c.name}</a>)}</nav>;
}

export default function CatalogPage() {
  return (
    <div>
      {/* Renders immediately — synchronous */}
      <h1>Catalog</h1>

      {/* Fast block — appears in ~50ms */}
      <Suspense fallback={<CategoriesSkeleton />}>
        <Categories />
      </Suspense>

      {/* Slow block — appears in ~800ms, rest not blocked */}
      <Suspense fallback={<ProductsGridSkeleton count={6} />}>
        <FeaturedProducts />
      </Suspense>
    </div>
  );
}

Parallel data fetching

Critical error — sequential awaits (waterfall):

// Bad: 200ms + 500ms + 300ms = 1000ms wait
async function Page() {
  const user = await getUser();           // 200ms
  const orders = await getOrders(user.id); // 500ms
  const stats = await getStats(user.id);   // 300ms
  ...
}

// Good: max(200ms, 500ms, 300ms) = 500ms
async function Page() {
  const userPromise = getUser();
  const [user, orders, stats] = await Promise.all([
    userPromise,
    userPromise.then(u => getOrders(u.id)),
    userPromise.then(u => getStats(u.id)),
  ]);
  ...
}

Even better — split independent data across different Suspense components so they stream in parallel without single Promise.all:

export default function DashboardPage() {
  // All three requests start in parallel
  // Each block appears as soon as its data is ready
  return (
    <main>
      <Suspense fallback={<UserCardSkeleton />}>
        <UserCard />         {/* getUser() — 200ms */}
      </Suspense>

      <Suspense fallback={<OrdersSkeleton />}>
        <RecentOrders />     {/* getOrders() — 500ms */}
      </Suspense>

      <Suspense fallback={<StatsSkeleton />}>
        <DashboardStats />   {/* getStats() — 300ms */}
      </Suspense>
    </main>
  );
}

Streaming in Node.js without framework

For custom servers — renderToPipeableStream:

import { renderToPipeableStream } from 'react-dom/server';
import { createServer } from 'http';

createServer((req, res) => {
  res.setHeader('Content-Type', 'text/html; charset=utf-8');
  res.setHeader('Transfer-Encoding', 'chunked');

  const { pipe, abort } = renderToPipeableStream(<App url={req.url} />, {
    bootstrapScripts: ['/static/js/main.js'],

    onShellReady() {
      // Shell ready (content before first Suspense) — start streaming
      res.statusCode = 200;
      pipe(res);
    },

    onShellError(error) {
      // Shell doesn't render — fallback to CSR
      res.statusCode = 500;
      res.end('<html><body><div id="root"></div></body></html>');
    },

    onError(error) {
      console.error('Streaming error:', error);
    },
  });

  // Timeout for very slow components
  setTimeout(() => abort(), 10000);
}).listen(3000);

Edge Streaming with Cloudflare Workers

// worker.ts
import { renderToReadableStream } from 'react-dom/server';

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const url = new URL(request.url);

    const stream = await renderToReadableStream(
      <App url={url.pathname} env={env} />,
      {
        bootstrapScripts: ['/main.js'],
        onError: console.error,
      }
    );

    // Wait for shell (critical path) but don't wait for Suspense
    await stream.allReady; // Optional: wait for everything for bots

    return new Response(stream, {
      headers: {
        'Content-Type': 'text/html; charset=utf-8',
        'Transfer-Encoding': 'chunked',
      },
    });
  },
};

Streaming metadata and headers

Problem with streaming: <head> is sent first, before data is ready. Metadata from async components must be passed separately:

// Next.js solves via generateMetadata — runs separate from page render
export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const product = await getProduct(params.id);
  return {
    title: product.name,
    description: product.description,
  };
}

// generateMetadata and Page component run in parallel
// Streaming starts as soon as generateMetadata completes

Loading UI and skeleton strategies

app/
  catalog/
    loading.tsx     # Automatic Suspense fallback for entire route
    page.tsx
// app/catalog/loading.tsx — renders while page.tsx loads data
export default function CatalogLoading() {
  return (
    <div className="grid grid-cols-3 gap-4">
      {Array.from({ length: 9 }).map((_, i) => (
        <div key={i} className="animate-pulse bg-gray-200 rounded-lg h-64" />
      ))}
    </div>
  );
}

Metrics impact of Streaming SSR

Metric Without streaming With streaming
TTFB After render (500–1500ms) Before render (< 100ms)
FCP After TTFB + parsing Right after shell
LCP Depends on slow data Depends on needed block only
INP Blocked until hydration Hydration starts earlier

Implementation timeline

  • Week 1–2: audit current SSR, identify slow requests, refactor for Suspense boundaries
  • Week 3: parallelize Promise.all and independent Suspense blocks
  • Week 4: skeleton UI for all Suspense fallbacks, loading.tsx for routes
  • Week 5: measure Core Web Vitals before/after, optimize shell time
  • Week 6: monitor streaming in production, alert on slow chunks