An interface for publishing projects requires these operations:
- Check the status of this item to see if it can be published (only unpublished items can be published)
- Backend upload files (there may be many files, and currently a maximum of 10 concurrent uploads are allowed for one request) to the cloud service (object storage)
- After all files are successfully uploaded, change the project status to 'Published'
- Return the result, the front end ends the loading state and prompts the successful publishing How should this interface be designed? Because the overall process is time-consuming, there is a possibility of failure during the intermediate process of uploading files.
Let me first talk about my understanding:
- When checking the status of an item, add a pessimistic lock to prevent other requests from reading the status of this item
- During the upload process, if there is a failure, return a failure message and end the request
- If both are successful, the project status will be rewritten and unlocked, and other requests can continue