Click Below to Get the Code

Browse, clone, and build from real-world templates powered by Harper.
Tutorial
GitHub Logo

Trials and Tribulations of Self‑Hosting Next.js

Discover what it really takes to self-host Next.js beyond just running next start. Learn how Harper reimagined the entire Next.js lifecycle. Develop, Build, Deploy, and Run, to support clustered, bare-metal environments with hot reload, rolling deploys, multi-zone support, and more.
Tutorial

Trials and Tribulations of Self‑Hosting Next.js

By
Ethan Arrowood
June 24, 2025
By
Ethan Arrowood
June 24, 2025
By
Ethan Arrowood
June 24, 2025
June 24, 2025
Discover what it really takes to self-host Next.js beyond just running next start. Learn how Harper reimagined the entire Next.js lifecycle. Develop, Build, Deploy, and Run, to support clustered, bare-metal environments with hot reload, rolling deploys, multi-zone support, and more.
Ethan Arrowood
Senior Software Engineer
Co-authored by Austin Akers


next start” Isn’t Enough

We love Next.js. It’s an incredible framework for building modern web apps with React. But the moment you try to self‑host it—especially on bare metal or in clustered environments—you quickly learn that serverless hosts are doing a lot of heavy lifting.

We faced this firsthand at Harper, a platform that fuses a database, networking stack, and application runtime into one high‑performance Node.js engine. So, we asked: What does it really take to self‑host Next.js inside Harper? Spoiler: it’s way more than running next start.

This is the story of how we reimagined the Next.js lifecycle—Develop, Build, Deploy, and Run— within our platform.

Develop: Rebuilding next dev Internally

The Next.js dev server is magic. Hot Module Reloading (HMR), Fast Refresh, error overlays—everything just works. To replicate that inside Harper, we built:

  • A WebSocket-aware upgrade handler to inject hot-reload support into the Harper middleware.
  • A CLI wrapper, harperdb-nextjs dev, which boots Harper and then spins up a Next.js dev server with all the right wiring.
  • Seamless Hot Module Reloading via shared WebSocket channels between client and server.
Sequence diagram showing how HMR updates modules in the browser via WebSocket after file changes are detected by the dev server.

We dove deep into how WebSocket upgrades work in Node and exposed just enough of Harper’s networking stack to give Next.js what it needed.

Build: One Thread to Rule Them All

Harper is multi-threaded. So if we weren’t careful, every thread would build the app independently. Our fix:

  • Thread-locking to ensure only one thread triggers a build.
  • Shared artifact storage so other threads can reuse the output.
  • A harperdb-nextjs build command to kick off clean, single-threaded builds.
Flowchart detailing how threads manage file locks, handle stale states, and coordinate build execution to prevent concurrent access.

This let us avoid the explosion of duplicate builds while preserving concurrency where it matters.

Deploy: Rolling Your Own (Literally)

Production Harper instances often run as clustered nodes, replicated across regions. Replacing all of them at once? A disaster waiting to happen.

Instead, we built rolling deployment support, one node at a time:

  • Nodes take turns building and restarting.
  • Traffic shifts around them.
  • Zero downtime. Full data consistency.
Illustrates a rolling deployment strategy where updates are gradually applied across server groups while maintaining service availability and performance monitoring.

And the best part? This isn't just for Next.js—it's the same deploy system Harper uses for all components.

Run: Programmatic Next.js + Middleware Wizardry

We don’t use next start. Instead, we load Next.js programmatically:

const app = next({ dir: componentPath, dev: false });
await app.prepare();

Then we inject the request and WebSocket handlers directly into Harper’s middleware. This unlocks some wild capabilities:

  • Dynamic version loading: We require.resolve() the right Next.js version from the app’s package.json.
  • Multi-zone hosting: Several Next.js apps, each at different paths, running in one Harper process.
Shows how Harper routes client requests to zone-specific handlers and components using HTTP middleware across blog, store, and root apps.

This allows enterprise users to collapse complex micro-frontend setups into a single runtime—no hops, no hard navigation.

The Tricky Bits: Working Directory Problem

Next.js handles dynamic paths well. But some React tools assume process.cwd() reflects their app’s root. When you’re running multiple apps in one process, that assumption breaks.

We didn’t find a silver bullet here. Instead, we emphasize:

  • Explicit paths over relative ones.
  • Avoiding tools that depend on working directory voodoo.

It’s manageable—but worth flagging if you try this approach.

What’s Next? (Yes, Pun Intended)

We’re not done. Here’s what we’re working on now:

  • Smarter HTTP middleware to remove unnecessary redirects in multi-zone setups.
  • Next.js page cache ↔ Harper database integration to persist pre-rendered HTML and speed up cold starts.
  • Framework parity: bringing the same experience to Vue, Nuxt, Svelte, Astro, and more.

Conclusion

Self-hosting Next.js is far more involved than running a single command—but with the right approach, it can be both powerful and seamless. By rethinking each stage of the app lifecycle—develop, build, deploy, and run—we integrated Next.js deeply into Harper’s platform, unlocking support for features like multi-zone apps, rolling deployments, and dynamic versioning.

The result is a flexible, production-grade setup that gives teams full control without sacrificing the developer experience Next.js is known for.

Co-authored by Austin Akers


next start” Isn’t Enough

We love Next.js. It’s an incredible framework for building modern web apps with React. But the moment you try to self‑host it—especially on bare metal or in clustered environments—you quickly learn that serverless hosts are doing a lot of heavy lifting.

We faced this firsthand at Harper, a platform that fuses a database, networking stack, and application runtime into one high‑performance Node.js engine. So, we asked: What does it really take to self‑host Next.js inside Harper? Spoiler: it’s way more than running next start.

This is the story of how we reimagined the Next.js lifecycle—Develop, Build, Deploy, and Run— within our platform.

Develop: Rebuilding next dev Internally

The Next.js dev server is magic. Hot Module Reloading (HMR), Fast Refresh, error overlays—everything just works. To replicate that inside Harper, we built:

  • A WebSocket-aware upgrade handler to inject hot-reload support into the Harper middleware.
  • A CLI wrapper, harperdb-nextjs dev, which boots Harper and then spins up a Next.js dev server with all the right wiring.
  • Seamless Hot Module Reloading via shared WebSocket channels between client and server.
Sequence diagram showing how HMR updates modules in the browser via WebSocket after file changes are detected by the dev server.

We dove deep into how WebSocket upgrades work in Node and exposed just enough of Harper’s networking stack to give Next.js what it needed.

Build: One Thread to Rule Them All

Harper is multi-threaded. So if we weren’t careful, every thread would build the app independently. Our fix:

  • Thread-locking to ensure only one thread triggers a build.
  • Shared artifact storage so other threads can reuse the output.
  • A harperdb-nextjs build command to kick off clean, single-threaded builds.
Flowchart detailing how threads manage file locks, handle stale states, and coordinate build execution to prevent concurrent access.

This let us avoid the explosion of duplicate builds while preserving concurrency where it matters.

Deploy: Rolling Your Own (Literally)

Production Harper instances often run as clustered nodes, replicated across regions. Replacing all of them at once? A disaster waiting to happen.

Instead, we built rolling deployment support, one node at a time:

  • Nodes take turns building and restarting.
  • Traffic shifts around them.
  • Zero downtime. Full data consistency.
Illustrates a rolling deployment strategy where updates are gradually applied across server groups while maintaining service availability and performance monitoring.

And the best part? This isn't just for Next.js—it's the same deploy system Harper uses for all components.

Run: Programmatic Next.js + Middleware Wizardry

We don’t use next start. Instead, we load Next.js programmatically:

const app = next({ dir: componentPath, dev: false });
await app.prepare();

Then we inject the request and WebSocket handlers directly into Harper’s middleware. This unlocks some wild capabilities:

  • Dynamic version loading: We require.resolve() the right Next.js version from the app’s package.json.
  • Multi-zone hosting: Several Next.js apps, each at different paths, running in one Harper process.
Shows how Harper routes client requests to zone-specific handlers and components using HTTP middleware across blog, store, and root apps.

This allows enterprise users to collapse complex micro-frontend setups into a single runtime—no hops, no hard navigation.

The Tricky Bits: Working Directory Problem

Next.js handles dynamic paths well. But some React tools assume process.cwd() reflects their app’s root. When you’re running multiple apps in one process, that assumption breaks.

We didn’t find a silver bullet here. Instead, we emphasize:

  • Explicit paths over relative ones.
  • Avoiding tools that depend on working directory voodoo.

It’s manageable—but worth flagging if you try this approach.

What’s Next? (Yes, Pun Intended)

We’re not done. Here’s what we’re working on now:

  • Smarter HTTP middleware to remove unnecessary redirects in multi-zone setups.
  • Next.js page cache ↔ Harper database integration to persist pre-rendered HTML and speed up cold starts.
  • Framework parity: bringing the same experience to Vue, Nuxt, Svelte, Astro, and more.

Conclusion

Self-hosting Next.js is far more involved than running a single command—but with the right approach, it can be both powerful and seamless. By rethinking each stage of the app lifecycle—develop, build, deploy, and run—we integrated Next.js deeply into Harper’s platform, unlocking support for features like multi-zone apps, rolling deployments, and dynamic versioning.

The result is a flexible, production-grade setup that gives teams full control without sacrificing the developer experience Next.js is known for.

Discover what it really takes to self-host Next.js beyond just running next start. Learn how Harper reimagined the entire Next.js lifecycle. Develop, Build, Deploy, and Run, to support clustered, bare-metal environments with hot reload, rolling deploys, multi-zone support, and more.

Download

White arrow pointing right
Discover what it really takes to self-host Next.js beyond just running next start. Learn how Harper reimagined the entire Next.js lifecycle. Develop, Build, Deploy, and Run, to support clustered, bare-metal environments with hot reload, rolling deploys, multi-zone support, and more.

Download

White arrow pointing right
Discover what it really takes to self-host Next.js beyond just running next start. Learn how Harper reimagined the entire Next.js lifecycle. Develop, Build, Deploy, and Run, to support clustered, bare-metal environments with hot reload, rolling deploys, multi-zone support, and more.

Download

White arrow pointing right

Explore Recent Resources

Tutorial
GitHub Logo

Real-Time Pub/Sub Without the Stack

Explore a real-time pub/sub architecture where MQTT, WebSockets, Server-Sent Events, and REST work together with persistent data storage in one end-to-end system, enabling real-time interoperability, stateful messaging, and simplified service-to-device and browser communication.
Harper Learn
Tutorial
Explore a real-time pub/sub architecture where MQTT, WebSockets, Server-Sent Events, and REST work together with persistent data storage in one end-to-end system, enabling real-time interoperability, stateful messaging, and simplified service-to-device and browser communication.
A man with short dark hair, glasses, and a goatee smiles slightly, wearing a black shirt in front of a nature background.
Ivan R. Judson, Ph.D.
Distinguished Solution Architect
Tutorial

Real-Time Pub/Sub Without the Stack

Explore a real-time pub/sub architecture where MQTT, WebSockets, Server-Sent Events, and REST work together with persistent data storage in one end-to-end system, enabling real-time interoperability, stateful messaging, and simplified service-to-device and browser communication.
Ivan R. Judson, Ph.D.
Jan 2026
Tutorial

Real-Time Pub/Sub Without the Stack

Explore a real-time pub/sub architecture where MQTT, WebSockets, Server-Sent Events, and REST work together with persistent data storage in one end-to-end system, enabling real-time interoperability, stateful messaging, and simplified service-to-device and browser communication.
Ivan R. Judson, Ph.D.
Tutorial

Real-Time Pub/Sub Without the Stack

Explore a real-time pub/sub architecture where MQTT, WebSockets, Server-Sent Events, and REST work together with persistent data storage in one end-to-end system, enabling real-time interoperability, stateful messaging, and simplified service-to-device and browser communication.
Ivan R. Judson, Ph.D.
News
GitHub Logo

Harper Recognized on Built In’s 2026 Best Places to Work in Colorado Lists

Harper is honored as a Built In 2026 Best Startup to Work For and Best Place to Work in Colorado, recognizing its people-first culture, strong employee experience, and values of accountability, authenticity, empowerment, focus, and transparency that help teams thrive and grow together.
Announcement
News
Harper is honored as a Built In 2026 Best Startup to Work For and Best Place to Work in Colorado, recognizing its people-first culture, strong employee experience, and values of accountability, authenticity, empowerment, focus, and transparency that help teams thrive and grow together.
Colorful geometric illustration of a dog's head resembling folded paper art in shades of teal and pink.
Harper
News

Harper Recognized on Built In’s 2026 Best Places to Work in Colorado Lists

Harper is honored as a Built In 2026 Best Startup to Work For and Best Place to Work in Colorado, recognizing its people-first culture, strong employee experience, and values of accountability, authenticity, empowerment, focus, and transparency that help teams thrive and grow together.
Harper
Jan 2026
News

Harper Recognized on Built In’s 2026 Best Places to Work in Colorado Lists

Harper is honored as a Built In 2026 Best Startup to Work For and Best Place to Work in Colorado, recognizing its people-first culture, strong employee experience, and values of accountability, authenticity, empowerment, focus, and transparency that help teams thrive and grow together.
Harper
News

Harper Recognized on Built In’s 2026 Best Places to Work in Colorado Lists

Harper is honored as a Built In 2026 Best Startup to Work For and Best Place to Work in Colorado, recognizing its people-first culture, strong employee experience, and values of accountability, authenticity, empowerment, focus, and transparency that help teams thrive and grow together.
Harper
Comparison
GitHub Logo

Harper vs. Standard Microservices: Performance Comparison Benchmark

A detailed performance benchmark comparing a traditional microservices architecture with Harper’s unified runtime. Using a real, fully functional e-commerce application, this report examines latency, scalability, and architectural overhead across homepage, category, and product pages, highlighting the real-world performance implications between two different styles of distributed systems.
Comparison
A detailed performance benchmark comparing a traditional microservices architecture with Harper’s unified runtime. Using a real, fully functional e-commerce application, this report examines latency, scalability, and architectural overhead across homepage, category, and product pages, highlighting the real-world performance implications between two different styles of distributed systems.
Person with short dark hair and moustache, wearing a colorful plaid shirt, smiling outdoors in a forested mountain landscape.
Aleks Haugom
Senior Manager of GTM & Marketing
Comparison

Harper vs. Standard Microservices: Performance Comparison Benchmark

A detailed performance benchmark comparing a traditional microservices architecture with Harper’s unified runtime. Using a real, fully functional e-commerce application, this report examines latency, scalability, and architectural overhead across homepage, category, and product pages, highlighting the real-world performance implications between two different styles of distributed systems.
Aleks Haugom
Dec 2025
Comparison

Harper vs. Standard Microservices: Performance Comparison Benchmark

A detailed performance benchmark comparing a traditional microservices architecture with Harper’s unified runtime. Using a real, fully functional e-commerce application, this report examines latency, scalability, and architectural overhead across homepage, category, and product pages, highlighting the real-world performance implications between two different styles of distributed systems.
Aleks Haugom
Comparison

Harper vs. Standard Microservices: Performance Comparison Benchmark

A detailed performance benchmark comparing a traditional microservices architecture with Harper’s unified runtime. Using a real, fully functional e-commerce application, this report examines latency, scalability, and architectural overhead across homepage, category, and product pages, highlighting the real-world performance implications between two different styles of distributed systems.
Aleks Haugom
Tutorial
GitHub Logo

A Simpler Real-Time Messaging Architecture with MQTT, WebSockets, and SSE

Learn how to build a unified real-time backbone using Harper with MQTT, WebSockets, and Server-Sent Events. This guide shows how to broker messages, fan out real-time data, and persist events in one runtime—simplifying real-time system architecture for IoT, dashboards, and event-driven applications.
Harper Learn
Tutorial
Learn how to build a unified real-time backbone using Harper with MQTT, WebSockets, and Server-Sent Events. This guide shows how to broker messages, fan out real-time data, and persist events in one runtime—simplifying real-time system architecture for IoT, dashboards, and event-driven applications.
A man with short dark hair, glasses, and a goatee smiles slightly, wearing a black shirt in front of a nature background.
Ivan R. Judson, Ph.D.
Distinguished Solution Architect
Tutorial

A Simpler Real-Time Messaging Architecture with MQTT, WebSockets, and SSE

Learn how to build a unified real-time backbone using Harper with MQTT, WebSockets, and Server-Sent Events. This guide shows how to broker messages, fan out real-time data, and persist events in one runtime—simplifying real-time system architecture for IoT, dashboards, and event-driven applications.
Ivan R. Judson, Ph.D.
Dec 2025
Tutorial

A Simpler Real-Time Messaging Architecture with MQTT, WebSockets, and SSE

Learn how to build a unified real-time backbone using Harper with MQTT, WebSockets, and Server-Sent Events. This guide shows how to broker messages, fan out real-time data, and persist events in one runtime—simplifying real-time system architecture for IoT, dashboards, and event-driven applications.
Ivan R. Judson, Ph.D.
Tutorial

A Simpler Real-Time Messaging Architecture with MQTT, WebSockets, and SSE

Learn how to build a unified real-time backbone using Harper with MQTT, WebSockets, and Server-Sent Events. This guide shows how to broker messages, fan out real-time data, and persist events in one runtime—simplifying real-time system architecture for IoT, dashboards, and event-driven applications.
Ivan R. Judson, Ph.D.
Podcast
GitHub Logo

Turn Browsing into Buying with Edge AI

Discover how Harper’s latest features streamline development, boost performance, and simplify integration. This technical showcase breaks down real-world workflows, powerful updates, and practical tips for building faster, smarter applications.
Select*
Podcast
Discover how Harper’s latest features streamline development, boost performance, and simplify integration. This technical showcase breaks down real-world workflows, powerful updates, and practical tips for building faster, smarter applications.
Person with short hair wearing a light blue patterned shirt, smiling widely outdoors with blurred greenery and trees in the background.
Austin Akers
Head of Developer Relations
Podcast

Turn Browsing into Buying with Edge AI

Discover how Harper’s latest features streamline development, boost performance, and simplify integration. This technical showcase breaks down real-world workflows, powerful updates, and practical tips for building faster, smarter applications.
Austin Akers
Dec 2025
Podcast

Turn Browsing into Buying with Edge AI

Discover how Harper’s latest features streamline development, boost performance, and simplify integration. This technical showcase breaks down real-world workflows, powerful updates, and practical tips for building faster, smarter applications.
Austin Akers
Podcast

Turn Browsing into Buying with Edge AI

Discover how Harper’s latest features streamline development, boost performance, and simplify integration. This technical showcase breaks down real-world workflows, powerful updates, and practical tips for building faster, smarter applications.
Austin Akers