DEV Community

Cover image for Serverless Containers vs Serverless Next.js SSR on AWS, GCP and Vercel
hexfloor
hexfloor

Posted on

Serverless Containers vs Serverless Next.js SSR on AWS, GCP and Vercel

ULTIMATE SUMMARY 2022

Introduction

We have so many tools to get the job done in cloud that it's easy to get lost, The Paradox in Choice
I'm writing this article to help you feel better by reducing the optionality. The main question is : do you want to have your application portable or you are satisfied with the dependency on a specific cloud provider. Naturally portability pays with complexity, have you ever heard about the multi stage build ? Let's get to it.

Common setup

In this guild I'm using yarn, next 12.2.0, react 18.2.0.

You may wish to get more information about the output standalone

The need to run an app in the container or with the node runtime is due to the next export limitations

I've got two domains : nextaws.tk and nextgcp.tk for the tests on freenom.

Deployments :

Limitations

First of all, check the Next.js deployment guide.
Known limitations :

  • Netx.js serverless announced in 2019 has been deprecated in 2021.
  • some features are not supported in the serverless mode, see SSR Amplify supported and unsupported Next.js features
  • internationalization doesn't seem to work out of the box in the serverless mode, you may be interested by issue_274, issue_911, issue_1311, issue_1490, issue_1552
  • when using some other modern libraries like tailwind, you have to update the Next.js version carefully or you may have some errors following the Next.js update. Nothing new in the javascript world, if something is working it's not guaranteed it will last :) It is important to really read the Next.js release notes as the base configuration may change in between the releases.
  • hosting of the Netx.js apps on Vercel naturally guarantees better feature and update support than hosting on any other cloud provider, consequently the technology itself is not cloud agnostic - it is what it is, as of today hosting in containers is more or less equivalent to the hosting on Vercel - it may change tomorrow, check on the serverless framework
  • as of today Next.js have better feature support in containers than in serverless mode and thus you have to be aware of the limitations
  • Next.js today offers great simplicity and performance, however at some point you are almost forced to switch to the SSR and thus the question should be formulated in the following way : are you ready to have the node.js serving js files on the server or you wish to have the js files executed in the browser only? You may often migrate to react by applying the From React to Next.js in reverse mode.

Summary

With all of the above I hereby may conclude that :

  • the best way to deploy a Next.js application is Vercel
  • the best way to deploy a Next.js application on GCP is Cloud Run
  • the best way to deploy a Next.js application on AWS is Amplify Lambda, however you will have to add custom i18n
  • at some point you will have to switch to SSR in yourNext.js application - this is the price to pay for the performance and the high-end look

I'm happy to use Next.js and at the same time I would appreciate to have more direction predictability. Quo vadis, Next.js ? Few years ago the move was towards serverless, today it's containers, will it be all-the-time-up-node-js instance tomorrow ? :) Next.js or There and Back Again.

Oldest comments (0)