๐—–๐—ฎ๐—ฐ๐—ต๐—ถ๐—ป๐—ด ๐—ฉ๐—ถ๐—ฑ๐—ฒ๐—ผ ๐—ฃ๐—ฎ๐—ด๐—ฒ๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—ฉ๐—ฎ๐—ฟ๐—ป๐—ถ๐˜€๐—ต ๐—˜๐—ฆ๐—œ

Our trending page used to crash during traffic spikes.

The problem was not slow rendering. The problem was the cache.

A typical page is a mix of different parts:

We used full-page caching. This meant the fastest-moving part, the view counter, forced the whole page to refresh every 60 seconds. This killed our database.

The fix: Stop caching pages. Start caching fragments.

We used Varnish with Edge Side Includes (ESI). Instead of one big object, we break the page into small pieces. Each piece has its own life cycle.

How ESI works:

This approach offers huge benefits:

We also use Varnish "Grace Mode." If a fragment expires, Varnish serves a slightly old version while it fetches a new one in the background. This prevents a "thundering herd" from hitting your origin at once.

If you run a read-heavy website, do not ask how long you can cache a page. Ask how long you can cache each piece of that page.

Source: https://dev.to/ahmet_gedik778845/caching-video-aggregator-pages-with-varnish-esi-and-edge-fragments-ep0