Reputation: 1361
I'm trying to understand what microservices are.
As I understand right now, it's just separated self-contained services that can be invoked by each other or by the client.
Let's say I have ProductService and UserService. If our system allows people to comment on product as well as user, should we store the comments of both systems in a comments table, or should each of them have separate comments table?
Should each service use its own database or store them in one place?
Upvotes: 0
Views: 534
Reputation: 31760
As I understand right now, it's just separated self-contained services that can be invoked by each other or by the client
You understand well! That's a pretty decent definition right there:
If our system allows people to comment on product as well as user, should we store the comments of both systems in a comments table
You would only do this if you had a separate Comments service. From your own definition, services should be self-contained. That means not having shared dependencies, like data models or database tables.
Should each service use its own database or store them in one place?
Again, quoting from your definition, services should be separated (or at least separatable), so as long as they do not use the same database instance they could share a server instance.
Upvotes: 3
Reputation: 468
Sounds like you think about splitting services according to entities, that's not really a good idea.
In the example you gave you could go with either approach or store them separately from both, or duplicate. It depends on what you're trying to do, how do you access that information and how your services interact with each other. Fast solutions, without understanding full context can cause you trouble in the future, so better spend some time now and avoid it.
Explaining what Microservices are and how to approach building them might take a whole book or two, so I encourage you to start with just that Microservices by Sam Newmann.
I've recommended that book before, it's a very good intro to the subject. It answers your questions in the first chapters.
Upvotes: 3