Skip to content

Instantly share code, notes, and snippets.

@maxenglander
Created August 8, 2012 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxenglander/3291569 to your computer and use it in GitHub Desktop.
Save maxenglander/3291569 to your computer and use it in GitHub Desktop.
Node.js metaphor

A traditional request handling model works like this:

  1. Browser makes a connection (think of it as dialing a restaurant)
  2. Server accepts the connection (restaurant employee answers phone)
  3. Browser sends a request (think of this as saying "I'd like to make a dinner reservation")
  4. Server processes the request and sends the response ("Got it, your reservation is made")
  5. The connection is closed (both sides hang up)

This is great, except that each employee is expensive, and the restaurant can only afford to pay N employees. If there are more people calling in a given moment than their are employees to respond to a call, callers will get frustrated that nobody has picked up, hang up, and try again later (or try another restaurant).

Node.js does things a little differently.

  1. Browser makes a connection
  2. Server places the connection in a queue (puts the caller on hold)
  3. Server process takes connection off queue, an accepts it (employee takes caller off hold)
  4. Browser sends the request
  5. Server processes request and sends response
  6. The connection is closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment