Edited by Zhang Handong

Original text: engineering.fb.com/2021/04/29/…

Facebook is embracing Rust, one of today’s most beloved and fastest-growing programming languages. In addition to bringing new talent to its Rust team, Facebook also announced that it will officially join the nonprofit Rust Foundation. Along with Mozilla (the creator of Rust), AWS, Microsoft, Google, and Huawei, Facebook is committed to maintaining and growing the open source ecosystem of the language.

Today, hundreds of developers on Facebook have written millions of lines of Rust code. While it’s clear that Facebook is investing more and more in the future of the language, it’s important to understand how Facebook got to this point.

2016 — 2017: Rust was first used in source code version control systems.

Facebook’s Source Control team has started a rewrite project called Mononoke with the goal of increasing Mercurial’s commit rate by several orders of magnitude to serve Facebook’s thousands of developers and automate the process. First, developing Mononoke with C ++ was the obvious choice. At the time, Facebook’s back-end code base was very C ++, which meant Mononoke would be implemented in C ++ by default. But the source control team needs to consider the reliability requirements of the source control back end. Reliability is of Paramount importance when damage or downtime can lead to service disruption. This is why the team chose to use Rust on C ++.

Facebook describes the experience in RustConf 2019.

It worked so well that Mononoke has been the production back end of Monorepo since 2019, successfully scaling up over the years.

2017 — 2019: Rust was successively adopted for each project

With Mononoke as proof of its feasibility and practice, Rust was considered and adopted by other projects over time. First, these are usually developer tool projects that don’t need to be integrated with the broader service infrastructure, or small services/daemons that can do their job with just some hand-wrappers around C ++ client libraries.

Many of the engineers on Facebook who adopt Rust come from Python and Javascript backgrounds. They appreciate the high performance of Rust combined with compile-time error detection. With more success stories circulating within companies (such as improving performance by two to four orders of magnitude), there is growing interest in using Rust for back-end service code and exploring its use in mobile applications.

2019-2020: Dedicated support for Rust

From 2017 to 2019, the Source Control team doubled in size and became the unofficial Rust support team within Facebook. But by 2019, the number of Rust developers on Facebook had grown exponentially to more than 100.

As an important example of this growth, Rust is the leading language in the development of the Diem (formerly known as Libra) blockchain, overseen by the independent Diem Association. Facebook is a member of the Diem Association through its digital wallet, Novi. Diem blockchain is primarily written in Rust and covers 94% of the open source code base. In addition, with Rust, Move, a new security programming language for blockchain, was developed.

Given the growth in demand, part-time help from source control teams is insufficient to support the number of teams capable of benefiting from it.

We created a small group of Rust developers experience dedicated to tools and integration challenges, such as establishing mechanisms for an open source package registry ecosystem that uses the language in non-cargo production releases. The team established a central point of contact for Rust developers across the company, prioritizing short-term developer experience issues, improving the core library, and laying the foundation for the success of the new Rust code base as it passed the million-line mark.

Future: 2021 and beyond

At the end of 2020, a Rust team was formed within fb’s internal programming language organization to renew that commitment, led by the same organization responsible for Facebook’s C ++ standards work and toolchain.

In our code base, the team focused on long-term work, not just the developer’s immediate priority experience. In particular, all the contributions that have been developed and sustained to make Rust a robust, productive language and community are now included.

In the short term, the new team is focused on four areas:

  • Support internal users from a language and toolchain perspective: this includes toolchain rollout, cross-domain migration, code review/audit, best practices, and acting as a point of contact for language and toolchain issues.
  • Actively contributing to the community outside Of Facebook: The team conducts code reviews of the standard library and compilers and provides developer resources for Rust community priorities.
  • Easy, secure interoperability between Rust and C++ : We have a lot of C++ code for communicating with the back-end systems that build the services. We need developers to be able to use these libraries safely and easily without sacrificing the benefits that Rust provides. Conversely, if we want to integrate Rust components with larger C ++ binaries, we need intelligent runtime interoperability in asynchronous code. Facebook’s servers are highly distributed and thread-intensive. The Rust task needs to function well on the C ++ thread pool and securely share synchronization primitives and I/O resources. We have done a lot of work in the C ++ area to improve asynchrony and have supported and quickly adopted C ++ 20 coroutines. Bringing Rust into the game would be an extension of it and would build on the excellent work already happening in the Rust asynchronous library stack.
  • Actively support and interact with the Rust Foundation: Since 2016, Facebook has been working on the Rust community and expanding its growth through Rust. We further this commitment by joining the Rust Foundation as a Platinum member, and we look forward to continuing our efforts to drive progress and adoption in a proactive and impactful manner.

Rust’s journey on Facebook is far from over. The team is small, but it will grow over time as support requirements expand. FB is excited and optimistic about Rust’s trajectory at Facebook and throughout the industry.