How Giphy uses CDN to serve a billion GIFs every day



4931 views Backend System Design



GIPHY serves 10 billion GIFs every day, here’s how it beautifully uses different features of CDN.

What is 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.

Geographical Nearness

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.

CDN for media content

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).

CDN for API responses

Apart from the media content, Giphy uses CDN to cache API responses of Search and Discover APIs like

  • /v1/gifs/trending
  • /v1/search?q=funny

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.

Route-specific TTL

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.

Response-driven TTL

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.

Cache invalidation by grouping

Giphy uses Surrogate Keys (tags) while caching endpoints on CDN. It helps in smarter cache invalidation, eg:

  • invalidate API responses that contain a specific GIF
  • invalidate API responses from an API key
  • invalidate API responses where the query contains a particular query

Arpit Bhayani

Arpit's Newsletter

CS newsletter for the curious engineers

❤️ by 38000+ readers

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.




Other essays that you might like



Be a better engineer

A set of courses designed to make you a better engineer and excel at your career; no-fluff, pure engineering.


Paid Courses

System Design for Beginners

A masterclass that helps early engineers and product managers become great at designing scalable systems.

300+ learners

Details →

System Design Masterclass

A masterclass that helps you become great at designing scalable, fault-tolerant, and highly available systems.

1000+ learners

Details →

Redis Internals

Learn internals of Redis by re-implementing some of the core features in Golang.

98+ learners

Details →

Free Courses

Designing Microservices

A free playlist to help you understand Microservices and their high-level patterns in depth.

823+ learners

Details →

GitHub Outage Dissections

A free playlist to help you learn core engineering from outages that happened at GitHub.

651+ learners

Details →

Hash Table Internals

A free playlist to help you understand the internal workings and construction of Hash Tables.

1027+ learners

Details →

BitTorrent Internals

A free playlist to help you understand the algorithms and strategies that power P2P networks and BitTorrent.

692+ learners

Details →