16 / 20

How do you avoid build-time data staleness in SSG?

Difficulty: 5/10
ISR, revalidation, data fetching

Avoid build-time data staleness in SSG by using ISR for background updates, implementing on-demand revalidation via webhooks, leveraging client-side data fetching for dynamic content, and adopting hybrid rendering strategies

Build-time data staleness is an inherent challenge with Static Site Generation (SSG)—pages are generated at build time and remain fixed until the next build. As your content changes in your CMS, database, or API, users may see outdated information. Next.js provides several strategies to combat this staleness without sacrificing the performance benefits of static generation: Incremental Static Regeneration (ISR), on-demand revalidation, client-side data fetching for dynamic portions, and hybrid architectures that combine static shells with live data updates.

Primary Strategies for Avoiding Staleness
  1. 1

    Incremental Static Regeneration (ISR): Set a revalidate time (e.g., 60 seconds) to automatically regenerate pages in the background when content becomes stale .

  2. 2

    On-Demand Revalidation: Trigger immediate cache invalidation via revalidatePath or revalidateTag when content actually changes (e.g., via CMS webhooks) .

  3. 3

    Client-side data fetching: Fetch real-time data in browser after the static page loads, keeping the static shell fast while ensuring fresh content .

  4. 4

    Hybrid approach: Use SSG for stable content (product descriptions, blog posts) and client-side fetching for dynamic elements (inventory, comments, prices) .

  5. 5

    Time-based rebuilds: For simple sites, schedule periodic rebuilds (e.g., every hour via cron jobs) to refresh content, though this is less efficient than ISR .

Strategy 1: ISR with Time-Based Revalidation
Strategy 2: On-Demand Revalidation with Webhooks

For highly dynamic data that changes frequently (like inventory levels, live comments, or user-specific content), the best approach is often to serve a static shell and fetch the dynamic data on the client. This gives you the performance benefits of SSG for the static content while ensuring users always see fresh data for the dynamic parts. The pattern is especially effective when combined with WebSockets or Server-Sent Events for real-time updates .

Strategy 3: Client-Side Data Hydration
Strategy 4: Hybrid Rendering with Selective ISR
  1. 1

    Critical vs. non-critical content: Use different revalidation strategies for different parts of your site. Product names and descriptions might use ISR with longer intervals (hours), while prices might use shorter intervals (minutes) or client-side fetching .

  2. 2

    Segment-specific configuration: Next.js allows setting revalidate at the segment level via export const revalidate = value in layouts or pages, giving fine-grained control .

  3. 3

    Combined approach: For maximum freshness, use on-demand ISR for core content changes (triggered by CMS webhooks) plus client-side polling for rapidly changing data like stock levels .

  4. 4

    Static with fallback: Use fallback: 'blocking' (Pages Router) or dynamicParams: true (App Router) to generate rarely-accessed pages on-demand while keeping popular pages pre-rendered .

Strategy 4: Selective ISR with Different Revalidate Windows

Next.js ISR implements the stale-while-revalidate caching pattern. When a page is requested after its revalidate time, Next.js serves the stale (cached) page immediately while triggering a background regeneration. This means users never wait for the page to generate—they see content instantly, and the next user gets the fresh version. This pattern is acceptable for most content types where slight staleness is preferable to slow page loads. The key is setting appropriate revalidate times based on how quickly content becomes outdated .

Strategy 6: Scheduled Rebuilds via CI/CD
  1. 1

    When to use: For sites where ISR isn't feasible (e.g., static export) or content changes predictably on a schedule .

  2. 2

    Implementation: Set up cron jobs (GitHub Actions, Vercel Cron Jobs, AWS EventBridge) to trigger rebuilds at specific intervals .

  3. 3

    Trade-offs: Simple to implement but rebuilds take time and may waste resources if content hasn't actually changed .

  4. 4

    Example: A news site that publishes daily at 8 AM can schedule a rebuild for 8:05 AM each day, ensuring fresh morning content .

Strategy 7: CDN Cache Invalidation Coordination

The best approach depends on your content characteristics: For content that changes predictably (blog posts, articles), ISR with time-based revalidation works well. For content that updates sporadically (product prices, inventory), on-demand revalidation triggered by your CMS or database is ideal. For highly dynamic content (live comments, stock ticks), client-side fetching after static shell is the right choice. Most production sites combine multiple strategies—using ISR for core content, on-demand for important updates, and client-side for real-time elements—to balance performance with freshness .

Scenario Questions

0-2 years experience

  1. 1We have a blog built with Next.js using getStaticProps. If a new post is added after the site is built, what will users see and how would you change the setup to ensure the new post appears without a full redeploy?
  2. 2Imagine you need to show a list of products that updates daily. How would you configure Next.js to fetch that data at build time but also keep it fresh without manual rebuilds?
  3. 3If a page generated at build time is showing outdated pricing, what quick fix could you apply to mitigate the staleness before the next deployment?

2-5 years experience

  1. 1Our marketing team wants the homepage to reflect the latest promotional banner, which changes multiple times a day. Walk me through how you'd implement this in Next.js, considering ISR vs client‑side fetching, and what trade‑offs you'd evaluate.
  2. 2During a recent release, a page that uses getStaticProps started showing stale data after a content update in the CMS. How would you debug why the page didn't refresh, and what changes would you make to prevent it?
  3. 3We have a Next.js site deployed on Vercel with a 60‑second revalidate interval, but some data changes more frequently. How would you adjust the strategy to balance build cost and data freshness?

5-8 years experience

  1. 1Design a strategy for a large e‑commerce catalog (hundreds of thousands of products) that needs near‑real‑time inventory levels while still leveraging SSG for SEO. Discuss how you'd combine ISR, on‑demand revalidation, and edge caching, and the operational implications.
  2. 2Our monorepo contains multiple Next.js apps sharing a common data layer. How would you architect a reusable solution to avoid build‑time staleness across all apps, handling rate‑limited APIs and ensuring consistency?
  3. 3Explain how you'd monitor and alert on stale data issues in a production Next.js SSG site, including metrics, logs, and fallback mechanisms.

8+ years experience

  1. 1We are planning to migrate a legacy server‑rendered site to Next.js with SSG for most pages. How would you define a long‑term data freshness policy that scales across teams, supports multiple data sources, and minimizes coordination overhead?
  2. 2Consider a multi‑regional deployment where some regions have stricter latency requirements. How would you design a global data invalidation and revalidation system for SSG pages that ensures consistency while respecting regional caches?
  3. 3What governance model would you put in place to ensure that developers across squads correctly use ISR/revalidate options, and how would you enforce it through tooling, CI, and documentation?

Follow-up Questions

  • What impact does a short revalidate interval have on your build pipeline?
  • How would you handle a third‑party API that limits request rates when using ISR?
  • Can you describe a fallback you’d use if revalidation fails at the edge?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.