Why Rust Has a Bright Future in the Cloud

Why Rust Has a Bright Future in the Cloud

Originally posted on qovery.

Rust is a programming language? Have you heard the question from your developer friends? 

Well, Rust has broken into TIOBE Top 20 Most Popular Programming Languages. Briefly stated Rust is a direct competitor to C and C++ and at a lesser level competes with Java and C#. 

There has been rapid adoption by open source projects by Mozilla, Polkadot, and Deno besides exciting system programming enterprise action from the likes of Google, AWS, Microsoft, Cloudflare, Dropbox, and many others. Let us explore more on this fascinating programming language, its advantages, and its growing popularity in today’s emerging technology world.

Rust is an open-source language developed by Mozilla. As per Stack Overflow’s 2019 developer survey, Rust is also the most loved programming language. It is a low-level programming language focused on safety and performance.

Traditional programming languages like C/C++ have been facing challenges with the build of concurrent programs and memory errors. Rust is good for performance. Network services that are sensitive to latency find that tail latencies are nearly nil while using Rust as there is no runtime garbage collection.

Java and C# became popular many years back as they were eliminating bugs related to memory safety. Their language runtimes like the Java Virtual Machine and .Net efficiently used Garbage Collection at runtime. But on the downside, it also led to runtime overhead resulting in application performance impacts and inconsistent performance.

Microsoft agrees that Rust is the best alternative to C and C++ today. Rust is reliable due to its static compile-time garbage collector that prevents bugs that are normally accepted in C++, Java, and Python. It also improves developer productivity and has built-in documentation, unit, and integration testing. 

How Rust helps to build a better Cloud infrastructure software

Organizations are rushing to gain advantages of cloud computing. Rust is gaining popularity and is making inroads into building software for better cloud infrastructure. There are a few reasons that are catapulting the adoption of Rust language for Cloud.

Some of the important reasons are as follows:

Rust is like C and C++ in performance

No matter how much investment software companies may put into tooling and training their developers, “C++, at its core, is not a safe language,”

There are many similarities and differences between Rust and C. Rust has syntax with brief keywords similar to C. The performance of a coding language depends on optimization, platform restrictions, and algorithmic complexity. The basic flaws of languages like C and C++ have not yet been fixed. Rust can be written as fast as the C language. One can use convenient abstractions as well to write code like C.

Let’s check out the property comparison between Rust, C, and C++

Comparison between Rust, C, and C++

As Rust does not require a runtime or garbage collector, it can deliver run time performance that is similar to C and C++ languages.

In cloud computing, there is a need to build low-level infrastructure components that need high performance to reduce critical overhead. For example, we have the hypervisor that acts like a virtual machine manager that allows the sharing of a single physical instance of cloud resources between multiple tenants.

Rust is focused on security and safety without impacting speed and performance.

Newstack quotes “No matter how much investment software companies may put into tooling and training their developers, “C++, at its core, is not a safe language,” said Ryan LevickMicrosoft cloud developer advocate, during the AllThingsOpen virtual conference last month, explaining, in a virtual talk, why Microsoft is gradually switching to Rust to build its infrastructure software, away from C/C++.

Low memory footprint

Cloud computing has always been in the limelight as a cost-effective and economic option for hosting applications. However, memory in cloud computing is an expensive affair and that is an area that Rust language has been able to provide good news.

Cloud computing is expensive on the memory side and is based on the vCPU in GHz/s and the memory in Gb/s. Memory and speed cannot be adjusted separately. Both are linked together and if you need more MHz, you will need more memory and vice versa.

Rust gives us the option of storing data on the heap or on the stack. It takes a call at compile time if the memory is no longer needed and can be cleaned. This approach enables efficient usage of memory and is advantageous for cloud computing. It also provides higher performant memory access. Rust has a major advantage with its ability to provide a low memory footprint in this manner.

Safe by design

Another advantage provided by Rust is better memory safety due to the compiler. Rust being a low–level statically typed programming language it has been developed with a focus on efficient memory management at the heart of its conception.

Rust has secure memory management too. The garbage collector (GC) in other languages is in place to ensure that unwanted items are removed from memory. Unfortunately, this slows the code performance speed when it runs. Here is where the Rust compiler drives in the advantage of discarding the garbage collector and performs checks in compilation for any memory errors.

Rust uses a strict type system. This coupled with the ownership model delivers compile-time verification of memory and concurrency safety which reduces the testing and validating costs of Rust cloud implementations.

Rust has powerful features

Borrow checker

The borrow checker in Rust prevents data races at the time of compiling. Data races happen when the same memory is accessed by two threads at the same time. Rust prevents these types of undefined behavior.

Ownership

Unlike some other languages that seek memory that is not being used while the program is run, Rust manages through a system of ownership. It includes a set of rules that are checked by the compiler.

Each value in Rust has a variable which is known as its owner. There can be only one owner at a time. Ownership is dropped when the variable goes out of scope which essentially means cleaning the memory allocated to a heap when the variable cannot be accessed any longer. 

The ownership rules provide benefits like memory safety accompanied by more fine control over memory, unlike other languages.

Lifetime

Rust compiler uses ‘lifetimes’ to keep track of the validity of references. A variable’s “reference” is a pointer that points to a particular variable. You can use Lifetime annotations to inform the borrow checker on how long references will be valid. The borrow checker can infer correct lifetimes in many cases but may need the developer’s help sometimes.

All these features help optimize memory management using Rust. This makes it a programming language of choice for the cloud.

Growing adoption of Rust language: 

We are seeing an increase in using Rust language by leading names like Google, AWS, Microsoft, Cloudflare, and others. A few examples include

  • AWS Firecracker: AWS has used Rust to build Firecracker which provides open-source virtualization technology. It powers AWS Lambda and other serverless offerings. Rust has also been used to deliver services such as Amazon Elastic Compute Cloud (Amazon EC2), Amazon CloudFront, Amazon Simple Storage Service (Amazon S3), Amazon Route 53, etc.  AWS firecracker (micro VM):  https://github.com/firecracker-microvm/firecracker
  • Linkerd service mesh proxy is built in Rust – https://github.com/linkerd/linkerd2-proxy
  • Qovery Engine:  is an open-source abstraction layer library that turns easy apps deployment on AWS, GCP, Azure, and other Cloud providers in just a few minutes. The Qovery Engine is written in Rust and takes advantage of TerraformHelmKubectl, and Docker to manage resources. https://github.com/qovery/engine

Rust is gaining momentum with companies realizing its benefits for cloud computing. Dropbox used Rust to rewrite some of its core systems while Mozilla used Rust to build the Firefox browser engine demonstrating its robust benefits.

Source: qovery