Content Lake (Datastore)

Live Content API

The Live Content API is perfect for fast-moving events like sports, news, and commerce. Deliver real-time experiences at scale.

The Live Content API allows you to deliver live, dynamic experiences to your users without the complexity and scalability challenges that typically come with building real-time functionality. It is available on all plans, including free plans. See the pricing page for usage details.

Loading...

With the Live Content API, you can:

  • Subscribe to changes and receive notifications whenever documents are created, updated, or deleted.
  • Efficiently query for the exact content you need, and only receive updates for that content.
  • Scale to handle high volumes of live updates, even during peak traffic periods.

When to use the Live Content API

The Live Content API is designed to integrate into your existing application. It provides an interface for subscribing to content changes and receiving real-time updates.

Most sites and applications benefit from a mix of live and static content. For example, a news organization may want their homepage to use live content while article pages remain statically generated. In other cases, you may want islands of dynamic content to use the Live Content API in an otherwise statically generated application.

The Live Content API requires API version v2021-03-25 or later.

Usage limits and live connections

How Live Content works

Taking advantage of the Live Content API is a two-stage process, plus an optional third stage when you serve content through a CDN:

  • Clients listen for content identifiers we call sync tags. They map to specific requests, so changes in your dataset only trigger new tags for requests on the new content.
  • Clients query your data, listen for changes, and update content only when it changes.
  • Optional: If you serve content through a CDN, set up a Sanity Function to invalidate the cache to allow for live updates.

Our client libraries handle this process for you and provide helpers for building on top of the API. In Next.js, next-sanity also manages caching. By default it revalidates cached routes in the background, so some visitors keep seeing the previous content until that revalidation finishes. To guarantee that every visitor gets the update, deploy an Invalidate Sync Tags Function and set waitFor="function" on <SanityLive>. To start building, see Add live content to your application. For more on the underlying API, see the Live Content API reference and our example implementations.

Dataset aliases

Get started

Start implementing the Live Content API by following one of our guides or experimenting with an example project.

Additional resources

Was this page helpful?