Get 50% Discount on Our Udemy Course to Memorize the Periodic Table in 30 minutes Click Here. COUPON CODE: ALCHEMY

Real world examples of how Node.js works

0 votes
5,022 views
asked May 9, 2015 by nanospeck (6,620 points)
reshown May 27, 2015 by nanospeck
I'm interested to know what are the most suitable real world examples that explains how and asynchronous system like node.js works.

2 Answers

0 votes
answered May 9, 2015 by nanospeck (6,620 points)

I found  a good example written by Ryan in Quora 

A popular metaphor often used to describe the difference between an asynchronous, non-blocking model (eg: nodejs) and a synchronous, blocking model (eg: java) is a restaurant.

Asynchronous model
Think of a web application as a restaurant and its incoming requests as customers making orders. An asynchronous application would allow a single waiter to serve multiple customers at once. The waiter takes one table's order and brings their order ticket to the kitchen. Instead of waiting for the kitchen to complete the ticket, the waiter can wait on other tables and handle new orders. Periodically the waiter returns to the kitchen to check the status of his tickets and would serve the customers as orders are completed. 

Synchronous model
A synchronous "restaurant" would dedicate a single waiter to a single customer from the start of its order to completion. As a result, the restaurant needs as many waiters as customers. Furthermore, there would be times when waiters would wait while other work could be done.

0 votes
answered May 9, 2015 by nanospeck (6,620 points)

Here is another one from the same Quora post as the next answer.

Let's say you were cooking a pasta primavera and the following tasks needed to be completed:

1) boil water (takes ~5 mins)
2) throw pasta in water
3) wait for pasta to cook (takes ~10 mins)
4) cut vegetables
5) pan fry vegetables (takes ~5 mins)
6) heat sauce (takes ~5 mins)
7) mix it all together

Notice there are certain tasks which take a longer amount of time, but you aren't just going to put water in a pot and watch it boil. In the meantime, you might decide to work on #4 and if you finish that fire up another stove and start #5. 

There's only one of you, just like there's only one process in node.js... yet you can still multitask by starting "blocking" operations (in our cases anything involving heating) and moving onto other things while you wait for them to complete.

Node works the same way. There's one process with a single thread, but you can write code in such a way that things that take a long time (disk I/O, network I/O, etc) can be interleaved with other operations.

 

 

Related questions

0 votes
1 answer 3,719 views
0 votes
1 answer 444 views
0 votes
1 answer 615 views

Part-time Student Content Contributor / Blogger

Eligibility: 8th-12th Standard Students Only, India

Job Description

Spellogram.com is a unique educational startup for creating engaging learning content. We are looking for creative students who can post new learning tricks to the website on part-time basis.

Salary: 3000 INR per month

Location: Remote / Work from home

Responsibilities

  • Create mnemonic or story bases answers to the questions posted in the website regularly
  • The answers should be creative, engaging and easy to recollect
  • Add new questions and interesting answers to the website regularly
  • Improve the overall user engagement and content quality of the website

Skills Required

  • Should have good imagination and creativity
  • Should have writing skill in English
  • Should dedicate minimum 4 hours / week
  • Having artistic skills like singing, cartoon drawing, acting etc are added bonus but not mandatory


How to Apply

Create a simple trick to learn any topic from any subject you like.

Checkout some examples at: www.spellogram.com

Email a short description about your self, details of your trick and contact number to:

spellogram0@gmail.com

The trick must be short, interesting and engaging and helps the reader to learn the topic very easily.

Tricks are preferred in text format but other forms like cartoons, drawings, songs or even TikTok videos are very much welcome.

Shortlisted candidates will be contacted for a short round of telephonic interview.

...