Why I'm Using Express Instead of NextJS
Summary
TLDRIn this video, the speaker discusses why they opted for Express.js over Next.js for their project, highlighting the limitations of serverless architecture, including timeouts, lack of stateful connections, and cold start issues. They explain that serverless functions can timeout quickly, making them unsuitable for tasks like web scraping or real-time data handling. The cold start problem can lead to significant delays for initial requests, which can deter users. Ultimately, while Next.js offers advantages in cost-effectiveness and scalability, the specific needs of the project necessitate the use of a traditional server setup.
Takeaways
- 😀 Next.js is a powerful full-stack framework but not always the best fit for every project.
- 😀 The speaker chose Express.js over Next.js API routes for their current project due to specific limitations.
- 😀 Serverless functions can time out, making them unsuitable for tasks requiring longer execution times.
- 😀 AWS Lambda has a default timeout of 3 seconds, and Vercel's free plan limits execution to 10 seconds.
- 😀 Stateful connections, like websockets, cannot be maintained with serverless architecture, requiring external solutions.
- 😀 Using serverless functions often necessitates external memory management tools, such as Redis.
- 😀 The cold start problem can significantly delay the first request to a serverless function, sometimes up to 2 minutes.
- 😀 User experience suffers with long cold starts, leading to potential loss of users.
- 😀 Despite its advantages, serverless functions may not be ideal for applications requiring real-time processing.
- 😀 Ultimately, the speaker emphasizes that while Next.js is cost-effective and scalable, its limitations guided their decision to use Express.js.
Q & A
What is Next.js primarily used for?
-Next.js is a full-stack framework used for building server-rendered React applications.
Why is the speaker using Express.js instead of Next.js API routes?
-The speaker is using Express.js due to specific limitations of Next.js API routes for their project requirements.
What does 'serverless' mean in the context of Next.js?
-Serverless refers to a cloud architecture where you pay for execution time rather than maintaining a constantly running server.
What is one major limitation of serverless functions mentioned?
-Serverless functions have a timeout limit, meaning they cannot run for extended periods, typically ranging from 10 seconds to a few minutes.
How does the timeout affect certain applications like web scraping?
-Web scraping often requires longer execution times, which serverless functions cannot accommodate due to their timeout limitations.
What are WebSockets and why can't they be used with serverless functions?
-WebSockets are persistent connections to a server, but serverless functions can't maintain open connections as they terminate after execution.
What is the 'cold start' problem?
-The cold start problem occurs when the first request to a serverless function takes significantly longer to process because the underlying infrastructure needs to spin up.
How can the cold start problem affect user experience?
-If a function takes too long to respond due to cold starts, users may abandon their requests, leading to a poor user experience.
What are some advantages of using Next.js over a self-hosted Express server?
-Next.js offers better scalability, ease of management, and a pay-for-what-you-use pricing model, reducing infrastructure concerns.
Why does the speaker feel that using Next.js would be more cost-effective?
-Next.js would be more cost-effective because it allows payment only for the actual execution time, as opposed to running a dedicated server continuously.
Outlines
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowMindmap
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowKeywords
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowHighlights
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowTranscripts
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowBrowse More Related Video
My tech stack for 2025
Building a Serverless Data Lake (SDLF) with AWS from scratch
Where should you deploy your Next.js Project? |Â Serverless vs Serverful
Using serverless functions for real-time observability - Liz Fong-Jones - CPH DevFest 2024
How To Setup Your NextJS Codebase | Routes, Components, Data Access Layer etc
Stop Using JavaScript Fetch - Do This Instead!
5.0 / 5 (0 votes)