Twitter's twits turned troll's tech taunt into thought-provoking tonic

Behind the scenes of web upstart's shift from Scala to Node.js

Twitter's mobile app, before revision

Node Summit In April, 2016 Paul Ford, cofounder of New York-based digital production studio Postlight, told Twitter its web app was crap.

"I use the Twitter web client for mobile Safari so that I never forget I am garbage," he wrote in a tweet.

Twitter engineers working on a rewrite of the Twitter mobile web app, started in 2015, were aware that other users felt the same way. As recounted by James Bellenger, senior software engineer at Twitter, at Node Summit in San Francisco on Wednesday, the team tasked with cleaning up the mess made stickers from the mean tweets that came their way to motivate the renovation effort.

Twitter in April launched Twitter Lite, a complete rewrite of its mobile web app as a Progressive Web App. The culmination of two years of work, it was the social propaganda company's first large user-facing service build with Node.js.

The previous version of Twitter for the mobile web used Scala, a programming language that runs on the Java Virtual Machine (JVM) on the backend and JavaScript on the frontend.

"This stack does a lot of things really well," said Bellenger, "because the JVM can get data efficiently."

But, Bellenger continued, there are downsides like the server handling all the data retrieval and view rendering. It has many backend dependencies, is slow to compile, is hard to maintain, and requires ongoing engineering attention, he explained.

"Hiring-wise, it's been really hard to find people with both frontend and backend dev skillsets," said Bellenger. "And they often don't know Scala."

Twitter wanted a web app that was fast, efficient, and functioned offline. "We really wanted our new stack to enable engineers at the company," said Bellenger.

The sticker that kicked it all off ... Click to enlarge

Node.js provided a way to remove the server from the critical path of most user interactions, to shift the center of gravity away from the server to the browser. But to effect technical change, Twitter's engineers first had to create organizational change, because not everyone at Twitter had faith in web technology.

The campaign to educate people was the most critical, most challenging, and least certain to succeed, Bellenger said.

One difference involved how Twitter dealt with the security of its software. Scala web services required about 100 external libraries, each of which was reviewed by the security team and had an owner, to keep up with changes and patches. Node-based Twitter Lite has about 2,000 dependencies.

"That's more than we can audit or understand," said Bellenger.

So Twitter decided not to trust its Node code. The app's service layer uses Twitter's public REST API and it runs in a sandbox. The company also put more emphasis on integration tests. The open source error reporting system "has been absolutely invaluable in building confidence," said Bellenger.

To get developers up to speed on Node, the Twitter Lite team began Watch Wednesdays, weekly group lunches during which meals were consumed while viewing tutorials about Node-related technologies.

The team also had to rethink its APIs, which were sending the app too much data, in large pieces. Node.js performs better with lots of small transactions, so Twitter Lite developers focused on reducing the app's 400KB parsing payload and managed to get the data down to 40KB.

The change cut CPU utilization in half and doubled the number of requests that could be served on the same hardware, said Bellenger. And Node's effect on compute resources (CPU and memory) was even more pronounced: Twitter Lite incurred just 3.5 per cent the compute cost per billion renders compared to the version that had been running on the JVM stack. ®

Biting the hand that feeds IT © 1998–2018