I just started thinking about building a microservices architecture for learning purposes. I understood that microservices are split, and they should be independent, even when storing data, but what is the real application of it? Most data isn't independent, and is relational in some way, even when using non-relational databases.
My starting idea is a basic app where someone can watch something, let's say a TV serie, have an account with a profile, and can comment and like that TV serie.
The idea is to divide everything in the two following services:
- User service, which basically means authentication and storing users data;
- TV series service, which stores TV series data, episodes, links and other blah blah;
- Streaming service, which handles video streaming, but let's not talk about it.
Obviously, for a correct independent microservices architecture pattern, we should split databases.
Now, my questions are:
- Let's say we use JWT for authentication, so it's stateless, and TV series needs authentication to perform some actions. Should the TV series service implement authentication too? Should they check for your JWT token, or should they call the User service to handle authentication?
- Where should you then store things that a user does - like comments, and likes, if there is a relation between the two databases? If having a single shared database is an anti-pattern, and calling a microservice from another one is an antipattern too, how should you handle a comment? In what database should you store it? And then, how would you do a query which gets "all comments of a specific user" if you can't join or aggregate data between databases, because they're split? Is manual aggregation worth doing?
- Would this approach benefit of an API gateway? I can't understand why and what API gateways are. Though I understood that, someway, they can help joining responses of two microservices.