https://kotlinlang.org logo
Title
l

Lena Stepanova

06/16/2021, 9:45 AM
Hello everyone! An Android developer with very little backend experience, I am interested to learn more of it. Kotlin seems to be getting more popular for backend development and to pair very well with KMP projects. Therefore I have several questions, mostly about how and where to start: 1. Is it reasonable/worth it to start learning Backend development with Kotlin? Or should I rather choose Java frameworks as they are more mature? Having lots to do with KMM not sure how happy I'll be learning backend from start in "experimental" mode 2. Which framework is good to choose for a beginner? Kotlin Spring probably benefits from the maturity of Java Spring, whereas I have seen and heard more about Ktor implementations. Also using Ktor in the client side in KMM may be a good addition to learning backend with Ktor. Or would you recommend a completely different option? 3. Any tutorials/starter projects/guides/learning kits you can recommend? 4. Speaking of completely different options, may be there is something different from Kotlin options you'd recommend? I've heard good things about Go backend developments - good for beginners. This being a kotlinglang slack, I totally understand the answers may be biased, still will appreciate any opinion and advise!
h

Holger Steinhauer [Mod]

06/16/2021, 9:55 AM
Hi. Good questions. 1. Absolutely. Kotlin is a splendid language and why learn Java or Go if you can have it all in one language? I do all my projects, whenever possible, in Kotlin nowadays. 2. Depends on your use cases. If you start completely from scratch and usually have the option to chose, go with Ktor. Spring, on the other hand, could open more doors if you are looking to switch more torwards the backend development side of things. Ktor has the huge benefit of being much smaller and easier to learn. Spring on the other hand is a full-blown and nowadays good-ish modularised one-tool-for-everything. 3. Go with the tutorials the projects provide. They get you up and running.Then, check back here with question on details (and check the internet as you will find loads of help on there as well). 4. It highly depends on what you are trying to achieve and what your background and time is. Go is nice and yet, a complete different language. Rust is also something that gains lots of traction nowadays. But then, you already know your Kotlin. So it is very likely easier to pick up a new framework or two compared to learn a new language AND frameworks. #justMy2Cts 😉
h

hfhbd

06/16/2021, 9:55 AM
The biggest advantage using a Kotlin based web server is code sharing. You can create a gradle module containing your DTO classes and your API interface, so you can share this with your server (and Kotlin based frontend). With KMM, you can move your business logic of your android/iOS apps into a common module, to reuse this and implement only the UI using platform specific code in the android app/iOS app. Spring is a "old" but good framework with a great community and lots of tutorials/libraries (eg database support), but it uses many Java specific implementations and reflections. Ktor is a relative new framework, using Kotlin Coroutines under the hood, but lacks widely/"stable" external libraries. One good starting point is https://github.com/joreilly/PeopleInSpace or my technical playground app https://github.com/hfhbd/ComposeTodo
👍 1
k

kenkyee

06/16/2021, 10:16 AM
Spring is the most popular framework... So if you want to do this professionally.. KTor has missing stuff if you watch the #ktor chat...e.g. JWT support IIRC. But it's useful for KMP. There are also nice frameworks like Quarkus and Micronaut that are in between (dev mode in Quarkus 2.0 is amazing) Golang is ridiculously fast (dev and run) but the language is a bit primitive so it's easy for the compiler to optimize. A few things need a different mindset ..e.g. no inheritance. It's very popular as well in companies.
j

jaguililla

06/16/2021, 12:22 PM
My take on those questions is: 1. Go with Kotlin, major Java Frameworks/Toolkits are already supporting it (Spring, Micronaut, Quarkus and Vert.x). 2. Regarding the tooling: * Spring is the most supported one (yet bulky and slow). * Micronaut feels like Spring but less supported although it performs better. * Vert.x is a toolkit (not a framework) that gives you more freedom (and the best performance) but offers you less features out of the box. * Ktor is the Jetbrains toolkit (and thus it will be the better integrated with Kotlin: coroutines, etc.). I find it a bit un-intuitive at some points, but this is a sure bet. * Hexagon Toolkit (hexagonkt.com) is a toolkit developed directly in Kotlin and focused on simplicity in the spirit of Express.js. I would pick this one, but I'm I little biased as I'm a maintainer. 3. All discussed tools have a Kotlin section at their Web sites. 4. Go is a correct language, but you'll going to miss generics (among other things). An alternative platform would be Rust (take a look at Gotham and Nickel). If you consider these languages for performance bear in mind that GraalVM could be a suitable alternative to learn a new language platform. Hope this shed a bit of light and help you sort and filter some options available out there . Good luck!
h

Holger Steinhauer [Mod]

06/16/2021, 12:27 PM
Regarding the speed on Spring: It ain’t as bad as everyone tries to tell the world. Shameless plug, I did a talk about it: https://fosdem.org/2021/schedule/event/this_spring_shall_be_challenged/
j

jaguililla

06/16/2021, 12:54 PM
Thanks for the comparison... For performance numbers this project could also be helpful: https://www.techempower.com/benchmarks
👍 2
c

CLOVIS

06/16/2021, 4:57 PM
Others have said most of it, but as an addition, here's an example project that has a Kotlin/JVM backend (Ktor), and a Kotlin/JS frontend (React) https://gitlab.com/clovis-ai/formulaide It uses code sharing for all data structures in the API (eg. for validation) so the web-based UI can validate input with the exact same code as the backend. When they say ‘Kotlin Multiplatform is in Alpha' that more or less means the gradle config is in alpha. The language itself (expect actual) is very unlikely to change (or if it does, you can expect very good migration guides because everyone is using those. The most likely thing to break is an update to the gradle plugins that requires a different configuration—but that's not going to kill your project nor require much effort to migrate. The example I gave only has a Kotlin/JS frontend, but it would be trivial to add JVM and native support for all parts (the only exception is the UI, there are currently no good multiplatform UI libraries, but JetBrains Compose is on the way to fill that role one day)—that means that with a few lines of gradle & CI config, essentially a few hours of work at the maximum, I can have all the business logic, validation, data structures, etc in any other platform.
If you try to do something like that, don't hesitate to ask around in #multiplatform, the Gradle config can be a bit daunting to get a feel for, but I honestly think it's worth it for the power it gives you
y

Yev Kanivets

06/17/2021, 4:55 AM
Hi @Lena Stepanova I agree with all answers in this thread - Kotlin is a good (if not perfect) fit for the backend development. Ktor is a default starter option. I’ve written my experience of Ktor/Kotlin with mobile background in this article (https://medium.com/xorum-io/backend-for-mobile-engineers-with-kotlin-and-ktor-7981372a9462) and pitched a starter project in this talk (https://www.droidcon.com/media-detail?video=530298873).
c

Christoph Beylage

06/18/2021, 12:08 PM
regarding question 2: the biggest part of our backend runs with http4k. This is a pretty lightweight framework which works perfectly in the core. If you want to go beyond the basic core functions than you have to integrate other libraries. http4k for example does not have an integrated ORM or something similar. Pro: You can use whatever fits your case the most. Contra: Maybe you have to find libraries that work together well. We also used other frameworks before in Java like dropwizard or spring. The good part about them is that those frameworks had plenty of functions that worked perfectly together. The bad part was they had plenty of functions we didn’t need and sometimes the core functionality did not fit our case perfectly and it was hart to make them fit. So we went to more lightweight approaches. In kotlin this is http4k. And on top of that we build something like a service framework on top which has everything included that fits to our case in a way that every service can use. for exmaple we integrated jetbrains exposed for database connection there in a way that works perfectly for every single service. we integrated handlebars there so every service has the possibility to render webpages. and between our service framework and the actual service there is a pretty generic api inside our framework that every service uses. but we still have the possibility to, for example, change kotlin exposed to something else without major effort in every service. The video above your post is a pretty decent overview of http4k. regarding question 1: we switched most of our java code to kotlin. and it works perfectly!
l

Lena Stepanova

06/27/2021, 12:46 PM
Thank you everyone for your opinions and recommendations!