Jeremy Tjahjana
ENGINEERING NOTES••6 min read

Migrating to a New Stack: Engineering for Edge Performance & Deterministic Latency

A comprehensive breakdown of overhauling our digital infrastructure: dismantling legacy hydration bottlenecks, benchmarking modern full-stack runtimes, and engineering a microsecond-level edge architecture.

#nextjs#edge-runtime#web-vitals#architecture
High-performance edge infrastructure and computational architecture
FIG 01. Distributed Edge Node Mesh & Zero-Runtime Hydration Pipeline Topology.

1. The Breaking Point: Why Rebuild?

Every engineering project eventually reaches a moment where incremental refactoring yields diminishing returns. For the past two years, my portfolio and web systems were powered by a traditional single-page application bundled with an array of client-side libraries. While the system functioned acceptably on a fiber connection with a top-tier laptop, synthetic tests in real-world mobile conditions told a dramatically different story.

Under 4G mobile emulation with CPU throttling enabled, the initial JavaScript execution cost was steep. The browser spent upwards of 800 milliseconds merely parsing script bundles before executing React's reconciliation pass. Users in regions with fluctuating latency—such as campus networks or mobile transit—routinely stared at blank canvases waiting for client-side fetches to resolve.

The friction wasn't simply aesthetic. Our telemetry revealed that First Input Delay (FID) and Cumulative Layout Shift (CLS) were steadily degrading as interactive modules expanded. The diagnostic was unambiguous: client-side hydration had become an unnecessary tax on the user experience. We required an architecture where zero non-essential JavaScript reaches the client, content renders statically at the edge, and dynamic widgets hydrate lazily on explicit intent.

2. Evaluating Modern Runtime Paradigms

Before writing a line of new code, we conducted an empirical audit of the frontend framework ecosystem, evaluating three primary contenders against strict criteria: zero-hydration capability, deterministic edge compilation, and developer ergonomics.

Pure Static Generation (SSG)

Extremely fast delivery via object storage, but rigid. Real-time telemetry (such as live Spotify playback, dynamically fetched GitHub commit activity, and interactive modal dialogs) required bulky client-side API polling that negated the speed benefit.

Traditional Node.js SSR

Dynamic and flexible, but hindered by cold starts and centralized origin latency. Delivering server-rendered HTML from a single datacenter meant international visitors incurred an unavoidable 200–400ms physical roundtrip penalty.

Next.js App Router on Edge

Combines static pre-rendering with React Server Components (RSC) and V8 edge functions. Server components remain pure HTML strings on the wire, while client interactive islands load asynchronously without blocking critical path rendering.

The decision to migrate to the Next.js App Router on an edge distribution layer gave us the best of both worlds: pre-compiled static markup for the portfolio body, paired with edge-cached serverless endpoints for dynamic state like Spotify and GitHub activity.

3. Zero-Hydration Islands Architecture

The cornerstone of the overhaul is the deliberate segregation between server-rendered content and client-rendered interactive islands. In our previous stack, an entire page tree had to be hydrated if even a single button had an onClick handler. In the new architecture, the document layout, prose, typographic hierarchy, and structural assets contain exactly zero client-side JavaScript.

app/page.tsx (Zero-Hydration Shell)TypeScript
// Server Component: Static HTML rendered directly at the edge
export default async function Page() {
  const staticData = await getCompiledSpecimens();

  return (
    <SiteFrame>
      <StaticHero title={staticData.title} />
      {/* Client Island: Only this isolated boundary hydrates */}
      <Suspense fallback={<TerminalSkeleton />}>
        <InteractiveTerminalEngine />
      </Suspense>
    </SiteFrame>
  );
}

By isolating client interactivity behind explicit 'use client' directives, our baseline JavaScript payload dropped by over 68%. The initial page response is delivered as raw, streaming HTML that renders immediately upon packet arrival.

4. Telemetry & Core Web Vitals

Architectural elegance is worthless without empirical verification. After deploying the edge-native build to production, we ran synthetic Lighthouse audits alongside real-user monitoring (RUM) across varied global regions.

MetricLegacy SPAEdge Next.jsDelta
Largest Contentful Paint (LCP)2.4s0.62s-74.1%
Total Blocking Time (TBT)410ms18ms-95.6%
Cumulative Layout Shift (CLS)0.140.001-99.2%
Initial JS Bundle Size342 KB94 KB-72.5%

“Speed is not merely an optimization trick; it is the fundamental respect you pay to the user's attention and battery life.”

5. Production Edge Cases & Trade-offs

Migrating to edge runtimes is not without friction. The V8 edge runtime does not provide standard Node.js APIs like fs or child_process. Every third-party library had to be scrutinized for non-standard globals or synchronous filesystem calls.

Additionally, streaming server components introduce subtleties in CSS rendering. CSS-in-JS solutions that dynamically inject <style> tags during client hydration cause noticeable flash-of-unstyled-content (FOUC). Transitioning fully to modern utility-first CSS and pre-compiled CSS custom properties eliminated layout recalculations entirely.

6. Conclusion & Looking Forward

Rebuilding from the foundation up provided valuable clarity. By shedding legacy abstractions and embracing edge-native architectures, we achieved sub-second global page loads while preserving rich visual design and interactive depth.

The journey doesn't end here. Upcoming iterations will explore WebAssembly compute pipelines for on-device machine learning visualizations and automated performance budgets embedded directly into our CI/CD workflows.

Jeremy Tjahjana

Written by Jeremy Tjahjana

Full-Stack, ML & Cybersecurity • Indonesia

Share: