Hi, I want to discuss the idea about using kotlin ...
# server
r
Hi, I want to discuss the idea about using kotlin coroutines and flow with spring boot to build (photo sharing) sociall platform. Will reactive spring boot make API to handle load more effectively than traditional rest api? Any other benifits? Please share your thoughts
c
Depends on use case. Raw response time will not improve (likely degrade) and code complexity will increase. However, making use of non-blocking IO and netty will allow you to vertically scale each instance of the application as it will no longer bind each request to a separate thread. In IO heavy workloads with really high traffic, it is a good fit.
👍 2
r
So, for MVP, transitional rest api should be good to start. Correct?
a
yes
If you are under 1k request per second - anything will work - its only when you hit certain limits async will help
your question is similar to asking what is the best programming language - the answer is it depends on your use case
r
Thanks for info. However, I would rather say my question is about asking clear advantages of reactive spring boot, not about what is best. Plus I think coroutines are less complex than thread based async tasks.
c
I think you’re mixing things up with that statement. Spring Webflux uses netty under the hood, but in terms of the APIs they are very similar. The traditional annotated controller still exists, but I suppose you can now make use of the functional declaration of routes. While I wouldn’t sing the praises of RestTemplate, the WebClient isn’t particularly nice to test. Also without kotlin, you’re dealing with reactive types everywhere that you use the client. Now if your goal is to simply say execute multiple tasks at once, then yes you might like a coroutine based async solution to say the CompletableFuture API. Although, there’s not a huge difference in complexity there. One thing I will say about coroutines is they do a nice job of unwrapping reactive types so that you can more or less write imperative code if you’re happy with having a “colored” API. I personally like working with Spring Webflux and I found coroutines make things much easier. However, I would say for most use cases it is unnecessary and pushing for its use in a team without the requisite familiarity is probably not the right thing to do. Also, there is no reason you can’t use coroutines in normal Spring Boot if a particular use case lines up. I have used them to parallelise calls to downstream microservices for example.
r
Thanks for detailed answer. I've seen a video from JSpring where presenter showed how powerful reactive programming is useful when there's high concurrent load. Also with suspend function, we don't need wrapper for data types. So all in all, coroutines based spring boot api will be great for me considering medium to high load.