I am writing a web application with Python and Flask. At a high-level, the web service takes an ID, downloads a file from a third-party API based on that ID, reads and analyzes the data inside the file, and finally returns that analysis to the client.
Here is the request-response workflow I have in mind:
- 1a. The front-end makes a request with an ID to a "download" endpoint and then notifies the client that the file is being downloaded.
- 1b. The server downloads the file and responds to the front-end with the downloaded filename. When this is successful...
- 2a. The front-end makes a request with the filename from step 1 and some additional configuration values--set when the user initially clicks "submit"--to an "analyze" endpoint and then notifies the client that the file is being analyzed.
- 2b. The server analyzes the file based on the client's configuration and generates an output file with the analysis. The server then responds with the output filename.
- 3a. The front-end then makes a request to the "output" endpoint with the output filename from step 2 and notifies the client that the output file is being downloaded locally.
- 3b. The server simply returns the static file on request. The server then deletes the output file.
Broadly, my question is: does this architecture work? More specifically:
- Is there a better way to show progress to the client? This seems like a lot of overhead for that functionality--on the other hand, it's nice to have cleaner API endpoints.
- What happens when client A and client B request the same data back-to-back? Client B's server-side process might respond that the output file is ready right before client A's process delete the file. Is there a way to avoid this scenario?
I realize this is a bit messy, but I am pretty new to back-end development and am very open to any suggestions.
Thanks in advance.