A
A
alexg-nn2019-11-05 18:51:58
PHP
alexg-nn, 2019-11-05 18:51:58

What is the best way to organize an image processing microservice?

Good afternoon!
There is a set of several services, say A, B, C, each of which does not use pictures in their own business logic, but they are used there for illustrative purposes. A vivid example of this is the user's avatar in the service responsible for the user profile. All three services are supposed to have an API for working with them. In addition, each service imposes its own restrictions on the required image sizes.
From the point of view of the client of these services, the most convenient way to upload an image would be like

POST /resourceA(B,C)/id/images
Content-Type: image/jpeg

...

However, this means adding logic for working with images for each service. If the number of such services grows, the solution does not seem to be very good.
Instead, there is an option to make some local "photo hosting" service D, which will process images. Access is also through the API. However, the question arises how to organize the download flow in this case. If in the first option, the validation of images took place at the place of loading, now it is necessary to transfer information about valid formats + data on the creation of derivative images to service D.
I spied this option on Vimeo:
1) The client sends POST /resourceA/id/images
2) Service A, in turn, sends a POST request to service D with the requirements to generate a link to download an image of the required format and additional data to generate other images.
3) Service D returns a response to service A with a JWT token and a link to download the image.
4) Service A returns the same to the client.
5) The client makes a PUT request with a picture to the returned link.
Then there are two options
1) After the download is completed, service D throws the event "loaded so-and-so" and service A extracts data from this event.
2) The client makes another PUT request to the created resource /resourceA/id/images/image_id with data received from D.
In principle, I saw a similar scheme in the VKontakte and YouTube APIs.
The question arises more about this. What to do if there is only one resource for the image.
For example, service B has a resource /resourceB/id/ image . How to build a download flow for this single image through service D? How to get generated download link from it? It seems wrong to make a POST request to this resource if it already exists.
For the same Vimeo, this is solved in such a way that there are still a lot of resources (POST /users/123/pictures), just after loading, the only "active" one is selected by a separate request (PUT /users/123/pictures/123 {"active": true }).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
grinat, 2019-11-06
@grinat

What for? A bunch of ready -made eg https://github.com/thoas/picfit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question