How does microservices work?
Hello, quick question, what are microservices? I hear that term often but didn't really understand, is it some kind of api that we call for third party services?
8 Replies
It's just a term. An API could be considered a 'micro service', but so could many, many other things, including cutting your neighbours grass. As always, context is important.
Microservices are usually discussed as the opposite of a monolith service. A monolith is one service that does it all. Auth, web server, API, whatever the business needs is all handled by one service.
Microservices are a collection of services that each do something different and specific. For example, say you have an image sharing site. You'd have one service for auth, one service for file upload, and one for shortlinks.
Each service is a self-contained app with no shared anything. So your upload microservice has no way to connect to the auth DB to know if the user is authorized to upload…so the auth microservice needs to provide a short-lived token of some kind. And when the token expires then the upload service hits the auth service for a new token.
yep I see, thanks !
Are microservices worth it? or do we build them because of the "trend" just like with AI stuff being integrated with anything
They are worth it when you need them, but a lot of people use them because "it's easier" than one monolith service. But then you run into issues like your upload service can't simply query the user DB to know if a user is allowed to do that action—not to mention the fact that you can't revoke static tokens so if a token is stolen there's very little that can be done until it expires. That's why tokens are designed to be short-lived: like 5m or 10m or something.
On the other hand, can you imagine trying to run Facebook off of a single monolith?
Usually, though, people prefer micro-services b/c it can hide more bad code than a monolith.
yep I see
honestly, you are very far from microservices being worth if
unless you need them, they arent worth it
This ☝️
But, like React, more people use it then should be so it’s good to know it exists and what it is
yup
it's not something you will see on your daily code