
Three months ago, we decided to stop using Django on our site and rewrite everything from scratch on server-side JavaScript under Node.js (if there is a time in a startup’s life when you can seriously change the infrastructure, it’s at the very beginning of the journey - when there is the greatest freedom maneuver).
What made us take such a decision? One simple thought - the LAMP stack is dead. In the two decades that have passed since its birth, there have been fundamental changes in the protocols, content, servers and clients on which the web is built. Three eras of web development can be distinguished:
1. 1991 - 1999: The Era of HTML.At the bottom of the HTML era were documents, in full accordance with Tim Berners-Lee’s original view of the “virtual universe of interrelated documents”. The web was filled with static, manually created files, the clumsy appearance of which in the browsers at that time offended the taste of even the most unassuming designer. Static documents were displayed in static clients.
')
2. 2000 - 2009: The Era of LAMP.At the base of the LAMP era were databases. The place of the documents took the stack of web applications. CGI, PHP, Ruby on Rails, Django filled HTML templates with data from the database. Now the pages were dynamically formed on the server, but they still came to the browser in a static form.
3. 2010 - ??: The era of JavaScript.At the heart of the JavaScript era are event streams. Modern web pages are no longer pages at all, but event-driven applications for sharing information. The basis for displaying content on the web — the document object model — still exists, but this is not so much a form of HTML markup representation as a data structure in memory generated by a JavaScript program.
The LAMP architecture is dead because few people now want to send tons of HTML markup in response to every user movement. Instead, it is better to update small DOM fragments with AJAX. But when the amount of JavaScript code in our server templates exceeds 90%, it becomes clear that we are doing everything wrong.
If we recognize this, we will see that the main function of the server is no longer the storage of documents (the HTML era) or the rendering of templates (the LAMP era), but the delivery of data and functions for processing them. The server must give the client the application code, and then the data that the application inserts into the DOM.
In addition, the server should monitor the flow of events (client actions or messages from other servers, such as stock price changes) and send updated data to clients in response to these events.
Node.js architecture is ideal for these functions. Since JavaScript is used by both the client and the server, it becomes possible to transfer part of the calculations to the browser, without any special problems with the mismatch of interfaces and without having to write twice the code that does the same thing in different languages ​​(for example, validation of forms).
Node.js is also great for working with event streams. Thanks to asynchronous, non-blocking architecture, it is incredibly fast. It uses HTTP 1.1 and can hold thousands of open connections at the same time.
Finally, it is worth mentioning that events are nothing more than data packets, and JSON is gradually becoming the lingua franca for data on today's web. It is JSON that is most convenient for client-side JavaScript applications. And for Node.js, this is the native format.
The JavaScript era will transform the Web from a global digital library into a global digital nervous system, the capabilities of which we are just beginning to realize.
About the author:
LinkedIn profile
personal site .