After reading and using different concepts(right or wrong) questions related to modularity have appeared.

I want to implement the microservice architecture in my projects the right way.

As from what I have understood in order to follow this architecture my project needs to be modular.As an example breaking down a social network into different services as chat API service, web API service, mobile service API etc...

What protocol should be used to communicate between the microservices?Is communicating through a REST protocol okay?For example, communicating via JSON?Also, how can I secure my communication between API 1 and API 2?

Now talking about OOP and Functional programming.

I've red that OOP is used when you have a fixed set of operations and when your code evolved you add new things.On the other hand, Functional programming is used when you have a fixed set of things and as your code evolved you add more operations.Can somebody give me an explanation for this?

Now to summarise these questions and to ask it as one question.What is the best approach to use different programming styles at different parts of a project when following a microservices architecture?

closed as too broad by gnat, Laiv, Useless, amon, Robert Harvey Mar 21 '18 at 16:42

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    This is fairly broad. Please help us focus by explaining why, with everything else up in the air, you're already certain you want to use micro services. – candied_orange Mar 21 '18 at 13:15
  • 1
    "I've red that OOP is used when you have a fixed set of operations and when your code evolved you add new things.On the other hand, Functional programming is used when you have a fixed set of things and as your code evolved you add more operations." – Where did you read this? This sounds like an extremely bad explanation of the Expression Problem. – Jörg W Mittag Mar 21 '18 at 21:37
  • Here is the source to the answer : stackoverflow.com/questions/2078978/… – DaAmidza Mar 22 '18 at 7:38
  • That answer contains a link to the original explanation of the Expression Problem. Did you read it? – Jörg W Mittag Mar 24 '18 at 9:32

In reverse order: There is of course no generic answer as to which paradigm is "best" for microservices. You have to know your use-case and have to decide for your self. This is almost impossible to get right without a lot of experience, and even with it most projects get it wrong.

OOP vs. Functional: The two are not that different actually. Both have a concept of encapsulation, clear separation, etc. The key difference is that Functional tends to be more disciplined. You have to know your math and how problems can be decomposed mathematically. OOP is basically programming for math-challenged people. I'm saying that as an OOP developer. In any case, neither is more appropriate, it depends more on the people than the problem itself.

Communication between Microservices: The first rule of communication between microservices is that you shouldn't communicate between microservices. A microservice should be a functionally complete part of your domain. Any communication to other systems should be fire-and-forget type. That is, you either send a message to a system, or that system sends a message to you, but not both. Both would mean that your problem is not cleanly separated from the other service.

Anyway, the exact method of communication is not that important actually. Can be HTTP, through a Message Broker, or through TCP/IP connections. Does not matter, and should actually depend on the requirements of the communication itself. Should it support large amount of data, should it be secure, etc.

Summary: The most important thing is to get a clean decomposition of functionality (so you don't require request-response communication). All the other things you can experiment with easily then.

Also, it helps if you know why you are doing microservices. Presumably you have some non-functional requirements, like teams, operational requirements, performance/scaling requirements etc.

Ultimately whether you are doing it right depends on whether you can meet your goals regarding the architecture. There is no real absolute measurement of what is the "right way" except your own goals.

  • Thanks a lot for clarifying some things.When you said that microservices should not communicate with each other did you mean in the sense of child-child or child-parent?Let's say Facebook parent mobile API has the child chat microservice.And the communication with the phones goes over the parent than to the child microservice.Id likes to clarify this than I'll accept the answer. – DaAmidza Mar 21 '18 at 13:40
  • I'm saying barring any other factors/requirements, there should not be a "mobile API" service. That would need synchronous request-response communication with the "chat service". This couples both, and makes the whole construct more fragile. The "chat service" itself should support a mobile-consumable interface for its own chat-related things. – Robert Bräutigam Mar 21 '18 at 15:01

As for microservices, you need to be careful of the not communicating with each other. For example, you could have an authentication microservice. You would want other microservices that need authentication to communicate with the auth microservice and not implement their own. You also want microserviced communicating through a network connection/queueing service and not through a back channel as in database tables. There are a number of open source project (openstack, jeager) that if you could get inspiration from.

  • I actually would not like direct communication with the "authentication service" either. There are authentication mechanisms that don't require that, like Kerberos, Json Web Tokens. – Robert Bräutigam Mar 21 '18 at 15:08
  • You mean the Kerberos that uses an Authentication Server? The Json web tokens that are provided to the client by an authenticating server? – Useless Mar 21 '18 at 15:43
  • 1
    @Useless Yes, those. Neither of those things require a service to communicate with the authentication server. The "token" provided to the user cryptographically contains all the information needed for the service. – Robert Bräutigam Mar 21 '18 at 19:10
  • Oh, you just mean indirect communication with the AS, not no AS at all? Sorry, I misunderstood your comment. – Useless Mar 22 '18 at 13:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.