prdn / pigato

PIGATO - an high-performance Node.js microservices framework
http://prdn.github.io/pigato/
MIT License
301 stars 31 forks source link

Workers communication strategy #66

Open TCMiranda opened 8 years ago

TCMiranda commented 8 years ago

Hello guys,

I am using Pigato in some projects for now, but sometimes I still get confusing about allowing workers to communicate or even to use each others services.

In some scenarios, I prefer to not allow sub levels of workers, but in other scenarios, this gives me much duplicate code, which I solve creating shared modules.

To illustrate a little better: captura de tela de 2016-02-13 21 19 52

So, what are your thoughts about it? Does anyone knows some good reference on this subject?

prdn commented 8 years ago

@TCMiranda in my opinion the right solution is the first. Workers can communicate between them via a Pigato client as well, so no need of direct interaction.

Sometimes you may want to reuse code between multiple workers. There you have two solutions:

  1. use a shared library via a separate github/npm project: suggested when you want to share simple solutions
  2. create dedicated workers: suggested for the rest of usecases.
TCMiranda commented 8 years ago

@prdn thanks for your answer!

So, if workers are connected to the "handlers broker" as clients, you would agree to allow them to "communicate" by messages without a separate layer like the second case?

Like this: screenshot from 2016-02-15 15-53-56

The second solution you mentioned would be that case when a worker posts another message as a client to finish its request, right?