Skip to content

Updated

Storage CDN

Knowing how the Storage cache works tells you why a first request is slower than the next one, and why public buckets cache better than private buckets. For how to remove an object from the cache, see Purge CDN cache.

How caching works

Supabase Storage caches every object you upload on a Content Delivery Network (CDN), to lower latency for users around the world. A CDN is a geographically distributed set of servers or nodes which cache content from an origin server. For Supabase Storage, the origin is the storage server running in the same region as your project. Aside from performance, CDNs also help with security and availability by mitigating Distributed Denial of Service (DDoS) and other application attacks.

For example, take a project in Singapore. Every request to its Storage API goes to the CDN first:

  1. A user in the United States requests an object and is routed to the U.S. CDN node. The node doesn't have the object in its cache yet, so it fetches it from the origin server in Singapore.

    Sequence diagram of a cache miss. The client sends a request to the Supabase CDN, which forwards it to the Supabase Storage server. The server returns the asset, the CDN caches it, and the CDN sends the response to the client.

  2. Another user in the United States requests the same object. The U.S. node serves it directly from its cache, without routing the request back to Singapore.

    Sequence diagram of a cache hit. The client sends a request to the Supabase CDN, which responds from its cache. The request never reaches the Supabase Storage server.

A CDN works similar to a library system. When a branch doesn't have the book you ask for, it orders a copy from the central library, then keeps it on the shelf for the next reader. A CDN node does the same with your objects.

The cf-cache-status response header shows the cache status of each request:

StatusMeaning
MISSThe CDN node didn't have the object, so it fetched it from the origin.
HITThe CDN node served the object from its cache.

When you measure cache hits in your logs, STALE, REVALIDATED, and UPDATING also count as hits. For how to query them, see Cache metrics.

Public vs private buckets

Public buckets cache better than private buckets, because Storage checks each user's permissions for objects in a private bucket. The following table compares the two when two users request the same object from the same region:

Public bucketPrivate bucket
AuthorizationNoneChecked for each object and user
Result for the first userCache missCache miss
Result for the next userCache hitCache miss, because each user can have different security policies
Cache hit rateHigherLower