How Snapchat Reduces Latency Of Snaps With DynamoDB
Snapchat reduces the median latency of sending snaps by 20% and supports millions of queries per second with Amazon DynamoDB.
290 million users use Snapchat daily to send billions of pictures and chat with friends.
Snap Inc. (Snapchat’s parent company) needed to evolve its infrastructure in order to handle this scale of requests to provide a seamless user experience.
To achieve this, Snapchat migrated its monolithic architecture to a service-oriented architecture using AWS.
Amazon DynamoDB was the core component of this modernization and allowed Snap to have a powerful and scalable database capable of delivering single-digit millisecond latency at any scale.
“As the number of Snapchatters grew to hundreds of millions, we did some technical diligence and found that Amazon DynamoDB was the right technology choice for us” — Saral Jain, Director of engineering and head of infrastructure at Snap.
This came from their need to acquire a reliable and cost-efficient solution that also offered low-latency experiences for their customers.
DynamoDB Use Cases
Snap made use of DynamoDB across several areas including the primary messaging feature, allowing them to scale chat messages as high as they needed.
This also helped Snap build a regionalized database structure to provide a fast experience to users around the world.
Saral Jain said that using DynamoDB allowed Snapchat to optimize annual infrastructure costs significantly, and provide low latency for core use cases like messaging and the friend graph.
Snap’s Infrastructure Challenges and Opportunities
When it was developed in 2011, Snapchat was built on a monolithic architecture where the majority of features were served from a single service application.
This made it more likely for a bug or issue to impact other services as everything was tightly coupled together.
As Snapchat grew, it needed to migrate away from this monolithic architecture and to a modern microservices solution capable of rationalizing the company’s data layer.
Snapchat liked the idea of flexible pricing that DynamoDB offered, including provisioned capacity mode and auto-scaling features.
Using Provisioned capacity and auto-scaling features, which Snapchat didn’t have previously, enabled them to pay in advance for discounted capacity and helped the company maintain reliable throughput while automatically scaling up (and down) as needed to optimize costs.
Additionally, Snapchat was also attracted to the built-in security and rich point-in-time backup features provided by DynamoDB.
Performance Improvements
The migration of Snapchat’s database to DynamoDB was mostly completed in 2018. With this migration, Snapchat took the opportunity to rethink and restructure its data architecture.
Snapchat’s teams carefully planned the migration to ensure it would not disrupt the user experience.
The modernization led to tangible improvements.
One of the most significant outcomes was a 20% reduction in the median latency of sending snaps, making Snapchat one of the fastest ways for users to communicate online.
Additionally, Snapchat saw a significant improvement in handling seasonal traffic spikes, such as those that occur during holidays like New Year’s Eve.
Snapchat handles more than 10 million queries per second during these peak times.
Leveraging DynamoDB for Snapchat’s Core Features
Snapchat uses DynamoDB for several critical features:
Messaging system
Friend graph
sticker packs
Bitmojis
Custom stories
These features all rely on DynamoDB’s fast and reliable database infrastructure.
DynamoDB’s auto-scaling features have also proven valuable for Snapchat.
As the app experiences different usage patterns throughout the day, it relies on auto-scaling to balance scalability and cost, all fully managed by DynamoDB.
During periods of low traffic, DynamoDB automatically scales down to help Snapchat save on costs.
Global Scaling with DynamoDB Global Tables
As Snapchat’s user base grew, Snap started making use of DynamoDB’s Global Tables.
Global Tables allow automatic data replication across AWS regions.
This provides fast, local read and write performance by automatically replicating DynamoDB tables to the regions closest to users.
Snap’s global architecture can now handle regional traffic without compromising on speed or reliability, which is critical for maintaining positive user experiences across different geographical regions.
Conclusion
Snapchat’s migration from a monolithic architecture to a microservices-based one, has been a critical step in maintaining app performance, cost-efficiency, and continued stellar user experiences.
By leveraging DynamoDB, Snap not only improved operational reliability but was also able to handle massive and unpredictable traffic patterns that come from running an app like Snapchat.
With this migration, Snapchat has empowered itself to deliver better, faster, and more reliable experiences for its users on its platform.
👋 My name is Uriel Bitton and I’m committed to helping you master Serverless, Cloud Computing, and AWS.
🚀 If you want to learn how to build serverless, scalable, and resilient applications, you can also follow me on Linkedin for valuable daily posts.
Thanks for reading and see you in the next one!