Questions
14 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?
14 / 33

How does getServerSideProps work internally? What is its execution context?

getServerSideProps executes on the server for every request, with full access to the request/response objects and Node.js runtime, returning serializable props that are used to pre-render the page HTML before sending to the client

Internally, getServerSideProps is a Next.js function designed for Server-Side Rendering (SSR) that runs exclusively on the server at request time. When a request hits a page with getServerSideProps, Next.js executes this function first, providing it with rich context about the request. The function can perform any server-side operations—database queries, API calls, authentication checks—and must return a serializable object. Next.js then uses the returned props to render the React component to HTML on the server, sending the fully-formed page to the client. This entire process happens synchronously per request, ensuring the page always reflects the latest data.

Basic getServerSideProps Example
The Context Parameter: What's Available
  1. 1

    params: Contains dynamic route parameters. For a page named [id].js, params will be { id: 'value' }.

  2. 2

    req: The HTTP IncomingMessage object with an additional cookies property for accessing cookies as key-value pairs.

  3. 3

    res: The HTTP response object, allowing you to set headers, cookies, or status codes directly.

  4. 4

    query: An object containing the query string parameters plus any dynamic route parameters.

  5. 5

    draftMode: Boolean indicating if draft mode is enabled (replaces deprecated preview/previewData).

  6. 6

    resolvedUrl: Normalized URL string without the _next/data prefix.

  7. 7

    locale/locales/defaultLocale: Available when i18n is configured.

When a request arrives, Next.js checks if the page exports getServerSideProps. If yes, it enters SSR mode: First, it calls getServerSideProps with the context object populated from the request. The function executes in a Node.js environment with full server capabilities—direct database access, file system operations, or internal API calls are all safe here because this code never reaches the client. Next.js then awaits the returned promise, expecting an object with props, notFound, or redirect. If props are returned, Next.js serializes them with JSON.stringify and passes them to the page component for rendering on the server. The complete HTML is generated and sent to the client, with the props also embedded in a script tag for hydration.

Internal Request Flow Visualization
Execution Context Characteristics
  1. 1

    Server-only execution: Code inside getServerSideProps never reaches the client bundle. You can safely use environment variables, database connections, and file system APIs.

  2. 2

    Request-scoped: Runs on every request, not cached. Each user gets fresh data tailored to their specific request context.

  3. 3

    Node.js runtime: Full Node.js API access (in default setup). This means you can use fs, read from disk, or connect to databases directly.

  4. 4

    Not bundled for client: All imports used only in getServerSideProps are automatically tree-shaken from client bundles.

  5. 5

    Serializable requirement: Props must be JSON-serializable because they're embedded in the HTML for client hydration.

  6. 6

    Timing: Executes before page render, blocking the response until complete. Long-running operations delay page load.

When users navigate between pages using next/link or next/router, getServerSideProps still runs on the server, but the mechanism differs slightly. Next.js makes a lightweight API request to _next/data/development/{url}.json (or production equivalent) which triggers getServerSideProps execution and returns only the JSON props, not the full HTML. The client then uses these props to render the page without a full reload, maintaining SPA-like navigation while still fetching fresh data per request. This is why you can't have loading states inside getServerSideProps—it's a blocking function that must complete before navigation finishes.

Cache Control with getServerSideProps
Important Constraints and Gotchas
  1. 1

    Page-only export: getServerSideProps can only be exported from page files (not components, not API routes).

  2. 2

    No client-side data: Never put sensitive data in props—they're embedded in HTML and visible in page source.

  3. 3

    Error handling: Thrown errors show the 500.js page in production, with error overlay in development.

  4. 4

    No getStaticProps mixing: Cannot use both getServerSideProps and getStaticProps on the same page.

  5. 5

    Performance consideration: Each request triggers server execution, which can increase response times and server load.

  6. 6

    Development vs Production: In dev mode, getServerSideProps runs on every request regardless of caching headers.

Choose getServerSideProps when you absolutely need request-time data—authenticated content, personalized pages, or data that changes faster than you can rebuild. It's perfect for dashboards, user profiles, and any page where the content is different for every visitor. However, for public content that changes less frequently, prefer getStaticProps with ISR—you'll get similar freshness with much better performance and lower server costs. And if the page doesn't need initial data at all, consider client-side fetching after a static shell for the best balance of performance and freshness.

Difficulty: 6/10
Topics: SSR lifecycle, execution context, data fetching

Scenario Questions

0-2 years experience
  1. 1

    If you need to fetch a list of products from an internal API and render it on a page, how would you use getServerSideProps to do that?

  2. 2

    What happens if you accidentally call window.localStorage inside getServerSideProps? Explain the result.

2-5 years experience
  1. 1

    Your page started returning stale data after deploying a new version. How would you investigate whether getServerSideProps caching or headers are causing the issue?

  2. 2

    You need to protect a route with authentication using getServerSideProps. Walk me through how you would access cookies and redirect unauthenticated users.

  3. 3

    During a load test, you notice getServerSideProps is a bottleneck. What strategies could you employ to reduce its latency without moving to static generation?

5-8 years experience
  1. 1

    Design a pattern for sharing a database connection pool across multiple getServerSideProps calls in a large Next.js app. What trade‑offs do you consider?

  2. 2

    Explain how you would implement incremental static regeneration alongside getServerSideProps for a hybrid page that needs both fresh data and fast response times.

  3. 3

    If a third‑party API you call inside getServerSideProps occasionally times out, how would you make the page resilient while preserving SSR benefits?

8+ years experience
  1. 1

    Your organization is migrating a monolithic Next.js site to a micro‑frontend architecture. How would you decide which pages should stay as getServerSideProps versus moving to edge functions or static rendering?

  2. 2

    Discuss the long‑term maintenance implications of heavily relying on getServerSideProps for personalization across the platform. How would you structure teams and contracts to manage performance, cost, and developer experience?

Follow-up Questions

  • What would happen if you try to use a browser‑only API inside getServerSideProps?
  • How does Next.js handle an exception thrown from getServerSideProps?
  • Can you control HTTP caching for responses generated by getServerSideProps, and if so, how?