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

How would you reduce TTFB (Time to First Byte) in an SSR-heavy Next.js app?

Reduce TTFB in SSR-heavy Next.js apps by implementing caching strategies, optimizing data fetching, leveraging CDN edge, using streaming SSR, and migrating to ISR where possible

Time to First Byte (TTFB) measures the duration between the browser requesting a page and receiving the first byte of response. In SSR-heavy Next.js applications, high TTFB is often caused by server processing time, data fetching latency, or geographic distance. Reducing TTFB requires a multi-layered approach: caching at CDN edge, optimizing database queries and API calls, using streaming to send content progressively, and strategically migrating from SSR to ISR for cacheable content. With Next.js 13+ and modern deployment platforms, you can achieve sub-100ms TTFB even for dynamic pages through these techniques.

Core Strategies for TTFB Reduction
  1. 1

    Implement caching headers with stale-while-revalidate to serve cached responses from CDN edge

  2. 2

    Use Incremental Static Regeneration (ISR) for pages that don't need per-request freshness

  3. 3

    Optimize data fetching with parallel requests, database indexing, and connection pooling

  4. 4

    Leverage streaming SSR with Suspense to send HTML progressively, reducing perceived TTFB

  5. 5

    Deploy to edge platforms (Vercel Edge, Cloudflare) to minimize geographic latency

  6. 6

    Prefetch data with middleware or early hints to start processing before page request completes

Strategy 1: Implement CDN Caching with stale-while-revalidate

If your page doesn't need truly per-request data (e.g., user-specific content), ISR can dramatically reduce TTFB. ISR generates static HTML at build time or on-demand, serving it from CDN edge instantly. Even with revalidation, the first byte comes from cache while regeneration happens in background. For pages that were previously SSR but have cacheable content, this can reduce TTFB from 300-500ms to under 50ms.

Strategy 2: Convert SSR to ISR
Strategy 3: Optimize Data Fetching
  1. 1

    Parallelize database queries with Promise.all instead of sequential awaits

  2. 2

    Implement database indexing on frequently queried fields (foreign keys, slugs, timestamps)

  3. 3

    Use connection pooling to avoid overhead of establishing new database connections per request

  4. 4

    Consider Redis or Memcached for frequently accessed data to bypass database entirely

  5. 5

    Create database read replicas to distribute load and reduce contention

  6. 6

    Use edge-optimized databases like PlanetScale or Turso that are geographically distributed

Strategy 3: Optimized Data Fetching Patterns

Streaming SSR, introduced in Next.js 13 with the App Router, fundamentally changes TTFB perception. Instead of waiting for all data to load before sending anything, the server sends the static shell (layout, navigation, fallbacks) immediately—often in under 100ms. Data-dependent components stream in as they resolve. This means the user sees content almost instantly, even if the full page takes seconds to load. The technical TTFB for the first byte is dramatically lower because the server doesn't block on slow data fetching.

Strategy 4: Streaming with Suspense
Strategy 5: Edge Deployment and Geographic Distribution
  1. 1

    Deploy to platforms with global edge networks (Vercel Edge, Cloudflare Workers, Netlify Edge)

  2. 2

    Edge functions run closer to users, reducing network latency from 200ms (cross-continent) to under 50ms

  3. 3

    Use geographically distributed databases or CDN-based data caching

  4. 4

    Consider region-specific deployments for compliance and performance

  5. 5

    Implement CDN with regional edge caches to serve static assets from nearest location

Strategy 5: Edge Runtime Configuration

Early Hints (HTTP status 103) allows the server to send hints to the browser about critical resources before the full response is ready. This enables the browser to start loading CSS, fonts, and JavaScript while the server is still generating the page. For SSR-heavy apps, this can significantly reduce perceived TTFB by parallelizing resource loading with server processing. Vercel supports 103 Early Hints automatically, and you can implement custom hints in middleware.

Strategy 6: 103 Early Hints Implementation
Strategy 7: Reduce Server-Side Processing Time
  1. 1

    Optimize JavaScript execution: minimize heavy computations in getServerSideProps

  2. 2

    Avoid synchronous file system operations or CPU-intensive tasks during rendering

  3. 3

    Use WebAssembly for compute-heavy operations where appropriate

  4. 4

    Consider offloading expensive operations to background jobs or queues

  5. 5

    Implement response compression (gzip/brotli) to reduce payload size

  6. 6

    Optimize image processing: use Next.js Image component with external loaders

Strategy 7: Server Optimization Example

To effectively reduce TTFB, you need to measure it accurately. Use browser DevTools (Network tab) to see TTFB for each request. For production monitoring, integrate with RUM (Real User Monitoring) tools like Vercel Analytics, Cloudflare Web Analytics, or Sentry. Track TTFB percentiles (p50, p75, p95, p99) to understand the distribution. Use server-side logging with timing information to identify slow operations. Compare TTFB across different geographic regions to catch latency issues. Set up alerts for TTFB degradation to catch regressions early.

TTFB Measurement and Monitoring
Progressive Optimization Checklist
  1. 1

    Start with caching headers on all SSR routes (immediate win)

  2. 2

    Identify routes that can migrate to ISR and convert them

  3. 3

    Profile database queries and add indexes where needed

  4. 4

    Implement parallel data fetching in getServerSideProps

  5. 5

    Add Suspense boundaries to critical SSR routes

  6. 6

    Deploy to edge platform if not already

  7. 7

    Monitor TTFB metrics and set up alerts

  8. 8

    A/B test each optimization to measure impact