バックエンド開発のためのJavaScript : Javascript for backend development

バックエンド開発のためのJavaScript : Javascript for backend development

※本稿は弊社のCTO、Slavi Pantaleevによる記事です。

Our previous series of articles (the current state of web-development: #1, #2, #3) talked about Javascript and its popularity in frontend web development.

In this article, we’re going to talk about the role of Javascript in another area: server-side web development.

前回はWEB開発のフロントエンド側のJavaScriptについて、いかに多くのシーンで利用されているかをお話ししました。(2014年WEBの世界で起こっていること(1)(2)(3): The current state of the web)



The most important change in the Javascript world that stemmed from Google’s V8 engine is the appearance of the Node.js platform in 2009.

Node.js is an environment for running Javascript on your server. The Node.js platform is a combination of Google’s V8 Javascript engine and a set of APIs (ways to do networking, filesystem operations, process management, etc.) that help with the development of server-side programs.

Node.js enables developers to use Javascript to write server-side (backend) programs. Not only that, but it’s highly-performant, scalable and ideal for creating distributed network services.

The Node.js environment functions in a similar way to how Javascript works in the browser. Programs are simple to write and understand. This allows frontend web developers that already know Javascript to easily transition into writing backend code.



Node.jsはサーバ上でJavaScriptを動作させる環境です。Node.jsプラットフォームは、GoogleのV8 JavaScriptエンジンといくつかのAPI(ネットワーキングを行う手段、ファイルシステム操作、プロセス管理など)の組み合わせでできており、サーバ側のプログラムの生成を助けます。



Node is good for real-time services

If you are to write a real-time chat system (like Facebook’s chat or Omegle) in a language like PHP (or Ruby or Python), you will face many challenges. To make it real-time, you need to push messages from the server to your users as fast as possible. There are 2 ways to do that:

  • frequent polling – you make the user’s browser ask your server “are there new messages for me” often (multiple times a second)

  • comet-streaming (long-polling) – you keep an open connection between the user’s browser and your server at all times and push new message over it (as soon as your server is made aware that there are new messages)

Both approaches don’t work well under scale.

Frequent polling leads to many re-connections and a lot of overhead – each request takes significant time to process.

Long-polling wastes a lot of memory – each open connection takes some megabytes of memory – you can’t service many users with a single server.

The modern web requires that you can handle tens of thousands of concurrent users at the same time. This is also known as the c10k problem.

Node.js is designed to be great at handling a lot of concurrent users and their data in real-time. It can keep thousands of client connections open and periodically do small amounts of work for each one.

(For completeness, we need to mention that there are ways to achieve the same result in other languages, albeit in a more complicated way compared to Node).



  • 頻繁なポーリング – 「私あての新規メッセージはありますか?」という、ユーザーのブラウザからあなたのサーバへの問合せ回数を多くする(1秒に複数回)
  • コメット・ストリーミング(ロングポーリング) – ユーザーのブラウザとあなたのサーバ間のコネクションを常時オープンな状態にしておき、新規メッセージをプッシュする(あなたのサーバが新規メッセージに気付いた段階ですぐに送る)

頻繁なポーリングでは、再接続が何度も必要になりオーバーヘッドも非常にかかります – 各リクエストごとにプロセスにかかる時間が大きいのです。

ロングポーリングでは、メモリーを多く使います – 各オープンコネクションにつき何メガバイトかのメモリーが必要です – ひとつのサーバで多くのユーザーにサービスを提供することはできません。




Node provides concurrency in a simple way

In most other languages, developers either perform tasks serially or use threads to parallelize work. Threads, however, are a dangerous feature – one that often leads to many hard-to-find bugs.

Node’s asynchronous execution model enables developers to parallelize certain types of work (work that involves input/output operations) in an efficient and safe way.

Thanks to Node’s simple concurrency model (asynchronous execution in a single thread), developers can perform many tasks at once, without the danger of using threads. Many customers can be served at the same time in an optimal way.


他のほとんどの言語では、開発者はタスクを連続的に実行するか、作業を並列化するスレッドを使用するかのどちらかです。しかしながらこのスレッドというものには危険な特性があります – 多くの発見困難なバグにつながる特性です。



Node is good for small web services

Node.js can be used to create small and useful backend programs.

They don’t even need to be full-fledged servers that do a lot. It could be a simple API server or just a small component that is part of your service-oriented architecture.

Node‘s power can be leveraged without throwing away all your other code. Modern web-development is diverse – many languages and frameworks, each offering a set of benefits. If you’re not afraid of mixing technologies (and you shouldn’t be), you can use your favorite web-development language for most of the code and only use Node where it makes sense.




(訳注:service-oriented architecture:ビジネス・プロセスの業務機能サービスに基づいたシステム設計構造◆【略】SOA(出典:アルク辞書))

Node’sの能力を活用するのに、他のコードの使用をあきらめる必要はありません。現代のWEB開発は多様です – 多くの言語、フレームワーク、それぞれに複数の利点があります。あなたがテクノロジーのミックスを恐れなければ(そしてまたそうであるべきなのですが)、ほとんどのコードについてはあなたお気に入りのWEB開発言語が使えるでしょう、そして理にかなっている部分のみにNodeを使用すればよいのです。