Video: Canva's Lessons From Scaling MongoDB Atlas to 10 Billion Documents Across 100 Nodes
Running complex, global, and mission-critical infrastructure at scale is difficult, and anyone who has done it for any length of time usually has a few gnarly lessons to share. At
MongoDB World
in June 2022, we were lucky enough to feature someone who had done just that.
Michael Pearson
, software engineering team lead at
Canva
, gave a talk titled “10 Billion Documents: How Canva Scaled MongoDB to 100 Nodes.”
I’ve had the pleasure of working alongside Pearson and his team for almost a year now, and his presentation focused on some of the massive challenges (and lessons) they’ve faced over the last two years as they have scaled into tens of terabytes of data and tens of billions of documents. I’m writing this blog to give a few highlights, but I’d recommend everyone check the original talk in full:
A tricky problem
For the uninitiated, Canva is a visual communication platform that empowers its users to design anything and publish anywhere. Or, as Pearson explained in his talk, “Canva is a really simple way to create beautiful designs and presentations.”
Canva’s mission is to empower the world to design, and more than 85 million people in over 190 countries use the platform every month. As you can imagine, this presents a huge data challenge — and opportunity. Canva holds more than 10 billion designs and receives up to 30,000 document requests per second. The success of the platform comes down to providing a fantastic user experience every time, and to do that they need to present their customers with the right data at the right time.
“This could be a really tricky problem for a database platform, particularly for a business based in Sydney with many users on the other side of the world,” said Pearson.
MongoDB Atlas supports the Document Service, which enables opening, creating, updating, or deleting any design on Canva. The Document Service is critical for every single user — if the Document Service is down, then Canva’s users can’t design.
But before we get too far into things, we should probably start with why Canva started using MongoDB in the first place.
Flexibility to support rapidly changing requirements
Michael Pearson, software engineering team lead at Canva.
“Canva was launched to the world back in 2013, when MongoDB was very new to the scene,” explains Pearson. “I'm not sure if there were any other databases that would have been up for the challenge.”
From those earliest days, MongoDB's flexible document model was the perfect fit for Canva's increasingly complex designs and document types.
“The flexibility that MongoDB gave us in those early days was instrumental to our success. As the Canva platform evolved, we were throwing new schema and new features at it. MongoDB would just handle it.”
Its continued innovation and problem-solving means MongoDB remains as valuable to us today as it was in 2012.
Michael Pearson, software engineering team lead at Canva
At the same time, it was essential that Canva’s engineering team was focused on building Canva, rather than time spent managing the data platform. With that in mind, Canva chose to run MongoDB as a service. After trying out multiple options, they went with MongoLabs and, in 2019, following MongoDB's acquisition of MongoLabs, Canva migrated onto
MongoDB Atlas
, running on AWS, where they remain to this day.
Ten years of relative bliss
“Before 2021, we had a very hands-off approach to how we used MongoDB,” said Pearson. “MongoDB just handled it. We didn't have to think about it at all."
That's incredible, right? Think about it — for nearly a decade the team barely had to think about their data layer and could spend their time working on new features and making the actual product better for its millions of users around the world. It's what every developer wants.
Eventually, though, Canva’s own success created certain challenges around scaling. With the stratospheric increase in growth, the load on the Document Service also continued to increase.
MongoDB’s ability to scale horizontally through the use of
sharding
was critical to overcoming initial scale challenges, something that traditional database management systems would have struggled to achieve, said Pearson.
With MongoDB, sharding is distributed or partitioned across multiple machines — useful when no single machine can handle large workloads.
In due course, though, some attributes of Canva’s workload presented a new challenge.
Said Pearson: “We were unique in that we have one cluster with one collection with a million chunks. Our documents are fairly large, given our product has evolved over the years and we put more and more stuff into our documents.”
Or,
Canva does many updates to relatively large documents, and by mid-2021 the surge in traffic was causing issues. “Our peak traffic caused three main problems: inability to run the balancer, latency issues, and a disk usage pretty much at capacity,” Pearson explained. “A really ineffective cache caused a really high write load to our cluster. This was causing downstream failures."
Pearson discussed some of the tactical solutions the company took. “Disabling the balancer immediately brought us back to service, but now we knew that there was something wrong with that cluster and we couldn’t operate without the balancer,” said Pearson. “We also noticed that the number of chunks in our cluster had skyrocketed, from around 400,000 to just over a million.”
Getting to the root of the problem
The professional services team at MongoDB discovered that “metadata updates were causing anywhere from a one-second to five-minute stalls in the cluster.” Going from 400,000 chunks to a million chunks, at the rate of a minute of each change, was not optimal.
There were three things to address with that cluster: reduce the number of chunks, reduce that disk contention, and reduce the size of documents.
“With regard to reducing the number of chunks, we just took any contiguous chunks on a shard and merged them unconditionally,” said Pearson. “This was tooling built in collaboration with MongoDB.”
After three months of merging chunks, Canva saw massive improvements in its cluster’s performance. A failure rate during reboot of around 4% dwindled to less than 1% during maintenance operations.
Further, to address latency spikes and full-disk capacity, the team formulated a six-step plan to move from network-based storage volumes to locally attached disks. This has proved a huge success. “We were able to run the balancer. Our large spikes in latency were pretty much all gone, and our disk usage was almost at zero,” Pearson said.
He continued: "The key takeaway for me is that sharding is great, but it's never a silver bullet. I don't think we would have caught these issues so quickly without such a thorough incident review process and such a close working relationship with MongoDB."
What was learned?
After presenting all of that information, Pearson closed out the presentation with a few key lessons. For anyone interested in running infrastructure at a massive scale, they are simple and worth taking note of:
Take advantage of the flexible document model to accelerate your pace of development.
Ensure chunks are distributed uniformly across the cluster in a consistent size.
Maintain a thorough incident review process and include your trusted partners (such as MongoDB).
Reliability is an essential part of Canva’s engineering practice, and prolonged service disruptions were particularly upsetting not only for engineers but for Canva’s global users. Pearson is glad to report that Canva has seen a turnaround in the number of incidents impacting its Document Service. This has freed the document team to shift focus back to shipping features and ensuring every user has a flawless experience using Canva.
Interested in joining Canva as it pursues its mission to empower the world to design? Canva is looking for a
software engineer
to join its Core Data team.
Want to take advantage of the flexible document model to accelerate your pace of development? Learn more about
MongoDB Atlas
.
August 2, 2022