Easing Next.js Deployment: Preventing Static Export Overload

Img Vp Eqi E Mi M1i Ucgp Wycw Nxe Ns.png
Paul Grieselhuber

Paul Grieselhuber

Founder, director

Jun 27, 2019

Launching a large content website powered by Next.js comes with its own set of challenges, particularly when it comes to setting up the production environment. About three weeks from launch, our development team faced a critical issue with the Next.js static exports during deployment, a situation that is all too common in large-scale projects. A smooth deployment process is crucial, and the realization of unexpected errors can be daunting as the launch date approaches.

Understanding the Dreaded 502 Errors

When our team began testing static exports directly from the production server, we were immediately met with a barrage of 502 errors. The errors were caused by an overload on the server due to the static export process running on multiple threads. This kind of bottleneck is particularly problematic when considering the frequency of site exports needed to keep content refreshed. Identifying the root of these issues is the first step towards finding a solution.

In this scenario, running the export and the API so closely together led us to unintentionally DDoS our own server, highlighting the delicate nature of resource management. Streamlining the deployment process not only ensures the stability of the production environment but also addresses critical performance considerations for the site post-launch.

Optimizing for Stability and Performance

The key to resolving the 502 error crisis involved adjusting the Next.js export process to run on fewer threads and with reduced concurrency. This change is straightforward—simply updating the package.json file to incorporate these new settings. By tailoring the deployment scripts in this manner, we prevent self-DDoS and ensure a more stable setup.

However, it's worth noting that this remedy does come with a trade-off. Export times are significantly increased, which requires a thoughtful balance between build performance and server stability. Waiting for an hour-long export may seem tedious, but it's a small price to pay for a reliable production launch. Moving forward, ongoing tests will help determine the most effective configuration that doesn't compromise the health of the API.

If you're navigating similar challenges with Next.js or are curious to dive deeper into the intricacies of deploying large content sites efficiently, be sure to explore our continued series that also touches on Next.js and multiple Apollo Clients and GraphQL sources.

Paul Grieselhuber

Paul Grieselhuber

Founder, director

Paul has more than 15 years of experience in UX design and product engineering. Currently he runs Rendr Software Group.

Chat with our product engineers.

Our team of UX design and e-commerce experts look forward to discussing your project with you.