Hacker News new | ask | show | jobs
by glutamate 1787 days ago
Microservices Pros: Code reusability?

Please ELI5 how I get better code reuseability in microservices than in my monolith with separated concerns into libraries and helper modules.

3 comments

Yeah I think it's better rephrased as "service reusability". A proper microservice should be able to be redeployed anywhere for anything.

If you have an authenticate() function in an auth helper library, you can move that around to new web apps to help users authenticate with different parts of your site(s).

Your authenticate() function for a microservice is probably going to be part of a broader "microservice api library" that gets reused, but I can't imagine reusing the microservice code itself - you're supposed to just spin up a new one.

If you have an “authentication” micro service. I can just reuse/deploy the service for my new app. No coding (maybe some configuration)
I find a lot of people create micro-services when a simple library would suffice. An "authentication" micro-service might make sense in some contexts, but in almost every real-world situation I've been in, this would be better as a library.
I think the idea is that if you only need for an external tool one service you don't need the whole thing.