I have an idea for an RFC that I would like to write, based on some thoughts I had in the last months.
Lots of you probably know ESI, the specification written by Akamai and Oracle back in 2001.
It basically consists in a XML dialect which lets reverse proxies (eg. Varnish) cache fragments of your webpages in order not to hit your application for output fragments that can be re-used across many clients.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
A really good presentation about ESI is Caching On The Edge , by Fabien Potencier.
ESI’s context
ESI is a really great technology that recently gained hype, in my ecosystem (PHP), thanks to the Symfony2 architecture, fully embracing the HTTP specification: consider that Symfony2 has no application-level caching layer, so everything is done with the HTTP cache, and ESI is the solution for really dynamic webpages.
…but who’s responsible of processing ESI fragments? Digging some more, an esi processor can be a middleware in your architecture , a reverse proxy or a software component ; basically any kind of software implementing the ESI specification.
But hey, all this kind of things are softwares that lie on the server side.
A different approch
I was thinking about pushing ESI to the client side:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Seems a bad idea, since, if the browser is capable to merge different fragments, retrieved with different HTTP requests, for assembling a really simple webpage you would need to hit your application much more times than with a single request, so there is no real need to ask for ESI support in clients, in this scenario.
But there’s a real-world application of ESI on the client side that should save lot of traffic over the internet and lot of bandwith.
Rarely-changing output fragments.
A RCOF – sorry for this bad acronym – is everything that can be cached for relatively long time (talking more about days than hours), like Facebook’s footer or your google analytics JS code.
The use-case
Why should we always transport Facebook’s footer over the network?
We don’t need it: once the user landed on his profile page, as he jumps to other FB pages, the footer it’s always the same, and should be retrieved from the client’s cache instead of being sent over the network.
This means that once you send your response
1 2 3 4 5 6 7 |
|
the browser makes an additional request to retrieve the footer and then, on subsequent requests, also on different webpages, it can use the cached fragment:
1 2 3 4 5 6 7 |
|
because it recognizes that fragment has been already retrieved once you requested the “Your profile” page.
You probably don’t get the great aspect of ESI on the client side, so carefully read the next chapter.
A few numbers
Facebook’s footer is about 1.4k
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
while an ESI fragment is 0.5k
:
1
|
|
Calculating how much traffic the internet needs to sustain with the 2 approaches, traditional and ESIsh, is trivial:
- Facebook has something more than 400M daily users
- it has 12 pageviews per user
- retrieving the footer the traditional way, we add
1.5k
of data each users’ request - retrieving it with ESI, we add
1.5k
of data for the first users’ request,0.5k
for the consequent ones
Then we can extrapolate some data:
1 2 3 4 5 |
|
1 2 3 4 5 |
|
1 2 3 4 5 |
|
So, just for the footer, facebook could decrease the internet traffic by 2 and a half terabytes per day, just looking at its footer.
It’s obvious that this approach rewards facebook (it processes less stuff on his side, whether it uses a reverse proxy as gateway cache or not), ISPs and the final user, who’s taking advantage of a (more) lean network.
If you enlarge your vision, think about sites like Google, LinkedIN, twitter and all those web applications which send useless pieces of HTTP responses over the internet.
Client side ESI invalidation
If you are scared about invalidating this kind of cache, the solution would be really easy:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Note the revision change in the ESI tag, something we already, daily, use for managing static assets’ caching.
This is not a panacea
I don’t wanna sound arrogant proposing this tecnique, but I would really like to get feedbacks about such this kind of approach: as stated, this can be a great plus for the global network but its limited to RCOF.
The only aspect I haven’t considered yet is the second HTTP request the browser needs to do to retrieve the fragment, once, parsing the response, it finds an ESI tag: since I really don’t know how to calculate how it affects the network, so any kind of help would be appreciated.
The aim of this post is to consider if browser vendors should really start thinking about implementing ESI processors directly in their products, for a better, faster and leaner web.