'Should multithreading be used in microservices?
Should parallel programming be used in the development of microservices in case the microservices are scalable and, for instance, deployed as ECS on AWS?
If yes, what are the benefits of consuming more resources by one instance vs the same resources by N instances?
How does parallel programming match https://12factor.net/
P.S. to be more specific - should I conceptually use parallel streams rather than simple streams?
Solution 1:[1]
Basically the link that you provided also provides answer to your question already
This does not exclude individual processes from handling their own internal multiplexing, via threads inside the runtime VM, or the async/evented model found in tools such as EventMachine, Twisted, or Node.js. But an individual VM can only grow so large (vertical scale), so the application must also be able to span multiple processes running on multiple physical machines.
Solution 2:[2]
Sure, imagine a microservice that needs to execute multiple independent calls to a dB or to other microservice and aggregate the results. As the calls are independent, they can be executed in parallel so that the total time is at most the time it takes to execute the slowest call.
Solution 3:[3]
Parallel streams must be used when the tasks at hand are mutually exclusive and can be done in parallel. However, parallel programming comes with an overhead of using a little more resources. So depending on the tasks at hand, you need to make a decision with trade-offs, which would be the best for you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ivan |
Solution 2 | |
Solution 3 | dgupta3091 |