Originally posted on zdnet.
AWS engineers explain why developers should build infrastructure software on Rust.
Cloud-computing giant Amazon Web Services (AWS) has outlined the reasons its engineers are embracing Rust, including that it’s a more energy-efficient programming language.
Just seven years ago, the Rust programming language reached version 1.0, making it one of the youngest languages and one that also holds big promise for large code bases written in C and C++. Today, Amazon, Google, and Microsoft back the language that originally started as a personal project of Graydon Hoare before becoming a research project at Mozilla in 2010.
Rust helps developers avoid a host of memory-related flaws common to C/C++, which ultimately cost organizations in security updates. The language got its most high-profile support when Microsoft revealed it was experimenting with it for Windows, chiefly to dodge memory bugs.
But a post by AWS’s Rust advocate and software engineer Shane Miller and Carl Lerche, a principal engineer at AWS, highlights that Rust isn’t only about memory safety and reducing security flaws; it’s a far greener language than Python and Java. In that way, it backs up Amazon’s broader push to make its data centers less harmful to the environment, with the company aiming to have its datacenters go totally renewable by 2025.
AWS services built on Rust include Firecracker, the technology behind its Lamba serverless platform for containerized apps, Amazon Simple Storage Service (S3), Elastic Compute Cloud (EC2), its CloudFront content delivery network, and Bottlerocket, a Linux-based container OS.
Datacenters make up 1% of the world’s energy consumption, amounting to about 200 terawatt hours of energy a day, and the programming languages used can also impact energy consumption.
“It’s not a surprise that C and Rust are more efficient than other languages. What is shocking is the magnitude of the difference. Broad adoption of C and Rust could reduce energy consumption of compute by 50% – even with a conservative estimate,” says Miller, pointing to a study showing the relative energy efficiency of languages, from C to Google’s Go, Lua, Python, Ruby and old Fortran.
“Rust delivers the energy efficiency of C without the risk of undefined behavior. We can cut energy use in half without losing the benefits of memory safety,” says Miller.
Popular messaging app Discord also moved to Rust after initially being built on Python, Google’s Go, and Elixir.
“Because Go is a garbage collection (GC) language, as objects are created and released, every so often, the garbage collector needs to stop execution of the program and run a garbage collection pass,” explains Miller.
Rewriting that service in Rust enabled that service to be 10 times faster and much reduced latencies, translating to fewer servers and as a result, less energy.
“Rust isn’t the first efficient language. C has been around for a long time, but Rust is the first mainstream programming language that is efficient without sacrificing safety. 70% of all high severity security vulnerabilities written with C and C++ are due to memory unsafety, and Rust gives you efficiency without feeling like you’re playing with fire,” says Miller.
However, for all the good news, Rust isn’t without some drawbacks, most noteably that it’s hard to learn.
It takes experienced engineers 3-6 months of study, supported by access to subject matter experts, to become productive with Rust, Miller and Lerche note. “Some engineers have likened learning Rust to learning to eat your vegetables, and while many of them love it once they are productive, a lot of engineers are deciding against learning it or abandoning the effort before they become productive. The potential impact of Rust on sustainability and security will only materialize if we turn the broccoli into a brownie.”