Monday 25 December 2017

Am I understanding how to handle data in microservices correctly?

I'm trying to understand how to implement microservices.I read this: http://ift.tt/2l9ChxP well as many other articles. It seems like the idea is you should separate concerns, and each microservice should have its own API and database. Also, microservice A cannot access microservice B's database directly, but has to do so through B's API.With that in mind, I came up with this:Accounts microservice with its own db - used for logins id(pk) | email | password Identity microservice with its own db - displayed in profiles user_id(pk, fk) | username | first_name | last_name Billing microservice with its own API/db - deals with payments user_id(pk, fk) | customer_id Where I'm unsure is what happens when a user registers? Assume we're not dealing with Billing here.It sounds like you have to create a row in both the Accounts microservice/db AND in the the Identity microservice/db?So:async signup(email, username, password, first_name, last_name) { // Accounts API -> insert email, password into Accounts db and return new user_id // Identity API -> insert new user_id, username, first_name, last_name into Identity db } async getProfile() { // Identity API -> get current user's username, first_name, last_name by user_id from Identity db } What happens if one these happens to fail during signup e.g. Identity? In that case, say if that user tries to login -> fetch their profile next time, they don’t have one (because it's missing from Identity)? Then you have a user account with no profile/identity attached to it. What should happen then to make sure things are still working/repair themselves? I mean I guess this could happen in a monolith too with one database, but probably less likely.Am I thinking about microservices correctly? How would you deal with all of these possible database integrity issues?

Submitted December 26, 2017 at 01:19AM by roachgirl11

No comments:

Post a Comment