How Facebook made a universal open source language for the web
How Facebook Made a Universal Open Source Language for the Web
The code that runs the web is a melting pot of programming languages and technologies. JavaScript, the most popular language on the web, is the standard for writing code that runs in your browser. But the server side is much more diverse. Java (no relationship to JavaScript) remains popular, as do PHP, Python, and Ruby. Mobile app developers, meanwhile, have their own preferred languages, like Kotlin for writing Android apps or Apple's Swift for iOS.The diversity of languages creates a need for a lingua franca that applications can use to talk to one another, regardless of the language used to create them. For example, the mobile version of a travel app might need to extract a flight schedule or upload changes to your profile on a server running software written in a different programming language. Meanwhile, application developers increasingly outsource parts of their software to cloud services that handle tasks such as sending text messages; the companies offering those services need to make them compatible with multiple programming languages.Historically, that lingua franca has been something called REST, short for "representational state transfer," a simple but sometimes blunt approach to sharing information between applications and servers. But a more flexible alternative called Graph Query Language, developed by Facebook, is spreading fast and has won over companies ranging from GitHub to Audi.GraphQL is heavily inspired by another language called Facebook Query Language, which in turn was based on Structured Query Language, the well-established lingua franca of database software supported by Oracle, Microsoft, and other database makers. That makes the structure and syntax of GraphQL familiar to many developers.GraphQL saw explosive growth among JavaScript developers over the past two years, according to data compiled by NPM, which offers tools for managing JavaScript code. The annual State of JavaScript survey conducted by a separate group of developers, which polled 20,000 JavaScript developers about the tools they use, found more than 20 percent already use GraphQL and another 62.5 percent want to learn it, up from 5 percent who had used it in 2016.How It WorksAdam Neary, a tech lead at Airbnb, says the company chose to use GraphQL because of the limitations of REST.With REST, you can only download predefined bundles of information. If you only want one part of that bundle, you still need to download the whole bundle and throw out the parts you don't need. If you need a little information from each of several bundles, you have to download all the bundles and then reorganize it yourself.For example, let's say you're a mobile developer at Airbnb and you want to add a feature to the iOS app that displays available properties in a particular zip code. In a REST system, you would request property listings by availability and locations, likely with the help of a “back-end” developer. But that could harvest a lot more information than you need, such as the number of bedrooms and bathrooms, the description, the list of amenities, the name of the host, and photos.