Platform primitives /

Netlify Platform Primitives

Netlify Platform Primitives are framework-agnostic runtime features of our platform. They are used in our framework adapters to offer consistent functionality and freedom regardless of your chosen framework.

These primitives can also be used directly to transform stale pages and static pages into dynamic experiences that best suit your architectural strategy and needs:

  • Functions: Use serverless functions to add dynamic behavior to your site. Functions can be used for server-side rendering, API endpoints, and more.
  • Edge Functions: Edge Functions connect our platform with an open runtime standard at the network edge, allowing fast, personalized web experiences in a dev ecosystem.
  • Background Functions: Use Background Functions for long-running serverless functions that handle tasks like batch processing, scraping, and more.
  • Scheduled Functions: Enable Scheduled Functions to run serverless functions on a regular and consistent schedule, like a cron job.
  • Image CDN: Transform images on demand without impacting build times. Handle content negotiation automatically.
  • Blobs: Store and retrieve unstructured data. Use blob storage as a simple key/value store or basic database.
  • Fine-Grained Cache Control: Options for controlling cache behavior, including Stale-While-Revalidate (SWR) and on-demand cache invalidation.

# Functions

With Netlify Functions, your serverless functions are version-controlled, built, and deployed along with the rest of your Netlify site, and we will automatically handle service discovery through our built-in API gateway. This eliminates overhead and brings the power of Deploy Previews and rollbacks to your functions. During a build, we automatically generate functions for web frameworks that support server-side rendering and/or API endpoints. This is done though a build plugin or adapter for that framework.

If you are using a framework that does not support server-side rendering, you can still add dynamic behavior by creating functions directly.

# Edge Functions

Edge Functions connect the Netlify platform and workflow with an open runtime standard at the network edge. This enables you to build fast, personalized web experiences with an ecosystem of development tools.

Using TypeScript and JavaScript, you can modify network requests to localize content, serve relevant ads, authenticate users, personalize content, redirect visitors, and much more. Edge Functions also support a new generation of edge-first web frameworks allowing your entire app to run at the edge, dramatically increasing performance in many cases.

All this dynamic processing happens in a secure runtime based on Deno directly from the worldwide network edge location closest to each user for fast response times. Plus, you have the option to cache edge function responses for even faster response times. With Netlify, your edge functions are version-controlled, built, and deployed along with the rest of your Netlify site. This eliminates overhead and brings the power of Deploy Previews and rollbacks to your edge functions.

# Background Functions

This feature is in Beta and is available on Core Pro and Enterprise plans.

Netlify’s Background Functions provide an option for serverless functions that run for up to 15 minutes and don’t need to complete before a visitor can take next steps on your site. For tasks like batch processing, scraping, and slower API workflow execution, they may be a better fit than synchronous functions.

Learn more about Background Functions

# Scheduled Functions

This feature is in Beta.

Scheduled Functions is a feature of Netlify Functions that enables you to run functions on a regular and consistent schedule, much like a cron job. Scheduled functions can do almost anything that serverless functions do today, though some tasks are better suited to scheduled functions than others.

For example, you may want to:

  • Invoke a set of APIs to collate data for a report at the end of every week
  • Backup data from one data store to another at the end of every night
  • Build and/or deploy all your static content every hour instead of for every authored or merged pull request
  • Or anything else you can imagine you might want to invoke on a regular basis!

Learn more about Scheduled Functions

# Image CDN

With Netlify Image CDN, you can transform images on demand without impacting build times. Netlify Image CDN also handles content negotiation to use the most efficient image format for the requesting client. Optimizing the size and format of your images improves both the runtime performance and reliability of your site. Transformations are integrated natively into the CDN so that repeated requests leverage layers of caching for improved performance. Many frameworks on Netlify use Netlify Image CDN to power image optimization and transformation.

# Blobs

With Netlify Blobs, you can store and retrieve blobs and unstructured data. You can also use this feature as a simple key/value store or basic database.

Netlify Blobs is a highly-available data store optimized for frequent reads and infrequent writes.

For maximum flexibility, it offers a configurable consistency model. If multiple write calls to the same key are issued, the last write wins.

We automatically handle provisioning, configuration, and access control for you. This integrated zero-configuration solution helps you focus on building business value in your project rather than toil on setting up and scaling a separate blob storage solution.

# Fine-grained cache control

Netlify’s global caching infrastructure is built to provide stellar performance without any stale pages or broken assets for your visitors.

We offer fine-grained cache control options to help you manage additional caching requirements. Three key patterns are stale while revalidate, durable cache for serverless function responses, and on-demand cache invalidation.

# Stale while revalidate (SWR)

Stale while revalidate is a caching pattern that allows the cache to keep serving a stale object out of the cache while the object is revalidated in the background. This can be impactful for implementing API caching or patterns like incremental static regeneration (ISR).

As an example use case, imagine you have a slow API endpoint that takes 5 seconds to respond. You can wrap it in a function that adds the following cache header:

Netlify-CDN-Cache-Control: public, max-age=60, stale-while-revalidate=120

Here’s what this header does:

  • public instructs Netlify’s edge to cache the first response.
  • max-age=60 instructs the cache to continue serving the cached response for 60 seconds after the initial request. After 60 seconds, the cache is considered stale.
  • stale-while-revalidate=120 instructs the cache how long it can serve stale content. If a request arrives within this specified duration after the content expired, the stale content is served while the cache revalidates the content in the background.

If there’s a steady stream of requests, visitors will get recently refreshed results from the API without having to wait 5 seconds for the API response.

Here’s a timeline to illustrate how this works:

  1. An initial request generates a response that gets cached (consider this to be t = 0).
  2. A new request is made 30 seconds later (t = 30). The cache is still fresh, so the edge serves the cached response.
  3. Another request is made 100 seconds later (t = 130). The cache is now stale, but the time is within the 120 additional seconds allotted to serve stale content. So, the edge serves the stale cached response while the cache revalidates the content in the background. Time is reset (t = 0) when the revalidated response is cached.
  4. Another new request is made 4 minutes later (t = 240). The cache is stale again and the time is outside the allotment for serving stale content (which ended at t = 60 120 = 180). The edge waits for a new response to be generated before serving and caching it. Time is reset (t = 0) when the new response is cached.

This is a pattern used by some frameworks, but can also be implemented directly.

Learn more about the stale while revalidate directive

# Durable cache for serverless function responses

By default, when a site visitor makes a request to Netlify for content that is generated by a function, the specific edge node the visitor connects to checks only its own local cache. If fresh content is not found in that node’s cache, the node invokes the function to generate a new response. This means the function is typically invoked multiple times for the same content.

To reduce function invocations and response latency, you can use the durable directive for a function’s response. This makes it so that the response is not only returned to the edge node that invoked the function but also stored in a shared cache mechanism - the durable cache. Whenever that content is requested, edge nodes that don’t have the response locally cached check the durable cache, and only invoke a function if the response is not found there.

Learn more about the durable cache for serverless functions

# On-demand cache invalidation

If you want to invalidate cached objects while their cache control headers indicate they’re still fresh, you can purge the cache by site or cache tag. These granular options for refreshing your cache without redeploying your entire site optimize developer productivity for your team and site performance for your customers. On-demand invalidation across the entire network takes just a few seconds, even if you’re purging a tag associated with thousands of cached objects.

Learn more about on-demand cache invalidation