Kotlin for backend services at Delivery Hero/Yemeksepeti Fintech
Delivery Hero has become a worldwide leader in the online food ordering business. The company serves millions of users, has operations in around 50 countries, and partners with more than 550,000 partner restaurants.
We use different technologies in our different services and projects in Delivery Hero and Yemeksepeti. As fintech teams, our infrastructure and services are working on the JVM infrastructure; since fintech services, backend stack and most libraries are Java-based in Delivery Hero/Yemeksepeti. Fintech services serve millions of customers in different countries every day and handle transactions on a very large scale. The development adventure is started with java from the JVM ecosystem. Most worldwide developers are thinking that Kotlin is the only Android development language. With our backend team’s foresight, Kotlin can also be used in backend services and this idea became true.
Kotlin has started to be given priority in all newly developed and renewed services, mainly by taking advantage of the power of features such as coroutines and Kotlin DSL, along with many great features of Kotlin. Nowadays, services are mainly developed with Kotlin. Especially if a new service is to be started and there is no other concern, Kotlin is the first choice. Kotlin has become one of the core technologies in a short time.
Java is still on the table and some of our legacy services are developed with java programing language. But our java services test parts are developed with Kotlin. Kotlin is a really good way to write tests; with its simplicity, readability, and success in mock/fake data generation.
Kotlin — For Server-side?
Kotlin is not only an Android development language. Contrary to popular belief, it is also a very powerful language for the server-side. As I mentioned before, for developers who are developing services with JVM-based technologies; there are a few languages (except Java) such as scala, Clojure, Groovy and of course Kotlin.
Kotlin has been developed by incorporating the most popular features of other languages. Since it is a relatively new language; It does not contain legacy or deprecated APIs, outdated concepts, obsolete structures. Kotlin provides a future-proof development environment. Since it is compatible with the java libraries, easy to use for java dependent services. Especially being popular in Android has improved Kotlin itself and libraries.
Kotlin allows writing more concise code and comes with many useful features and libraries. The main reasons for choosing server-side Kotlin are: you have the ability to be much more compact in your code, its compactness, safety, and interoperability with Java (which allows you to use Kotlin in tandem with Java), many more features that make it a good choice for backend development. Here are some other key features that we like:
- Null-safety: It offers a NullpointerException-free development experience, which provides a more safe codebase.
- Data Classes: We often have to create and use classes that contain data. In Kotlin this is so easy that you can create a class with data keyword in one line containing getter, setter, equals, hashcode and toString.
- Extension functions provide to write extended code the functionality of existing classes without inheriting them.
- Functional programming: Kotlin supports functional programming with code that is short and highly readable.
- Asynchronous code and coroutines: Coroutines enables to write clean, simplified and readable asynchronous code that keeps the application responsive
- Java-interoperability: Easily integrates into existing java apps and is interoperable with the Java language. Able to use Java libraries while you have Kotlin codebase. it is a powerful thing if you have familiar with the java libraries and java really has a huge library ecosystem.
- Concise and readable: Kotlin improves the conciseness and readability codebase with data classes, null-safety, default and named arguments, operators, extensions, coroutines, and more…
Easy Adaptation
Kotlin is an easy-to-learn language (especially for java developers) that is easy to adapt. Kotlin contains many features that are desired/in demand by developers and its concise syntax makes it easy to write code. Kotlin has an attraction for java developers while hiring.
Spring Kotlin and Ktor
Framework support is very important for the server-side development usage of a language. Spring is the most popular framework on the Java side and it is supporting Kotlin powerfully, and spring initializer offers Kotlin directly as an option even documentation includes Kotlin examples. Spring Boot with Kotlin does a great job, and we use this duo extensively in our projects.
On the other hand, Ktor is a great option. Ktor is a Kotlin framework that allows building asynchronous client and servers web applications and It provides a coroutine-based API. We began experimenting with Ktor on server-side development.
Kotlin Coroutines
Coroutines are basically “lightweight threads” that work concurrently. They allow writing non-blocking asynchronous codes in an easier way with a readable and concise style. We like to use coroutines while developing asynchronous codes and it is managing concurrency easily.
Kotlin DSL
DSL provides to change the syntax of that specific part of the code. It is used for the specific part of the code to form it reusable and more understandable. With Kotlin DSL, you can create easy and useful structures, especially in structures such as rule engines. We are using the Kotlin DSL as the first choice when the DSL-based structures are required.
Test Code in Kotlin
Fintech systems are always needed to be bug-free products. For this reason, it is vital to write unit and integration tests.
Perhaps one of the most enjoyable parts of Kotlin is writing tests. Along with Kotlin data classes, it allows you to quickly create mock/fake data. Besides, you can write test names in sentences for example fun `i am a readable test`
. Kotlin provides default arguments and you can specify a default value for the parameters in function declarations. Kotlin supports the named arguments that you can specify the names of arguments that you’re passing to the function. This makes the function calls more readable. So it is making the test cycle easier with creating fake/mock data for different scenarios for each case.
We are using Kotlin in unit and integration tests even which are some of our projects are written in Java.
Summary
Delivery Hero and Yemeksepeti Fintech team use Kotlin for server-side development. Kotlin provides to write concise, readable and null safe features. One of the powerful things is the coroutines and writing tests in Kotlin. Kotlin is the first choice for the new project for JVM-based projects in Yemeksepeti/Delivery Hero fintech service developments.