Question presented to candidate: "An editor publishes a change in the CMS and wants it live within seconds, not after the next hourly regeneration. How do you do that in Next.js, and when would you use a tag instead of a path?"
What a strong answer should cover:
revalidatePath(path)marks the cached output of one route as stale.revalidateTag(tag, profile)marks every cached fetch or 'use cache' entry with that tag as stale, across all routes that use it.- In Next.js 16
revalidateTagtakes a second argument; with'max'the next request is served stale while it refreshes, with{ expire: 0 }it refetches immediately. The single-argument form is deprecated. updateTagexpires a tag immediately for read-your-own-writes, but only inside Server Actions.- Trigger them from a Server Action after a mutation, or from a Route Handler used as a webhook.
Clarifying questions expected:
- "Is the change triggered by our own form or by an external system?" β Server Action versus webhook Route Handler.
- "Must the editor see the change on the very next request?" β decides between
max,expire: 0andupdateTag.
Code / implementation expected: Yes β tagging a fetch, a webhook that revalidates it, and a Server Action.