This question has arise to me for a while now. I am working in a company apply microservices architecture. They have a big monolith written in PHP but recently break down that into smaller microservices written in nodejs/es6.
I know Node.js is non-blocking-io and can handle lots of requests compared to blocking io couterpart. And nodejs and npm echo system provides lot of awesome dependency that we can make use of.
But the problem is that the Node.js backend code is not very easy to read if you just use Promise. I usually need to use async/await to make to code more imperative.
So my question is why don't we just write nodejs as controller to handle incomming request and then forward that request to micro-services backend written in Java/Python/PHP. With that approach we still leverage the nio nature of nodejs and still can leverage the clear code style of other programming language.
To me, We can combine the best of both worlds.
What is your thought ?
I agree with the sentiment about a typed language being preferable. For that reason I use TypeScript for any JavaScript microservices that I write (any JS for that matter).
I also like to use a backend framework named NestJS that uses TypeScript and provides a strong architectural foundation for backends written for Node. It also has great support for transports other than HTTP for communicating with other microservices, like gRPC, Redis pub-sub, MQTT, and NATS.
One of the advantages of microservices is that, like you've proposed, you can write services in whatever language fits the project. And then by using a transport layer like gRPC, you can maintain type safety between all of the services, even the untyped ones like JS, PHP, Python, or Ruby. gRPC uses a language called protocol buffers for defining over-the-wire types and then has a set of code generators for generating objects based on the types in your language of choice.
But the problem is that the Node.js backend code is not very easy to read if you just use Promise. I usually need to use async/await to make to code more imperative.
So... write it with async/await and be happy? :) You aren't required to use promises in JS, use whatever coding style suits your team and your purpose.
If you just want type safety, use one of the many static-typed options that transpile to JS .
If you don't want to write JS at all, then don't... as Mark points out you can write async code in other languages.
Now this this a very interesting concept. I would consider myself a newbie to Node.js, but I think I get what you're saying. Maybe one day I'll give this a shot. It could prove to be very useful.
Mark
I don't think you need to use nodejs forwarding to other languages if you just want to have async performance.
Other languages are also able to do async io, just the event loop is a library instead of built-in. E.g. Python has async/await and can do event loops with e.g. Twisted.
If the goal is to abstract the event loop stuff away from the main code, then you could indeed use Nodejs, but there are other options.
For the type safety, I'm not sure what you're asking. Typescript would make nodejs more type-safe and scalable. Python is indeed more strongly typed than Javascript, and I personally think it's an improvement. You could also use statically typed language, like Java, Kotlin, Rust...
I really like type-safety myself, I think it's most important for large, long-running projects maintained by many people. It'll be a bit slower to get started, but you'll have a lot more guarantees and context when making changes later. And there's performance as a bonus.