1

I'm learning micro services architecture for NodeJs, as much i know about micro services is mentioned below:

  • ms architecture have different types of services.
  • each service will have it's own DB.
  • each service will contain full NodeJs project.
  • each service will communicate through calling API endpoints of each others.
  • each service should be able to deploy independently.

If anything is wrong or i missed up so please let me know.

My main question is like if we have 2 services, one is video service and another one is user service. Video service has model Videos and User service has model Users. Videos model will have a userId of the user who uploaded it. Now i want create an API which will return all the videos, each video object will have a sub object of user (who uploaded it) in behalf of that userId like given sample code. but now both Videos and Users model are exist on different databases, so how i can achieve this?

videosList: [
    { id: 1, name: "Video 1", userId: 11, userObj: {...} },
    { id: 2, name: "Video 2", userId: 20, userObj: {...} },
    { id: 3, name: "Video 3", userId: 15, userObj: {...} },
    ...
]
Harsh Lodhi
  • 159
  • 4
  • 11
  • You have to write services for inter communication between your microservices, like in video service you have to call user miccroservice for fetching user information.. – turivishal Jun 03 '20 at 18:28
  • 1
    Read this full conversation [https://stackoverflow.com/questions/30213456/transactions-across-rest-microservices](https://stackoverflow.com/questions/30213456/transactions-across-rest-microservices) – turivishal Jun 03 '20 at 18:33
  • @turivishal b=how i can append a user sub object to the video object? because both DBs are different. – Harsh Lodhi Jun 04 '20 at 03:52
  • hey @HarshLodhi, for what reason you have to put user object in video object? just put user reference id in video list and you have to call user microservice for user object on the base of user reference id. – turivishal Jun 04 '20 at 04:47
  • 1
    Microservices main concept is your microservices will communicate internally if you want but not DBs, You can exchange data through microservices not directly from DBs. – turivishal Jun 04 '20 at 04:51
  • Thanks @turivishal, i want to show the list of videos in my front end where it require to show the name of user who uploaded it. if i try to to fetch each individual userId then it gonna increase the time complexity over the time. – Harsh Lodhi Jun 04 '20 at 05:01
  • To reduce time complexity you have to setup proper server architecture, you can use `docker` or other methods. I am also working on this part and will share proper architecture with explanation, will keep updating you. – turivishal Jun 04 '20 at 05:29
  • @turivishal can we create one or more db-services? which will communicate to DB and our services will communicate to these db-services to perform task on db. – Harsh Lodhi Jun 04 '20 at 06:01
  • 1
    Yes we can make as much as needed.. – turivishal Jun 04 '20 at 06:07

0 Answers0