What You Shall Know to Choose Go vs Rust for Your Next Project
Two programming languages: Rust and Go (Golang). Both belong to the most popular programming languages among developers. According to the yearly Stack Overflow Developer Survey, Rust has been and remains the most loved language since 2016. In its turn, according to the State of Developer Ecosystem 2021 report by JetBrains, Go belongs to the top 5 languages that developers plan to adopt or migrate to, and the top 5 fastest growing languages. The question is, what developers find in them, and what benefits they offer for business and what risks they can bear.
We, at Surf, have been working in the web and mobile development market for 12 years already, and have always followed the technology trends to be the first to ride the wave. This was the case with Flutter where we have been early adopters and continue to contribute to technology growth through the efforts of our strong Flutter team. And today, we share our experience and knowledge about two other promising programming languages and their pros and cons in terms of achieving business goals.
Why did Mozilla create Rust?
Rust belongs to statically-typed programming languages (along with C, C++, Java, Go, Scala, etc), where the type of variables is known at the compile time. Their advantages lie in better performance due to more opportunities for compiler optimization, and early bug detection due to the fact that checking is performed by a compiler.
Initially, Rust started as a personal project of Graydon Hoare, a Mozilla employee, and was designed to enable browser developers to write faster, more parallel, and more secure code. In general, the goal was to find better ways to build browsers and avoid weak points of C++ while implementing high-performance software. In 2009 the project received Mozilla sponsorship and was officially announced in 2010.
The COVID-19 pandemic made adjustments to Rust active development: in the course of corporate reconstructing Mozilla laid off 250 of its 1,000 employees worldwide including the team of Servo (Rust-powered browser), Rust active contributors. The impact could be crucial for Rust’s future. And the decision was taken to form the Rust Foundation that would take ownership of all trademarks and domain names and financial responsibility for their costs. The founding member companies are AWS, Huawei, Google, Microsoft, and Mozilla. And now, the Rust ecosystem is in safe hands.
The Rust programming language is a good fit for:
- game development
- command-line apps
- web apps
- embedded development.
Why did Google create Go?
Go (Golang) is an open source programming language designed to power fast and scalable software. Go was created in response to real problems faced by Google such as slow program build, uncontrolled dependencies, hard-to-read code, poor documentation, expensive updates, and others. The goal was to allow the engineers to be more productive, and use Google’s enormous hardware resources more efficiently. Go can be considered as an attempt to replace C and C++ with regard to the already accumulated experience in creating complex systems. Accordingly, the new language was made similar to them to be easy-to-learn for the programmers.
Its syntax is similar to C, but Go has among other features
- memory safety to prevent common buffer overflow vulnerabilities used by many cyber attacks,
- garbage collection that makes writing Go easier due to simpler managing the lifetime of allocated objects, and
- CSP-style concurrency that allows building complex concurrent pipelines.
Go is a good fit for:
- cloud and network services,
- command-line interfaces,
- web development,
- DevOps and site reliability engineering.
Does your project belong to one of the four categories above? Check our Go development services, and let’s carry out your project together.
Go and Rust challenges to be aware of
npm, Inc: is it good for Rust to be boring?
npm, Inc. is the company behind Node package manager, the npm Registry, and npm CLI. They also build and sell useful tools for developers. With 1.3 billion package downloads per day, the company needed efficient and scalable solutions. They chose Rust to use as part of npm’s stack. Though Rust required more time to dive into (as compared to Node.js and Go), its stunning dependency management helped it win. As a result, the biggest compliment for Rust was that it is boring, meaning that a service can be deployed and forgotten to save operations time and focus on other issues. According to the case study of 2019, the weak point of Rust as a young language was the lack of industry-standard libraries and best practices for monitoring, logging, and alerting. But a couple of years have already passed by, and the community is actively working on Rust long-term development.
Figma: Rust for performance-critical code
For Figma, performance is one of the most vital features. The service offers teams the possibility to work simultaneously on one document, so everyone shall see each change in real time.
The case study comes from 2018, Figma was rapidly growing more popular and the server written in TypeScript couldn’t keep up. The decision was taken to rewrite the server in Rust. The decisive advantages of Rust were excellent speed, low resources usage, and safety as offered by other standard server languages. The results achieved were impressive.
But there were some cons highlighted by the Figma team:
- confusing variable lifetimes that made developers pause regularly and check little unnecessary issues. The Figma team found their own solution at that time, while Rust addressed this issue with non-lexical lifetimes.
- complicated error debugging as in Rust stack traces were for the code that reported the error but not for the code that caused the error. Since then, the Rust community has offered solutions such as error-chain and failure.
- Some libraries had subtle correctness issues that could have resulted in data loss, The bugs in the affected libraries were reported and have since been fixed.
- Asynchronous Rust is difficult. The Figma team finally decided to keep the network handling in node.js. The Rust community offers an experimental RFC for adding a new feature to the language, coroutines (also commonly referred to as generators).
As we see from above examples, most Rust-related challenges were due to its young age, but the community is apt to respond promptly and actively to the needs of developers and business. The Rust Survey 2021 results prove that the most respondents (9354, and this is 1500 more than a year before) are likely to use Rust in future though its adoption has been challenging.
Dropbox: easy to be productive in Go
Initially, Dropbox was powered by Python that provided for fast iterative development. But as the company grew, they needed a more efficient way to scale. In 2013, they decided to migrate the performance-critical back ends to Go. The key advantages of Go were better concurrency support and faster execution. The migration was a success, and as of 2017, the most Dropbox infrastructure was written in Go: 1.3 million lines of Go company-wide, 15+ teams build and run Go services, 150 unique contributors to the Go server repository.
The key challenge the Dropbox engineers faced was the lack of robust libraries required to build large systems. Go was still young at the moment, and this was not surprising (similar issues are typical for young technologies). The Dropbox team created various libraries to provide better abstractions, such as connection management and a memcache client, and what is more, they open sourced the libraries to share with the community better opportunities in building large-scale production systems.
Go: when you should choose other way
Go is increasingly used in various industries, by startups and by large-scale enterprises such as Dropbox, Uber, Monzo Bank, American Express, and many others. And their success stories are impressive.
But there are cases, where you’d better check some other languages rather than spend time and resources to overcome the challenge:
- Go isn’t the best choice if your business is still validating its concept, and you need to create a demo for investors and stakeholders. Creating your PoC with Go will cost you too much precious time at the early startup stage. You will need Go as soon as the existing code starts extending and influencing user experience, and you begin offering on-demand services or expanding e-commerce functionalities.
- Go is not the best fit for applications related to mathematics or engineering calculations, or for machine learning. Such apps need SciPy, and Python provides better support for different numeric types and reflection than Go.
We will not persuade you to use the tech stack that doesn’t match your project needs, but will offer the solution tailored for your project. This is the way we approach every project. Check our case studies.
Summing things up
As we see, being relatively young, both languages (Rust and Go) have already deserved top positions and reviews among developers, and rightfully.
Rust is not easy to learn and use but due to the complexities it helps detect some errors related to the memory management and race conditions, etc., and it works well in terms of security and parallelism. If you need your code to be safe and without memory losses, then Rust is a good choice. With Rust you’ll get well-written documentation, but tooling is weaker as compared to Go. As a result, Rust can be considered as a language to choose, but the development cost will be approximately comparable to C++, while there are even fewer skilled developers as for Go.
Golang is loved for being concise, expressive, and readable. It helps build secure and scalable web applications, complex systems requiring high performance, web servers and microservices, cloud computing systems. Go is a good fit for scaling use cases both in startups and enterprises.
But along with specific features of the languages and case studies, you should take into account the cost of developers, available resources, and whether you have a team that you can trust.