ElChache / log-collection

API that fetches logs from files
0 stars 0 forks source link

remove dependency on apache-commons #1

Open ckulkarni-cribl opened 1 year ago

ckulkarni-cribl commented 1 year ago

Hi David,

Thank you for submitting the code, as exercise recommends to keep the dependencies to a minimum would it be possible to remove usages of apache commons?

ElChache commented 1 year ago

Hi there! I did try to keep the dependencies to the minimum - the included libraries like compojure and ring are very standard on Clojure, and actually there is no way to set up a server without including some libraries, as there is no server included in the Clojure core files.

The Apache Commons dependency is used in order to be able to use the ReversedLinesFileReader, which is used to read files starting from the end instead of from the beginning. As far as I know, there is no reversed file stream reader included in the main Java library.

This dependency could be removed and replaced with my own implementation of a ReversedLinesFileReader, but this woudn't be an easy task and I wouldn't have been able to finish the exercise on the recommended time. But I think in a real situation I would prefer to include this battle-tested dependency rather than my own.

The reverse reader it's necessary because the application should be able to handle big log files gracefully, I didn't want to have to read the whole file, put it in memory and then reverse it, as this would be slow, use a lot of memory, and wouldn't scale properly.

I couldn't think of a solution with good performance that doesn't involve a reverse reader.