Question presented to candidate:
"A user edits their profile and clicks Save. Separately, a CMS webhook tells us a blog post changed. And a notification badge in the header should update after the user marks something as read. Next.js 16 gives us revalidateTag, updateTag and refresh. Which one goes where, and why?"
What a strong answer should cover:
revalidateTag(tag, profile)marks tagged data stale; with"max"the next visitor gets the stale copy instantly while a background refresh runs (stale-while-revalidate). Works in Server Actions and Route Handlers, so it fits webhooks.updateTag(tag)expires the data immediately so the next read waits for fresh data: read-your-own-writes. Server Actions only; it throws elsewhere.refresh()invalidates no cache at all; it asks the client router to re-render the current page from a Server Action, so uncached parts update.- The one-argument
revalidateTag(tag)is deprecated and a TypeScript error in 16; it behaves like{ expire: 0 }. - From a webhook that needs the data gone now,
revalidateTag(tag, { expire: 0 })is the substitute forupdateTag.
Clarifying questions expected:
- "Does the person who made the change need to see it immediately?" β that is the
updateTagcase. - "Is the trigger a user action in our UI or an external system?" β a Route Handler cannot use
updateTagorrefresh.
Code / implementation expected: Yes β one Server Action per function and a webhook Route Handler.