r/Clojure • u/clojureftw • May 16 '16
Ask /r/Clojure: Secure web frameworks for building REST Api?
I'm evaluating Pedestal and I guess I like it's built-in security features although I'm not sure whether this is just a fluff piece of somebody has actually done a thorough auditing.
I'm working in fintech space and since I'm using datomic I'm pondering what my backend endpoint api stack is going to be. I like the appeal of keeping everything clojure to save the cognitive cost of switching between backend server / datomic, and all in all I've gone through the clojure essentials yesterday and was just blown away by it's concise and straight forwardness, no ambiguity, and see it as a powerful language for dealing with lot of data, and more importantly it feels like the first time I began learning programming, but I digress, I'm turning to the community to get some advice preferably from people who work in fintech.
So should I use Pedestal + Datomic?
I'm sort of wary about using "collection of libraries" that people seem to advocate, and this arises from my experience of using "microframeworks" like Flask in the Python world and ending up googling "how to get stuff I got for free in full MVC frameworks but in Flask + 3rd party libraries that seem sporadically updated by individuals". It left a very bad taste and I've made some pre-judgement here coming to clojure....
However, if I could attain a better security feature by employing the "collection of libraries from the shelf" to build backend API, I might consider it seeing how tight the community is and not flaky like Flask....but again if Pedestal or some full framework on clojure lets me achieve higher productivity and security features then I'd much much prefer the full framework approach.
Anyways I'm going through the more advanced topics on clojure and will come back time to time to check on people's replies.
Thanks y'all.
3
u/ohpauleez May 20 '16
Your point about thread pools is well heard, but it's leaving out a lot of subtle and important details. It's common to create thread pools based upon workload and resource utilization - a thread pool for accepting connections, a worker thread pool, a thread pool for I/O bound tasks, and so on. In the Ring model, you're forced to synchronously process your task, always holding a thread in the initial pool that you start in (regardless if you start tasks on the other thread pools).
In the interceptor model, your request can migrate across thread pools, freeing up the thread in one pool, while you occupy/use a thread in another pool. What's more, when your response is bigger than the HTTP buffer, your Ring handler must occupy a critical server thread until the client finishes consuming all of the data, often 100ms-1000ms worth of idle time. With NIO-based responses, you can free that thread and have the Container signal you when it's ready to send more data.
In Pedestal, that's as simple as returning a core.async channel, ByteBuffer, or ReadableByteChannel as your response body from your handler function.