Code

CDN: Living in the Modern “Edge”

Patricio Echague on April 6, 2016

Every young company faces the problem of scaling out infrastructure and increasing the throughput servers can sustain in order to provide a better customer experience and serve more customers without doubling resources.

Of course, caching static assets is a good way to alleviate the load in your web servers, but in our case the vast majority of traffic comes through our SDKs. As we scale, we are looking at different caching strategies to speed up our API servers in order to increase the throughput our infra can provide.

CDNs have come a long way since they were used to serve static assets like images (.png, .jpeg, etc.), Javascript files, and stylesheets (.css). After a bit of research, we found that CDNs like Fastly can be used to cache the results of API endpoints just as if you have a cache layer (Redis, Elasticache, Memcached) in front of your servers. Furthermore, CDNs have many POP (Points of Presence) all over the world, which means they are close enough to our customers to create only a small latency between the cached asset and our clients (the SDKs).

Caching alone is not enough when you look at speeding up your API services, however. The return values of your endpoints are very likely to change (sometimes very quickly), so the ability to immediately purge those cached values at the CDN edge play an important role in avoiding serving stale data for a long period of time. One of the features we like about Fastly is the instant purging time of the cached assets, which makes it one of the best CDNs out there when it comes to caching APIs. Solutions like CloudFront are less ideal in this case because their purging periods vary from 5 to 15 minutes. We also evaluated MaxCDN, which failed to match such a fast purging speed at the time, though they seem to be moving in that direction now.

In order to reduce the friction of interfacing with Fastly from Java, we contributed with a tiny Open Source wrapper for their API, which can be found in Github.

Take a look and let us know what you think—feedback and feature requests are always welcome.

And if this type of work interests you, we are always looking for great engineers to help us solve complex problems. Check out our job openings to learn more.

We're Hiring!

Join the Team