Category : Others Toggle

How replacing Java with JavaScript is paying off for PayPal

Online payment service PayPal says swapping Java for node.js on its servers is allowing it to serve web pages more rapidly and simplifying the creation of server-side software.

PayPal has moved from building web applications using Java to using JavaScript in the browser and node.js on servers.

Node.js is a platform built on Chrome’s JavaScript runtime that allows engineers to build fast and scalable network applications using JavaScript. Node.js is suited to creating data-intensive, real-time applications that run across distributed devices using its event driven, non-blocking I/O model.

 

Jeff Harrell, director of engineering at PayPal, described the architectural advantages of shifting from Java to JavaScript.

“Imagine an HTML developer who has to ask a Java developer to link together page A and B,” he wrote in a blogpost.

“That’s where we were. This model has fallen behind with the introduction of full-stack engineers, those capable of creating an awesome user interface and then building the application backing it. Call them unicorns, but that’s what we want and the primary blocker at PayPal has always been the artificial boundary we established between the browser and server.

“Node.js helps us solve this by enabling both the browser and server applications to be written in JavaScript. It unifies our engineering specialties into one team which allows us to understand and react to our users’ needs at any level in the technology stack.”

PayPal started using node.js as a prototyping platform but this year moved to using it in production. The team at PayPal started on node.js using the web application framework express, the JavaScript task runner Grunt and nconf for configuration.

To enforce consistency in how servers are set up, important inside a large development organisation, PayPal created a convention layer on top of express called Kraken.js. Harrell said PayPal will open source Kraken.js soon.

Simpler, faster

PayPal’s first use of node.js in production was to serve the ‘Account Overview’ section to its users. The company hedged its bets by building an equivalent Java application in parallel.

It took two node.js engineers a few months to build the necessary software, almost half the time it took the five-man Java team, with the node.js app written in 33 percent fewer lines of code and built using 40 percent fewer files. It also took a few months to complete the one-time step of building the infrastructure to allow node.js to work with PayPal — adding support sessions, centralised logging and keystores.

The node.js version of the app was built on kraken.js using express, the templating engine Dust and other open source code, while the Java software used an internal application framework based on Spring.

The applications contained three routes, with each route making between two and five API requests, orchestrating the data and rendering the page using Dust.

In performance tests on production hardware the node.js application responded to requests on average 35 percent faster than the Java alternative, resulting in the same page being served 200ms faster, “something users will definitely notice”, Harrell said.

All of PayPal’s consumer-facing web apps will be built on node.js in future.

“There are over a dozen apps already in some stage of this migration and we will continue to share data as more applications go live,” Harrell said.

nodejsperformance

The results of PayPal testing the two apps. Image: PayPal

ShutDown