2942 views • Backend System Design
GIPHY serves 10 billion GIFs every day, here’s how it beautifully uses different features of CDN.
Think of CDN as a geographically distributed cache; and just like any regular cache, it sits between the user and the origin.
For any request, if it has the data, it serves the response. If not, it hits the origin to grab the data, cache it, and then responds.
A key highlight of using a CDN is geographical nearness. Because the CDN servers are distributed worldwide, the request from a user is served from the nearest edge server giving an excellent UX.
This is a no-brainer application of CDN. Giphy serves all the media content like images and videos through CDN that sits transparently between the user and the origin (eg: S3).
Apart from the media content, Giphy uses CDN to cache API responses of Search and Discover APIs like
It serves these APIs from CDN because the responses of these APIs do not change often; hence using CDN for this reduces the load on API servers.
Not all APIs or media objects need to be cached on CDN for the same amount of time. Hence Giphy configures different expirations for different types of APIs.
Media object endpoints are cached longer while trending API is cached for a shorter duration.
Sometimes, it is the backend server that should dictate for how long the response should be cached.
Hence, Giphy, in the HTTP response from the origin server provides
max-age headers that tell CDN the TTL for the specific response. This gives finer control over key expiration.
Giphy uses Surrogate Keys (tags) while caching endpoints on CDN. It helps in smarter cache invalidation, eg:
If you like what you read subscribe you can always subscribe to my newsletter and get the post delivered straight to your inbox. I write essays on various engineering topics and share it through my weekly newsletter.
924 views • 54 likes • 2022-11-14
When a company scales, they adopt microservices and each service typically gets its own independent database. With data ...
2206 views • 98 likes • 2022-11-07
Authorization plays a critical role in ensuring that the platform is not abused. For example, Instagram ensures that if ...
2572 views • 152 likes • 2022-10-31
Do hyperlocal companies like Uber, Ola, Swiggy, Gojek, Zomato, etc share our phone numbers with the delivery people or t...
2193 views • 81 likes • 2022-10-24
Elasticsearch is a great search engine, but Yelp was not happy with its performance, so they built their own HTTP layer ...
A set of courses designed to make you a better engineer and excel at your career; no-fluff, pure engineering.
Being a passionate engineer, I love to talk about a wide range of topics, but these are my personal favourites.
Arpit's Newsletter read by 21000+ engineers
Weekly essays on real-world system design, distributed systems, or a deep dive into some super-clever algorithm.
Powered by this tech stack.