I got an assignment for which I have to build a API (I use FastAPI) that accepts POST Requests to store raw data in a Mongo database. This data should then be transformed and stored in a different table. The assignment says, it "would be nice" if the API and the transformation are separated (they propose some messaging service between the 2 components, but I have no idea what that is). I did some research and came across the Subprocess functionality of Python, but before I go on with that, I would like to clarify if my assumptions are actually correct. Is it possible to execute a subprocess.run from within the API code, passing the body of the POST request as an argument to the transformation script? If yes, how would be the general Syntax? If there is a better way of doing what I want to do, I am open to anything. Right now, the transformation takes the raw data from the Mongo collection, but I dont know how to trigger the execution of the transform script everytime new raw data is stored to the database.
Thanks a lot in advance!