Sequence Diagrams for Asynchronous Flows in Node.js
Ben Kittrell
06/13/2012 05:09PM
If you're getting started with Node.js, like I am, chances are you're having a hard time grokking asynchronous workflows. I'm typically a "just dive right in and kick it till it works" kind of guy, but I've been trying to discipline myself a little more and do some planning. After trying some different techniques I found sequence diagrams to be very helpful. I guess I did learn something from all of those years of corporate Java development.
Sequence Wha?
For those unfamiliar, in a sequence diagram, the vertical lines represent components in your application or architecture and the horizontal lines represent messages between them. The white vertical rectangles represent the life that particular component.
Examples
I'm working on a Node.js media server. Here's a diagram of a potential slave replication flow.
Right away you can see that there is nothing asynchronous about this. The browser has to wait for a lot of stuff to finish before the connection is released. In reality, the connection could be released as soon as the file is saved.
Here's an improved flow, with the addition of video transcoding.
The file is uploaded, and an asynchronous video transcoding job is started. Right away we replicate the original file to the slaves. At this point, everything is in the hands of the transcoding job. When it's complete, we download the completed files, set the metadata such as the duration, replicate to the slaves and set the status as finished.
You can easily see that the browser session is very short, which is what we want in an asynchronous flow. As soon as the uploaded file is saved to disk, it returns a 200 and then starts the a video transcoding job. Also, we can start copying the original file to the slaves before the transcoding is finished.
It's also clear that some pieces still need to be synchronous. We can't replicate the the slaves until we have the files and the metadata, and we can't set the status to finished until the files are replicated.
However, it also shows a weakness in this flow. The only thing that can complete the flow is a message back from the video transcoder. If that message is never sent, we have an orphaned file. This suggests that we may need something to check for failed jobs and retry.
I used OmniGraffle for these, but you can also just draw them out on paper.
Comments
http://www.websequencediagrams.com/ ???
this doesn't seem like it would scale if the master is receiving files from the browser. the master would be a bottleneck if you plan on having multiple users upload files.
slaves should be receiving the files and either queueing jobs for the master to handle and replicate, or they should be doing the work themselves and be aware of other slaves in the array that they need to replicate to.
Patrick, Nice Link!
Langdon, That's a good point, and something I'll consider. One part of the design that isn't in this article is the load balancing. Let's say I need to get the URL for an <img tag. The app that generates the URL will have a "Registry" from the media server that tells it the host names of the master and all of the slaves. If the app knows that the file is "Finished" (replicated) then it will choose a random URL from the registry. Otherwise it uses the Master URL. Too your point that would add even more stress to the master.
I guess I could have the app keep track of where it uploaded the file, instead of just assuming it was the master. In that case there would be no need for a master, just a cluster of nodes. Something for me to chew on.
JavaScript is very good at handling variable args :)
[code]
function foo(){
alert(arguments.length)
}
foo(1);
foo(1,2);
[/code]
I have no words to appreciate this post ..... I'm really impressed with this post .... the person who created this post was a big thank you man .. for sharing with us.
http://www.wedding-bliss.org
Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you.
www.autoskola-hyvnar.org
Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you.
http://www.computeroutlets.org
I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post
http://www.winetourtemecula.com
I've seen your awareness about this theme whenever you post it and it really gives an informational message to us readers. I am hoping that you'll continue writing this kind of blog. Thanks for sharing this information.
http://www.residenttechnologies.com
Must say that overall I am really impressed with this blog. It is easy to see that you are passionate about your writing. If only I had your writing ability I look forward to more updates and will be returning.
http://www.anyonecanbe.co.uk
Hello Ben,
Thanks for the post.
i would also like to ask you, is there any plugin, program etc to automatically create a flow chart or a state diagram directly after importing my source code?
This is such a great resource that you providing and you give it away for free.
http://www.fedes.net
I am very happy about the sequence diagram for having this one. The blog helps every user to get many www.thebestessayshelp.net web articles. Every diagram is important to all of us and the details really useful to get more knowledge.
Cheats in clash royale are not of any worth for me, even though we can create free gems using the clash royale hack from this webpage http://freeclashroyalehacker.net it obviously ruin the gameplay. Getting free gems for clash royale can make you powerful, but use clash royale cheats on your own risk.
Its nice post ! Thanks for sharing such wonderful article. Keep sharing. Waiting for more.I'm going to subscribe so that i can come to know every updates! Get digital marketing course pakistan from http://www.pnytrainings.com/social-media-marketing-training-lahore/
I have read the topic to learn sequence diagrams http://legitimate-writing-services.blogspot.com/2016/06/ukessays-com-review.html websites. The details you can find from this blog with great features. Everything we are needed to get many opportunities and asyn articles.
This was one of the most well documented blog entries I have read in a long time. It was a pleasure to fill all the gaps I had about this topic. Well written an concise. Get gym flooring easy to wipe from http://www.gymflooringco.co.uk/gym-flooring.html
As most fans know, the upcoming season 6 of Teen wolf http://teenwolfonline.us of the show will serve as its last on TV, which came as a disappointment to viewers of the drama.
Great article by Ben Kittrell , thanks for sharing great knowledge.
I can't tell you that i gain lot of knowledge from this article.
I also write article on domain name registration service <a href:"http://cashhost.net"> domain name registration
service </a> for additional features of domain name registration service.
Thank you so much again
this is a great article and give more information for visitors
also read my article hope this will be help you in pets industry https://www.pet-fashion.co.uk
very good indian face massage you can use easily and buy from our website http://marys-courses.thinkific.com/courses/indian-head-massage
you can easily buy from this website
<a href="serialgamingonline.net">Serial Gaming Online</a> will relieve all your stress and take your game to a high new level!
http://serialgamingonline.net will relieve all your stress and take your game to a high new level!
if you want rent a car in moroco, then simply visit this website http://www.cosmos-car.com/
and get good and cheap plans
What an informative article, Felt Ball Rugs have become very popular item nowadays in the area of
home, office and baby nurseries decoration. I also write article on https://www.mimosacrafts.com.au/felt-ball-crafts-australia/felt-ball-rugs. Please Read this
Thanks
Regards
Alex John
Wi-Fi router technology has made very quick changes from the past few decades. With increased use of
Smartphones, gaming consoles and other network-based gadgets, the need for a good router has also elevated
drastically. For complete article please visit http://bestcomputersforgaming.com/best-wireless-routers/
Great article| this article is very informative to its reader.
These are beautiful Mexican style heavy duty hooded ponchos. Made by our skilled artisan from 100% cotton (also known as Shyama or Gheri Cotton). These Baja Style Nepalese Hooded Poncho are available in two types; Brushed and Unbrushed. The brushed poncho has its outer part hand brushed for fuzzy looking and warm feelings though both types are very warm. visit for complete details
https://www.mimosacrafts.com.au/clothing/mens-clothing/mens-poncho
Good news for me!
Thanks a lot...
http://www.purevolume.com/bingo49634
ES File Explorer Apk
https://www.esfileexplorerproapk.com/
https://www.goatsimulatorapk.com/
nice post. also check free movie streaming sites here: https://www.goodtechtricks.com/top-best-free-movie-streaming-sites-2016/
http://www.barcelonavsalavescdrfinal.com/
iZombie Season 3 will portray Liv gulping down the brain of a dominatrix. Therefore, we can expect the upcoming installment to be more engaging than the previous ones.
I would like to appreciate your properly written content it's useful and your writing concept helped me to the idea without the difficulty. Thanks http://worldcosplay.net/member/608324
I found useful information on this topic as I will be taking care of a company project. Thanks a lot posting relative information and its currently becoming easier to finish this project http://8tracks.com/bliherbalsehat
Now i'm currently focusing on an assignment and I have been exploring your page for a few hours. I'm appreciate your the idea proved valuable for me. http://www.bookcrossing.com/mybookshelf/bliherbal/
https://noxappplayers.org/
https://www.bestlaptopsunder500d.com/
Interesting post! I really impressed to read the great information that you have shared with us. Keep doing the great work up. http://callatlantaplumber.com/ is the best home services.
http://walmart-creditcardlogin.org/
Amazing work! I really impressed to see the information that you have shared with us. I want to say thanks to you for the sharing of this great post. http://www.netwising.com/
Amazing work! I really impressed to see the information that you have shared with us. I want to say thanks to you for the sharing of this great post. http://www.netwising.com/
http://blog.dnevnik.hr/girlchat
http://clickandchat.eklablog.com/
http://jemmawilkins.doodlekit.com/
Tracking Axis bank credit card status details is easy now-a-days
my website. please checkout.
http://rootexplorerapk.net/
For its new Hulu Live service, MoffettNathanson uses a range of calculating advertising at $5.89 to $9.82 per subscriber per month. It also assumes an average consumer monthly price for Hulu Live at $40 -- the current price of the package.
For its non-linear, on-demand programming service, Hulu is estimated to have generated $8 to $9 per subscriber per month, factoring in lower advertising loads and healthy CPM priced ad units.
By way of comparison, estimates from Hulu’s existing businesses indicate the company pulls in just over $900 million annually in advertising.
Last year, Alexia Quadrani, media analyst of J.P. Morgan, estimated that Hulu revenues -- from its legacy ad-supported on-demand service, Hulu, and its non-advertising service Hulu Plus -- would total $2.4 billion in 2017. (That counts 61% from subscribers revenues/39% from advertising).
https://helpguide.co/hulu-plus-login-sign-in-www-hulu-com/
I think this might be helpful: 192.168.0.1 https://19216801help.com/
https://www.downloadtubemateforpc.com/
https://www.downloadtubemateforpc.com/tubemate-apk-for-android-free-download/
https://www.downloadtubemateforpc.com/tubemate-for-mac-pc-free-download/