Questions
17 of 33
1Explain server-side rendering (SSR) in Next.js.
2List the benefits of Server-Side Rendering in Next.js.
3What are server components?
4How to use server components in next js?
5What is the React Server Component Payload (RSC)?
6Describe how server components are rendered.
7Describe server rendering strategies
8How can you keep Server-only Code out of the Client Environment
9What are the issues of using context provider at the root of the application?
10List dynamic functions available to server components.
11List all Dynamic APIs.
12How do we opt for Static Rendering, Dynamic Rendering and Streaming?
13Explain the difference between SSR, SSG, ISR, and CSR in Next.js. When would you choose each?
14How does getServerSideProps work internally? What is its execution context?
15What are the performance trade-offs of SSR vs SSG in a high-traffic production app?
16How does Next.js handle hydration? What is a hydration mismatch, and how do you debug it?
17What happens when getServerSideProps throws an error? How do you handle it gracefully?
18How would you architect a Next.js app that needs both personalised (SSR) and cacheable (SSG) pages at scale?
19Explain the App Router vs Pages Router SSR model differences. How does React Server Components change the SSR paradigm?
20How do React Server Components (RSC) differ from traditional SSR? Can they be used together?
21How does streaming SSR work in Next.js 13+? What role does Suspense play?
22How would you implement partial hydration or Islands Architecture in Next.js?
23Explain how Next.js handles data fetching waterfall problems in SSR and how you'd mitigate them.
24How would you implement partial hydration or Islands Architecture in Next.js?
25How do you implement caching strategies for SSR responses in Next.js? (CDN, Cache-Control, stale-while-revalidate)
26How would you reduce TTFB (Time to First Byte) in an SSR-heavy Next.js app?
27What's the difference between fetch caching in the App Router vs traditional getServerSideProps?
28How do you avoid redundant database/API calls across multiple server components on the same page?
29How do you securely handle authentication in SSR? What are the risks of passing tokens via cookies vs headers?
30How do you prevent sensitive server-side data from leaking to the client bundle?
31How would you implement role-based rendering on the server without exposing protected routes to the client?
32How do you debug SSR-only issues that don't appear in local development?
33How can we control dynamic rendering behaviour in next js?
17 / 33

What happens when getServerSideProps throws an error? How do you handle it gracefully?

When getServerSideProps throws an error, Next.js by default shows a 500 error page in production, but you can implement custom error handling with try-catch blocks, return notFound, or use custom error pages for graceful degradation

When an unhandled error occurs in getServerSideProps, Next.js's default behavior depends on the environment. In development, you'll see an error overlay with detailed debugging information. In production, Next.js shows a generic 500 Internal Server Error page to the user (customizable via pages/500.js or app/global-error.js). The request fails, no page is rendered, and the error is logged to the server console. However, this default behavior often provides poor user experience—a broken page instead of partial content or a graceful fallback. Proper error handling in getServerSideProps is essential for building resilient applications that can recover from API failures, database timeouts, or authentication issues.

Default Error Behavior (What Not to Do)
Error Handling Strategies
  1. 1

    Try-catch with fallback props: Catch errors and return partial data or empty states with a flag indicating an error occurred.

  2. 2

    Return notFound: When data is missing (404 case), return { notFound: true } to show the custom 404 page.

  3. 3

    Return redirect: For authorization failures, redirect to login or an error page.

  4. 4

    Custom error page: Use pages/_error.js or app/global-error.js to create branded 500 pages.

  5. 5

    Error boundary: In the App Router, wrap client components in error boundaries to handle rendering errors separately.

Strategy 1: Try-Catch with Fallback Props
Strategy 2: Return notFound for Missing Data
Strategy 3: Redirect on Auth Errors

Next.js allows you to create custom error pages that match your brand. In the Pages Router, pages/_error.js handles both 404 and 500 errors. In the App Router, app/global-error.js specifically handles errors in the root layout (must be a client component), and app/error.js handles errors in nested routes. These error pages can include branding, support links, and automatic retry mechanisms. Unlike the default error page, custom error pages maintain your site's look and feel during failures.

Strategy 4: Custom Error Pages
Advanced Error Handling Techniques
  1. 1

    Centralized logging: Integrate services like Sentry, LogRocket, or DataDog to capture errors from getServerSideProps with context (URL, params, headers).

  2. 2

    Retry logic: Implement exponential backoff retries for transient failures (network timeouts, database deadlocks).

  3. 3

    Partial data rendering: Return what data you can fetch successfully, with placeholders for failed sections.

  4. 4

    Circuit breakers: For external API failures, temporarily serve stale cached data instead of failing completely.

  5. 5

    Error categorization: Distinguish between client errors (4xx) and server errors (5xx) to show appropriate UI.

Advanced: Centralized Error Handling with Monitoring

In the App Router, the pattern changes because there's no getServerSideProps. Instead, you use async Server Components with try-catch blocks. Error handling is done via error.js files that create error boundaries around route segments. For data fetching errors, you can catch them and either render fallback UI or throw to the nearest error boundary. The App Router also provides notFound() and redirect() functions that can be called directly from Server Components.

App Router Error Handling Example
Difficulty: 5/10
Topics: error handling, SSR, fallback UI

Scenario Questions

0-2 years experience
  1. 1

    If getServerSideProps throws an exception while fetching data, what will the user see in the browser?

  2. 2

    How would you modify getServerSideProps to return a custom error page instead of the default Next.js error?

  3. 3

    What happens to the HTTP status code when an error is thrown inside getServerSideProps?

2-5 years experience
  1. 1

    You notice that a page sometimes shows a blank screen after a network timeout in getServerSideProps. Walk me through how you'd debug and fix it.

  2. 2

    Explain the trade‑offs between catching errors inside getServerSideProps and using Next.js error pages.

  3. 3

    If an external API call fails inside getServerSideProps, how would you ensure the page still renders with fallback data and an appropriate status code?

5-8 years experience
  1. 1

    Design a pattern for handling multiple independent data fetches in getServerSideProps where each can fail, ensuring the page degrades gracefully and logs errors centrally.

  2. 2

    Discuss how you would instrument getServerSideProps errors for monitoring in a high‑traffic production app, considering performance impact.

  3. 3

    When scaling to thousands of requests per second, what strategies would you use to prevent getServerSideProps failures from overwhelming your backend services?

8+ years experience
  1. 1

    Our monorepo contains many Next.js pages with duplicated error handling in getServerSideProps. How would you architect a reusable solution that works across teams while keeping type safety?

  2. 2

    If we plan to migrate from getServerSideProps to edge functions or static generation, how would you handle existing error handling logic to avoid regressions?

  3. 3

    Explain the long‑term maintenance implications of relying on try/catch inside getServerSideProps versus a global error handling middleware.

Follow-up Questions

  • Can you show a code snippet of your error handling approach?
  • What would you log, and where would you store those logs?
  • How does your solution affect SEO or caching?