5 ms·
> sharing actual business logic through libraries is often a bad idea (which is unintuitive to most). Seems unintuitive to me too, would be curious to hear if
by tobr 7y ago
> sharing actual business logic through libraries is often a bad idea (which is unintuitive to most).
Seems unintuitive to me too, would be curious to hear if you have more to say about it!
- dwohnitmok 7y agoNot parent, but I can share my own experiences as to why you might not want to share business logic. The short answer is you couple your microservices together and bring yourself one step closer to a distributed monolith with all its attendant pros and cons. This is especially so if you're in an OO world where data and logic are coupled together so that sharing business libraries often entails sharing business data models. This is also aggravated by the fact that the nature of business logic makes backwards-compatibility difficult to achieve (behavior often changes even if the programming API remains the same). This means changes to business logic libraries often require all downstream users to upgrade immediately or risk inconsistency (which negates the purpose of using a single library in the first place). Shared libraries when using microservices really only work well if it's reasonable to have multiple versions of that library running across different services. In other words, to some degree the sharing is only coincidental in nature. The conventional wisdom around microservices as far as I'm aware is to try to segregate services by business function (rather than e.g. segments of your domain model) to minimize sharing of business logic. Extensive sharing of business logic is a good indication your services are not split across proper lines. Of course getting these divisions down is really hard and therein lies the heart of why getting microservices right is hard.
- maxxxxx 7y ago"Of course getting these divisions down is really hard and therein lies the heart of why getting microservices right is hard. " I think you can only get this right if you deal with pretty mature processes that are well understood.
- shados 7y agoImagine you have a React/Redux app with Rest endpoints. You have a dumb "Button" component. You share that with all the other apps. The Button is in React. You now tie your entire ecosystem to React. Not having individual apps have to agree on dependencies is one of the benefits of micro apps, and you lost that. However, you only lost that for React, which many people agree is pretty darn good and not going anywhere. That's a tradeoff we take. Pure React components are also well encapsulated, so whatever the opinions are behind the Button doesn't pollute the apps. App owners are still free to architect their apps however they want: their only hard requirement is React. Now, imagine you have a Medium style text editor built with React, Redux, and rest endpoints, complete with automatic draft save, a working publish button, onboarding experience, etc. If you share that, now all your apps have to agree on: backend, authentication, I18n, Redux, state management architecture, it probably uses local storage and cookies, is opinionated on what you do when logged out, and so on and so forth. If you bring that editor in an app, you're now tied to all of this. If 100 apps use that editor, and they want to upgrade Redux in the editor, they all have to upgrade to get back to the same version. If you change the backend, you have to also upgrade all apps or keep the old endpoint forever. If you want to add an I18n language, you will have to rebuild/redeploy everything. If you don't encapsulate your state, its architecture will pollute the app, but if you do you're likely going to have a much more bloated library (more bytes, slower download). Apps are no longer free to make their own decisions. It gets worse if you have transitive dependencies. Your app depends on A that depends on B that depends on C. Your app also depends on C. C releases a new version that your app wants. You now need to either bundle two versions of C, or upgrade the world. If C has global side effects, bundling 2 versions of C might not even be possible at all. These kind of "full stack components" are tech debt the moment they hit your apps. As the other reply to your post stated: you end up with the worse of both worlds. All the costs of micro-apps, with all the costs of a coupled monolith TOO. Its much worse than if you had picked either one or the other.
- halleonard 7y agoGreat answer
- camgunz 7y agoThat all sounds like frontend components to me. Is there any benefit to duplicating the implementation of business logic for each micro frontend? My instinct is that would lead to inconsistent behavior across them.
- marcosdumay 7y agoIt's a losing proposition. If you replicate the interface of a set of business logic, those will start to deviate, and the business logic turns into a mess. While if you refuse to replicate the interface (by deeply coupling it to a client) different teams will have to cooperate while creating requisites for it.