How to update the data in the database from one server micro-service to another?

Viewed 171

I have two microservices/modules on the backend:

  1. ugc
  2. utilities

ugc is the core microservice that contains all the data and has a database attached.

utilities is a separate tool that has no database of its own and takes care of the resource and time-intensive jobs like attaching watermark to video, extract thumbnail from video, etc.

For watermark video processing, we have a queue whose publisher end is at ugc module and the consumer end is at utilities to actually process the video.

Now, whenever a user uploads a video, an API is hit in the ugc module from the client side and it stores details in DB and pushes the video to queue to produce watermarked video.

Now, the utilities module picks each item from the queue and processes it, and once done, we need to store the updated video URL in the ugc database. Now to update the database from the utilities module, we have two options:

  1. Make an API in the ugc module to receive the watermark video URL and hit it from the utilities
  2. Connect ugc DB in utilities module using DB creds and update the model object directly using object id.

What do you think is the right way?

Is the first option an over-engineering step?

1 Answers

With option 1, it seem like you want keep your database access inside ugc. It's not a problem, but what if you create another service that needs a database? What would you like to do?

If you want to keep db access inside a service, then I think it is better to create an exclusive service for this purpose and make every other access to the db through it.

It is less flexible in terms of querying the database, because you will have to create an endpoint for each new query. And now you have to keep two things up, the database and the database service.

With option 2, you have to have a way to distribute your credentials to all your services. You probably want one user for each service and set permissions accordingly.

I don't think there is a right way, just preferences and, personally, I prefer option 2 just because it is simpler to set up and maintain.

Related