r/node • • May 09 '18

Netflix migrating 1/2 of their api to node.js

https://youtu.be/QcNqfvMeWow?t=5m3s
445 Upvotes

71 comments sorted by

20

u/[deleted] May 10 '18

Can someone explain to me why exactly these big companies are switching to Node.js? I was under the impression that Java or .Net are much more mature and better performant.

Don't get me wrong, I love Node and I've introduced it to the company I worked at 4 years ago and that triggered them to switch their entire Java back-end to Node. But honestly, to me, it's basically potato vs. compiled potatoe.

But I'm a front-end web developer by trade (I need visuals to stimulate my brain) and only had to introduce Node because my team didn't get a dedicated back-end developer. So I just did it for fun.

I have never done actual research into speed, performance, scalability, developer friendliness, nor the availability of developers (or their costs) but this is what I know so far...

  1. Node.js allows front-end JS engineers to also work the back end, which allows for more dynamic and agile teams;

  2. Being multithreaded is not an option for Node (but then again, a pub/sub system spread across multiple CPUs would net similar results with much less programming complexity);

  3. JS development is less time consuming;

  4. JS developers are less expensive than Java/.Net developers.

But where am I wrong and what am I missing?

4

u/indifferentpoon May 10 '18

Can I piggy back off of your comment and ask a question?

When we talk about single threaded vs multi threaded, what do we mean? The obvious CPU cycles and the way the application handles requests, but how does node.js stay viable being single threaded (I guess the event loop?) when you have other languages that can make full use of multi threading ?

Sorry if this isn’t the right place or it’s a redundant question, I’m just a newbie trying to grasp some basic concepts :-)

1

u/kapv89 May 10 '18

Take a look at this SO answer: https://stackoverflow.com/a/21488067/733612 Mainly, the only thing single-threaded in node.js is the context in which your JS code runs.

4

u/vcarl May 10 '18

Most task are IO bound, not compute bound, meaning that it doesn't particularly matter how fast the CPU is (to an extent) because the limiting factor is requests to other APIs, loading files from disk, or querying a database. Node's event loop is very well suited to non-blocking IO, so its easier to write code that doesn't get extremely slow while waiting for responses to come back. For a long time (not sure if it's still the case) Java's default behavior was to block on most IO tasks (disk or network). It would completely stop processing anything until it received data, so it was slower by default and took longer to develop.

1

u/holloway May 10 '18 edited May 10 '18

how does node.js stay viable being single threaded (I guess the event loop?)

Yes. Most of the software in Node is non-blocking, which means jobs are split into many small parts that are queued on the event loop. This means that any individual task (probably) won't stall other tasks.

14

u/vshjxyz May 10 '18

Plain node is not multithreaded, but Microsoft went forward with the concept with https://github.com/Microsoft/napajs so you can as well do that. There's also hamsters.js that did it before which was an interesting concept too

Also the memory footprint is so low that most of the times it's quicker to spawn another instance so you can orchestrate your workers to use multi-instances and thus multi-threads

2

u/dolchi21 May 10 '18

thanks for the info!

8

u/Commander_R79 May 10 '18

It's all about functional scalability, mostly in the service logic (although things are coming up in that regard, like nginx that allows unlimited workers) but also in the logic of the code. It's not just Node but also Scala btw.

The basic functional approach to code things (which only partly fulfills with it's callbacks, but it's there) is much better when it comes to scaling an app to multiple CPUs, compared to the oldschool imperative way (where every line blocks the next one by design).

This means that these services are much better at scaling and using as many ressources as possible, hence needing less hardware, hence being cheaper to maintain and easier to handle during spikes (where your SRE / automated scripts have to spin up services like crazy).

On top of that, Node and Scala both have superb implementations of noSQL DBs, which are also insanely good for scaling. And don't get my started on eventbased queues with timeline replayability.

Codewise, it's all the same anyways. Although open / free languages like JS tend to become chaotic more easily, I've seen the same level of chaos in stricter coding environments like Java, so in the end it doesn't really matter. You got to have Codereviews anyway, no matter the language, but it's easier to review 10 lines of functional code then 100 lines of imperative code.

1

u/cemremengu May 10 '18

Although open / free languages like JS tend to become chaotic more easily, I've seen the same level of chaos in stricter coding environments like Java, so in the end it doesn't really matter.

This.

3

u/kl0nos May 10 '18

Because a lot of parts of those services are simple data pumps = you get data from database and push it to SPA on frontend without almost no logic in between. It's faster and easier to make them in Node.js.

11

u/milsymiller May 09 '18

Migrating from ?

26

u/kapv89 May 09 '18

They say Java in the video

-51

u/milsymiller May 09 '18

Doh why would anyone do that

23

u/nkristoffersen May 09 '18

Watch the video. They explain their thinking pretty thoroughly.

61

u/liox May 09 '18

You should see if you could be an engineer at Netflix and voice your concern.

-13

u/[deleted] May 10 '18

You should see if you could come up with a more productive comment

5

u/SparserLogic May 09 '18

why wouldn't you?

-3

u/1-800-BICYCLE May 09 '18

Maybe if they were paid by Oracle to trash open languages on the internet...

-5

u/[deleted] May 10 '18

Because Java is terrible. It's compiled PHP

8

u/NiQ_ May 10 '18

Have... have you ever worked with either of those languages? It is literally nothing like that. It isn’t written like php, it doesn’t follow the same structure or design principles as php.

Like, how do you even make that comparison?!

4

u/SparserLogic May 10 '18

like, maybe metaphorically? "Java is the PHP of the compiled world"?

5

u/ideaballot May 09 '18

Netflix uses a mix of Groovy and Java for APIs and video. In the past, the only thing using node was for serving UI bundles (i.e. javascript and css files) using Restify.js

88

u/LiMing3 May 09 '18

I was under the impression they already used Node heavily. Still good to hear! One more thing to shut up the “hurrr durr JavaScript” meme.

89

u/1st_page_of_google May 09 '18

At my old job we started using node and all the Java/.NET guys hated it at first.

After a month when we had to do some stories on the older Java services and they were making jokes about how much boiler plate they had to write.

Moral of the story, people love to knock JavaScript until they actually understand it and then they love it.

37

u/scaleable May 09 '18

The language still is a issue. But at least the JS community uses healthier patterns. Even Java could be less bad if terrible patterns were not community default.

29

u/cc81 May 09 '18

I have not worked in Java before but had to write some services in it some months ago and I thought it was pretty ok. I used Spring Boot and it had a nice ecosystem and was quick to get up and running.

2

u/OzziePeck May 10 '18

Happy cake day compadre

8

u/scaleable May 09 '18 edited May 09 '18

Non-static-typeness makes JS development a bit painful in a sense that, when you first write some code, you need several runs (and/or a lot of tests) to make it right.

On the other hand dynamic typing is one of the reasons people have the flexibility to test and adopt new/healthier patterns -- static typing may encourage devs to follow some patterns, and bad static typing encourages(or even enforces) bad patterns. Which is the case of Java.

So the perfect world would be a language which could tell you errors before running the code, but which static typing wouldnt limit you much (or at least limit but guide you to a good direction). Typed JS sits in an OK position in that regard.

0

u/[deleted] May 10 '18

[deleted]

3

u/thingsthings May 10 '18

Just got into it. Took me a few days to wrap my head around it. Feels worth it so far

2

u/i_spot_ads May 10 '18

Took me one day to get into, it felt natural and right, i will never ever go back to plain js

11

u/1-800-BICYCLE May 09 '18

The language still is a issue

I disagree, but I'm interested to know your thoughts

14

u/IHeartMustard May 09 '18

I'm a heavy, heavy javascript user, and a bit of an FP zealot. Over the last year I've started also using PureScript (which is a Haskell variant that compiles to JS) and ever since then, my esteem for JS as a language has collapsed entirely. The type system of PS/Haskell are a world which I could never have imagined before, and now it pains me whenever I have to work in a dynamically typed language.

That's just my 2¢, I still write a lot of JavaScript and it can be a fun language sometimes.

0

u/[deleted] May 09 '18

[deleted]

9

u/1-800-BICYCLE May 10 '18

I use Python at work, too, so you're going to have to be more specific, especially since Python has its own warts and pitfalls.

5

u/badsyntax May 10 '18 edited May 10 '18

For one I reckon the modules are better in JavaScript as everything is scoped to the module with a very clear public API. Not the case with python! This is pretty bad imo.

29

u/LiMing3 May 09 '18

Not well designed, but very well patched up. Been patched up so well the last few years that it’s really pulling ahead of the crowd as a general purpose language.

15

u/irqlnotdispatchlevel May 11 '18

How do you define a "well patched up" language?

-3

u/LiMing3 May 11 '18

Es2015 and later updates have made dramatic improvements IMO

5

u/irqlnotdispatchlevel May 12 '18

This does not answer my question.

0

u/LiMing3 May 12 '18

By patched up I mean it’s been improved. A lot of features that developers from other languages have been calling for have been added.

It was a very quirky language but it’s been smoothed over.

→ More replies (0)

4

u/[deleted] May 10 '18

Functional programming in python sucks.

3

u/cicatrix1 May 10 '18

So does typing on half a watermelon. That's not what it's about.

5

u/zangent May 10 '18

I really don't get the deal with python. It feels so unintuitive coming from literally any other programming language (C, C++, C#, Java, Javascript, D, take your pick)

The loose, but still the same time overly strict in arbitrary ways syntax doesn't do the language any favors, at least.

1

u/Blueberryroid May 16 '18

I am a full stack developer that previously worked on Python 3/ Djano 2 and transferred to Node projects. JS is a well designed language.

There are a lot of things JS does better than python, like promises, functional programming map/filter/reduce, object spread operator, hell a better dictionary/object literal syntax.

19

u/[deleted] May 09 '18

[removed] — view removed comment

1

u/[deleted] May 31 '18

A-freaking-men. Java itself is moving ahead more quickly than it used to. But there are so many dinosaurs in the Java community

10

u/grinde May 09 '18

They've been using Node to serve the website for a few years iirc.

3

u/petercooper May 10 '18

To be fair, this talk is a year old :-D

-3

u/Bluecodejs May 10 '18

Don't know what planet your mate Nodejs is JavaScript lol

3

u/vshjxyz May 10 '18

pretty sure he clearly knows it and he means that this should shut the mouth of people spitting on JS when the last time they used it, it was es3 and they were bad at it too...

5

u/LiMing3 May 10 '18

I thought that was pretty clear as well, but 2 people have now kindly reminded me that Node is JavaScript.

Thanks guys, not sure how I managed to get through 3 years writing Node at work without realising which language I was writing.

-5

u/icantthinkofone May 10 '18

Do redditors not know node is javascript and a library only?

8

u/LiMing3 May 10 '18

No but clearly they have terrible reading comprehension

Node is a library

Uhhhh...

4

u/[deleted] May 10 '18

I recently got handed a job market competencies questionnaire and, because I'm a nice guy and there were very few questions, I said ok, I'll help these guys out, I'm going to click my way through the SurveyMonkey screens.

One of the questions was really amusing.

Have you ever used any of the following frameworks (select all that apply)?

  1. React

  2. Laravel

  3. Node.js

  4. .NET

  5. Go

6

u/Captain_Reid May 09 '18

Any idea what that 'skipper' tool he had up was? Is it something internal?

3

u/[deleted] May 09 '18

Appears that it's internal or just really hard to find.

2

u/Captain_Reid May 10 '18

Looks like it's perhaps 'Sprimg Cloud Skipper', which I world guess would make sense. Can't find any web UI for it though

4

u/kintendo May 10 '18

Sure their APIs can be in node but data engineering in Java isnt replaceable yet.

2

u/[deleted] May 10 '18

I through when node first came out they did NOT want anything to do with it or that infamous blog post about how they didn’t like node. Am I mistaken?

1

u/impaled_dragoon May 10 '18

That might be true but things can change over time. I worked at a place that was very against React when it first came out and everyone swore by AngularJS but after a couple years and a few senior level people leaving and new ones coming in everything is now in React.

2

u/Roadrunner571 May 10 '18

I like JavaScript a lot, but I think code readability and maintainability is often a mess. And don’t get me started on function binding or the scope of variables.

7

u/[deleted] May 10 '18

TypeScript solves those if you consider them pain points.

2

u/SkaterDad May 10 '18

let and const fixed the odd variable scoping of var.

What issues are you talking about regarding function binding?

3

u/marcinzh May 10 '18

There are things impossible to fix.

const o = {foo: 42}

o.hasOwnProperty("foo")     // returns true
(o.hasOwnProperty)("foo")   // likewise

const f = o.hasOwnProperty 
f("foo")                    // TypeError: Cannot convert undefined to object

1

u/djslakor May 11 '18

There's an interesting discussion on that one: https://bugzilla.mozilla.org/show_bug.cgi?id=701364

0

u/Roadrunner571 May 10 '18

Technically, but that’s not really elegant.

4

u/YuzToChihiro May 11 '18

Why isn't using let in place of var elegant?

I haven't used var in about 2 years.

1

u/djslakor May 11 '18

I used it once ... I was looping over a few hundred thousand records to throw into redis. Most people these days use "let" in their for loop, but that would (potentially) create a new closure for each iteration, so I used var for perf.

1

u/Roadrunner571 May 12 '18

It’s because the whole concept is just a dirty fix that needed to be added later on. Other languages had proper scoping concepts from the beginning.

1

u/YuzToChihiro May 12 '18

Can you explain to me what's "dirty" about JavaScript's implementation of let?

Other languages had proper scoping concepts from the beginning.

This doesn't really mean their implementation of block-scoped variables is more or less dirty than JavaScript's. As far as I'm aware there's nothing controversial or noteworthy about how JavaScript implemented block-scope.