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
RAiDeRTuRbO
RAiDeRTuRbO2w ago
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.
13eck
13eck2w ago
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.
Faker
FakerOP2w ago
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
13eck
13eck2w ago
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.
Faker
FakerOP2w ago
yep I see
ἔρως
ἔρως2w ago
honestly, you are very far from microservices being worth if unless you need them, they arent worth it
13eck
13eck2w ago
This ☝️ But, like React, more people use it then should be so it’s good to know it exists and what it is
ἔρως
ἔρως2w ago
yup it's not something you will see on your daily code

Did you find this page helpful?