PubNub Pursues Rust to Deliver Best-in-Class APIs

Rust-at-PubNub-1200x630.png

We discuss how PubNub is committed to providing the best possible customer experience by using innovative technologies like Rust. Rust is a high-performance, safe, and concurrent programming language that has helped PubNub to develop fast and reliable APIs. This article discusses the benefits of using Rust, such as performance boosts, improved safety features, and significant reductions in operational costs.

PubNub's commitment to quality and customer-centric value continuously push us towards the bleeding edge technology.  We are always on the lookout for new and promising solutions. This is how we got to love Rust. Rust is a performant, efficient and safe (to say the least)  programming language. With a few years in use, we can confidently say that Rust helped us to develop fast and reliable APIs. We have already seen numerous benefits from our applications written in Rust. Performance boosts, improved safety features, and significant reductions in operational costs.

Rust is an innovative programming language. It surpasses many conventional languages with its safe, concurrent, and functional design. It has been key in steering our progressive methodology at PubNub. As any organization in the IT business, we have accumulated a set of legacy services, that if we would try to implement them now, we would do it differently. This is the situation, when an organization may become a “hostage” of its own legacy. At PubNub, we acknowledge this kind of risk. Risk of becoming stagnated. 

As a remedy from stagnation, we do not hesitate to re-architect, refactor, or, in plain language, rewrite. There are definite financial and executional hazards linked with rewriting applications, but, there is no other, easy way of “converting” python code base to other newer languages to reap benefits of technology advancement. So…, we, as an organization, welcome advancement, nonstop refinement, and celebrate our achievements at PubNub. If it leads to improved customer service, better performance or any other gain for our customer, it is a win. Hence this post…

Empowering Development Teams to Innovate

Our development teams are given the power to determine what comes next with the software they develop, they deploy and they run. Product teams conceive business ideas, put ideas into work queue and dev teams pick them up, it has been a pattern. In this pattern the dev team has no time to look back into work that is already done. We enable dev teams to put into the work proposals for enhancements. This time, the team has opted to revamp an application, selecting Rust as the language, and altering the application stack entirely.

The target is an impressive performance improvement up to 50% as well as substantial operational cost savings. The project proposal included safety measures that would warrant 100% of backward compatibility with legacy. We could not directly convert integration and unit tests into Rust, so we had to opt for something else… That something else resulted in writing a CLI utility tool that helped us to create identical synthetic dataset in both our legacy and next-gen implementations. That utility used generated types and stubs from legacy OpenAPI specification. While implementing data seeding, we realized additional use cases, parity confirmation, performance and more.

PubNub’s View on Innovation Culture

At PubNub, our focus is fostering a setting where employees can flourish, evolving in both their professional and personal skills. This reciprocal relationship of growth isn't limited to just us and our team members, our applications mirror this progression too. You'll see obsolete applications pave the way for innovative replacements. These are amplified in their performance, efficiency, power and cost-effectiveness. New additions to the programming or technology landscape changes are not overlooked. 

In PubNub’s environment we encourage everyone to share every bit that people find interesting. Whoever wants, puts “eyes” on the post and shares their thoughts or comments. We also have a Confluence wiki for ideas exchange.

Rust Command-Line Interface (CLI)

Back to the “rewrite” story….  The team opted for a command-line interface (CLI) instead of a web-based user interface (UI), largely due to its basic design and adaptability. CLI applications can be continuously enhanced with commands or subcommands and adaptable options effortlessly, without the need for any supplemental components. The team's goal was to ensure our testing tool remained simple to manage, avoiding it becoming an overly complex mess that eventually no one wishes to handle. Moreover, they were keen on making the tool uncomplicated to install and a self guiding CLI help system that was straightforward in exploring and navigating.

Another prominent advantage of CLI applications, often missed, is their ability to be utilized in shell scripts. Collaborative groups can now generate shell scripts which can be executed from a localized workstation or even a designated host in the cloud for load testing. They can formulate test scenarios, craft practical examples, and can even be manipulated by innovative Artificial Intelligence. Despite the fact that AI may not be actively constructing code for the APIs, it undeniably can be trained on CLI assistance and command prompts like "create user XYZ".

Brief Overview of the Technologies we use at PubNub

In our roundtable, we spoke with Serguei Oleinik, a significant contributor to our collective endeavor in Rust landscape. Serguei explains the unique benefits of using Rust, stating that it "essentially makes me a better programmer." He points out that the language's stringent compiler creates a baseline for senior and junior programmers.  Experience with language will get developers faster to the base line. Code quality will not be compromised for junior developers, it just will take a bit longer though. 

Yes, code might be not as efficient, but it will work. Just like in Scala one could be writing Java code, same for Rust, one could be producing Java like code, not as memory efficient. In contrast, Rust compiler, on another hand, will not let in many types of error that languages, such as Java or .Net, would solely rely on developer’s experience. Rust compiler pushes both junior and senior developers to improve their code quality, thereby effectively unifying the codebase. 

Rust teaches programmers to navigate complex issues inherent in concurrent processing, resulting in robust and error-free software. Development cycle wise, Rust’s ecosystem, integration and unit testing, cargo and abundance of open source projects, is about the same as Java, which results in applications with C like performance! 

Rust's Effect on Programmers

At PubNub, we strive to deliver performant, reliable, and fast-to-market software. To achieve this, we empower our employees to make key decisions. After all, no one knows our systems better than the people who implemented them.

We hold the belief that this methodology empowers us to develop software that's not only groundbreaking, but also efficient. This also instills in our team members a feeling of proprietorship and self-respect in their work. We have strong faith that this strategy will keep providing beneficial outcomes.

You can create a simple diagram showing the pathway of a developer learning and improving through the use of Rust. Start with a label called "Developer starts with Rust", then arrows pointing to boxes titled "Strict compiler catches errors" and "Developer learns to manage complex concurrent processing". Another arrow could then point from those boxes to one saying "Improve code quality". The final arrow points to "More efficient and reliable software".

At PubNub, we are continuously upgrading our infrastructure for better performance. The Rust-based “pn-harness” allows us to test parity as we transition from older systems to newer ones. By populating both systems with data, we can compare and ensure data integrity, which helps to avoid lock-ins into our code and gives us the flexibility to switch databases in the future. 

For future integration we foresee opportunities in using artificial intelligence (AI) with our CLI tool. Serguei envisions a seamless blend of AI with our CLI where natural language commands like 'Create me a user' are automatically translated into actions like 'Add a user to the database.' This stands to improving the user experience by turning a complex task into a simple action. 

Transitioning Systems with pn-harness CLI

To visualize the system transition and testing process, start with two parallelograms side by side labeled "Old System" and "New System". Arrows from a box titled "pn-harness CLI tool" should point to both systems showing "Populates with data". An arrow from both systems should then point to a box titled "Data comparison & integrity check". Finally, a single arrow would point towards a box saying "Confident transition with maintained data integrity".

User Command → AI interpretation → Actionable Task → Desired Outcome

The pn-harness CLI offers extended functionality. It generates unit tests, evaluates performance metrics, and offers intuitive backward and forward navigation. Looking forward, we anticipate enhancements such as integrating AI for improved user support, a browsing function for easier data navigation and deploying pn-harness on an EC2 work instance for reliable performance evaluation.

The procedure where an end user issues a command which is interpreted by an artificial intelligence, transformed into an action, and eventually leads to the realization of the desired effect. Even though we are simply providing a diagram, it is possible to easily replicate this in our experience.

We Strive for Continuous Improvement

We are not bound by our legacy application, we continuously search out opportunities for enhancements. We don't step back from the idea of updating a system that will position us for added advancements. Integrating the Rust CLI has streamlined our procedures, amplified developer productivity, and brought our systems a notch above, nudging us closer to our aspiration of providing unmatched services to our customers. The exploration continues, as we head towards improvements that sit just over the horizon. Keep an eye out as we ceaselessly chase the finest for you.