Search code examples
node.jsweb-servicesamazon-ec2microservices

What is an efficient way to communicate in microservices architecture


I am using Node.js and a REST based light weight web service to communicate between servers. i want to know if there is another more efficient way to communicate between servers? I am using ec2 instances in a vpn.


Solution

  • More efficient than REST over HTTP will be, from least efficient to most efficient:

    • REST over HTTP/2
    • WebSocket
    • TCP sockets
    • UDP packets

    But this difference may be completely irrelevant if your miscroservices are actually doing anything useful and don't spend most of their time handling the HTTP headers.

    For example, when you spend half a second waiting for the database and then return a megabyte of JSON then adding few additional lines of HTTP headers can be even not measurable.

    You need to profile your code and test it before doing premature optimization and keep in mind that some of those ways to communicate more efficiently in terms of sending less bytes, can be much less efficient in terms of development time, maintenance and debugging. Keep in mind that nothing is easier to inspect and debug than text based protocols like good old HTTP/1.1 that you can talk to using netcat or anything else that handles plain text.