Deconstructing the fast rate of content served by GIPHY
How GIPHY Uses CDNs To Serve GIFs At Break Neck Speeds
In this article, we will be breaking down how exactly GIPHY serves its GIFs (or JIFs) to over 10 billion users every day. We will be deconstructing how exactly it serves this data and how it serves content at a very fast pace.
APIs or Application Programming Interfaces in general tend to serve text content in the form of a JSON document and these documents in general occupy low amounts of space. However, for applications like GIPHY which tends to primarily serve media content like images, videos and GIFs in the form of a JSON document, the space occupied by the JSON document might increase 100 times because of the complexity of the content which in turn brings down the performance of the application.
So, how does GIPHY maintain its performance and serve GIFs at lightning-fast rates to its users? It uses a CDN namely the Fastly CDN. CDNs or Content Delivery Networks are tools which cache and deliver content over the internet. They are spread widely across the world and almost every country will have lots of CDNs running, For example, you can find a CDN near you by using this.
GIPHY with the help of edge servers finds the server nearest to you and serves content from this edge server and if the edge server nearby does not have the required data stored, it goes to the origin of the data, gets the data, stores it in the nearby CDN for further usage and provides it to the user.
However, let's assume there are a lot of requests coming from users to look at the content posted from one particular region because it became viral. This would end up causing a lot of cache misses because every single server has its own independent caches and it is not guaranteed that this particular viral data is stored on every single one of these independent caches.
Once this happens, the request goes to the root server to fetch this data and this can end up placing a lot of load on the root server.
To combat this, the Fastly CDN offers a second caching layer called the "Origin Shield". This origin shield layer helps the edge nodes that do not contain the requested content by retrieving the data from the origin server only if the origin shield layer does not contain the data. To be precise, the origin shield server helps reduce the load on the root server and does not access it until it does not contain the user-requested data on its cache thereby reducing the load on the root server.
Source - GIPHY
Now that the content is cached on the Origin Shield server or the Edge server, their caching policies have to be managed. For example, we do not want all pieces of content to stay forever cached on these servers (famous content tends to die down) and would like to remove them to save storage space.
To achieve this, we add a TTL or a Time To Live property to the content stored and remove them from the cache after a certain period of time.
In conclusion, GIPHY utilizes the power of Content Delivery Networks (CDNs) to effectively serve its massive user base with blazingly fast GIFs and media content. By leveraging CDNs like Fastly, GIPHY ensures that content is cached and delivered from servers nearest to the users, reducing latency and improving performance.
To handle situations where popular content goes viral, GIPHY employs an "Origin Shield" caching layer, which reduces the load on the root server by retrieving data from the origin server only when necessary. This ensures a smooth user experience even during high-demand periods.
Additionally, GIPHY manages its caching policies by assigning a Time To Live (TTL) property to store content. This enables the removal of outdated or less popular content from the cache, optimizing storage space and ensuring that users are always presented with fresh and relevant content.
By understanding the inner workings of CDNs and their role in serving complex data quickly, we gain insight into the strategies employed by GIPHY. With a robust infrastructure and efficient content delivery mechanisms, GIPHY continues to provide billions of users with a seamless and enjoyable GIF experience every day.
I hope this article has expanded your knowledge of CDNs and how GIPHY enables the efficient delivery of media content. Thank you for reading, and have a great day!