Skip to the solution
HardFrontend10 min read

What are Multi-Zones in Next.js and when would you split an app into zones?

606 views

The problem

Question presented to candidate: "Our Next.js monolith takes 25 minutes to build and three teams keep blocking each other's releases. Someone proposed Multi-Zones. What are they, how do they work, and would you recommend them here?"

What a strong answer should cover:

  • A zone is a separate Next.js app serving a set of paths on the same domain (for example /blog/*); a default zone serves everything else.
  • Routing by rewrites in the default app's next.config (or any HTTP proxy, or proxy.ts for dynamic decisions), and assetPrefix on each non-default zone so /_next assets do not collide.
  • Navigation inside a zone is soft; crossing zones is a hard navigation, so links across zones should be plain <a> tags and pages used together should share a zone.
  • Benefits: independent builds and deploys, smaller apps, team autonomy, even different frameworks. Costs: full reloads between zones, duplicated framework JavaScript, shared layout and design system drift, cross-zone Server Action origins, coordinated releases via feature flags.
  • Alternatives to consider first: route groups and code ownership in one app, monorepo build caching, or splitting only truly separate sections.

Clarifying questions expected:

  • "How often do users move between the sections we would split?" β€” frequent crossings make zones feel slow.
  • "Is the pain build time, deploy coupling, or team ownership?" β€” some of those have cheaper fixes.

Code / implementation expected: Yes β€” the rewrites in the default zone and the assetPrefix in the other zone.

  • nextjs
  • multi-zones
  • micro-frontends
  • architecture

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

10 min read Β· 9 sections

Read the code

Home zone next.config.ts: rewrite the blog paths to the blog zone
// home zone: next.config.ts
import type { NextConfig } from "next";
const BLOG_URL = process.env.BLOG_URL ?? "http://localhost:4187";
const nextConfig: NextConfig = {
  async rewrites() {
    return [
      { source: "/blog", destination: `${BLOG_URL}/blog` },
      { source: "/blog/:path+", destination: `${BLOG_URL}/blog/:path+` },
      { source: "/blog-static/:path+", destination: `${BLOG_URL}/blog-static/:path+` },
    ];
  },
};
export default nextConfig;
Blog zone next.config.ts: assetPrefix and allowed origins
// blog zone: next.config.ts
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  // Assets are served under /blog-static/_next/... so they never collide with the home zone
  assetPrefix: "/blog-static",
  experimental: {
    serverActions: {
      // the user-facing domain, needed when a proxy in front does not preserve the original host
      allowedOrigins: ["www.example.com"],
    },
  },
};

export default nextConfig;
Linking across zones: plain a tags, not next/link
// home zone: app/page.tsx
import Link from "next/link";
export default function Home() {
  return (
    <main>
      <h1>Home zone</h1>
      <Link href="/products" id="same-zone">Products (same zone)</Link>
      <a href="/blog" id="other-zone">Blog (other zone, plain a tag)</a>
      {/* Avoid: <Link href="/blog"> wastes an RSC request, then does a full load anyway */}
    </main>
  );
}

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 113 of 129 in Next.js

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

All Next.js questions
Up nextHard

Parallel routes (@slot) β€” how do you build a dashboard with independent slots?

Continue