Jacky26 / quarkus-interview-practice

Practice
0 stars 0 forks source link

What's the impact of having filePath as a parameter #2

Closed orangepaydev closed 11 months ago

orangepaydev commented 11 months ago

https://github.com/Jacky26/quarkus-interview-practice/blob/add1828e78ebd7695d2dbad8db75b245da747673/src/main/java/org/jc/controller/DataController.java#L37

If this is hosted inside a docker container and deployed to a Kubernetes, what's the implication if the service just passes the File Path?

Jacky26 commented 11 months ago

I don't have much experience on dockering the project, but from what I understand for docker, docker container runs in its own file system. The file path provided might not exist within container's file system. Including the file in docker image during build process can be the way to ensure the file in present when container is deployed.

But I have to admit, passing file path as param is not a good practice at all, especially coming to design an API like this. This is because file path is inconsistent and different for everyone on their local. Passing in file path will cause file not found issue and these exceptions has to be handled well especially in a distributed environment like Kubernetes.

Let's assume that this file has the data that is important and has to be loaded, we should load the file from a configurable location like using environment variables to specify the file path and then load the data. By doing this, we don't have to rely on the file path. But the prerequisite is to make sure the file has to be available in either project repository or docker container. Moreover, security might be a vital aspect to look into if API or service layer accepting file path as parameter.

Hence, instead of using file and passing file path through API and services, setting up and connect to a database should be the way to store and process the data.

orangepaydev commented 11 months ago

yes... so that's correct. You can say if the file is large then instead of a API, it should use a batch system (e.g. file upload to S3 / FTP instead).

In this case, the API should receive the content of the file body itself and have a means to restrict the HTTP body (I think quarkus has that configured in the application.properties)