Auto Added by WPeMatico

JetBrains Toolbox 사례 연구: 100만 사용자를 Kotlin 및 Compose Multiplatform으로 이동

JetBrains의 Toolbox 팀 리더인 Victor Kropp이 데스크톱에서 Kotlin과 Compose Multiplatform을 사용하게 된 사연을 전해 드립니다.

JetBrains Toolbox App은 JetBrains IDE를 사용하여 개발 작업을 수행하기 위한 단일 진입점으로, 도구 및 프로젝트를 위한 제어판 역할을 하며 JetBrains IDE를 빠르고 쉽게 설치 및 업데이트할 수 있게 해줍니다. 2015년 해커톤 프로젝트에서 시작된 이 애플리케이션은 현재 월 100만 명의 실 사용자에게 서비스를 제공하여 JetBrains 제품과 함께 작업 생산성을 높이는 데 도움을 주고 있습니다.

Toolbox 팀이 이 애플리케이션을 C++ 및 JavaScript에서 Kotlin 및 Compose Multiplatform으로 완벽하게 마이그레이션한 후, 코드 작업과 관리를 더 간편하게 수행하고 아티팩트 크기를 줄여 런타임 성능을 개선할 수 있었다는 이야기를 읽어보세요.

JetBrains의 Toolbox 팀을 이끄는 Victor Kropp로부터 직접 들으려면 Talking Kotlin #107을 확인하세요.

Victor씨, JetBrains Toolbox에서 사용하는 아키텍처와 기술 스택을 소개해줄 수 있나요?

Toolbox App은 일반적인 클라이언트-서버 애플리케이션입니다. 이 데스크톱 앱은 서버에서 사용 가능한 도구 목록을 요청하여 사용자에게 보여주고 필요할 경우 JetBrains 제품 업데이트를 다운로드합니다. 애플리케이션의 서버 측 부분은 처음부터 Kotlin으로 구현했습니다. 그러나 데스크톱 애플리케이션은 달랐습니다.

2015년에 JetBrains Toolbox용 데스크톱 앱을 빌드하기 시작했을 때 C++를 사용하여 비즈니스 로직을 구현하고 React 및 HTML/CSS/JS와 함께 Chromium Embedded Framework를 사용하여 사용자 인터페이스를 빌드했습니다. 이러한 선택을 할 당시에는 Kotlin 1.0이 아직 출시되지 않았고 Java 9와 함께 제공된 모듈식 JDK도 없었습니다. 고작 작은 도우미 애플리케이션을 위해 수백 메가바이트의 JRE(Java Runtime Environment)를 번들로 제공할 여유도 없었고 사용자들에게 환경을 수동으로 설정해야 하는 번거로움을 안겨주고 싶지도 않았습니다. 그래서 완전히 다른 접근방식을 선택해야 했죠.

2021년에 이르러 사용자 인터페이스를 React에서 Compose Multiplatform, 더 구체적으로는 Compose for Desktop으로 마이그레이션하여 이 데스크톱 애플리케이션을 100% Kotlin으로 만드는 마지막 단계를 완료했습니다.

Compose for Desktop 웹사이트 방문하기

해당 제품에서 Kotlin과 라이브러리를 어떻게 사용하시나요?

Kotlin으로 마이그레이션을 완료하면서 모든 곳에서 사용하고 있습니다. 사용자 인터페이스를 지원하는 Compose for Desktop 외에도 모든 비동기 작업에 kotlinx.coroutines를 정말 많이 사용합니다. Toolbox App은 수많은 JSON 객체를 처리하므로 이에 따라 저희도 kotlinx.serialization을 (역)직렬화에 사용합니다.

서버 측은 최대한 단순하게 유지됩니다. 사실 여러분이 생각하시는 것과는 달리 이것은 HTTP 서버가 아닙니다. 설치 가능한 도구에 대한 모든 정보와 설명(Toolbox에서는 ‘피드’라고 함)은 정적으로 생성되며 CDN에서 JSON 파일로 제공됩니다. 피드가 자주 변경되지는 않으므로 저희는 TeamCity에서 지속적 배포 파이프라인의 일부로 새 버전의 도구가 출시될 때만 이를 업데이트합니다. 제너레이터는 지원되는 각 제품이 빌드될 때마다 자동으로 트리거되는 ‘빌드 구성'(작업을 나타내는 TeamCity 명칭)으로 호출되는 간단한 명령줄 Kotlin 프로그램입니다. 두 번째 작업에서는 새로 생성된 모든 피드를 주기적으로 병합하고 오래된 피드를 폐기하고 유효성 검사를 수행합니다.

Toolbox 팀이 데스크톱용 애플리케이션 개발에 Kotlin을 사용하기로 결정한 이유는 무엇인가요?

Compose for Desktop으로 이전하기 전에는 Chromium Embedded Framework를 사용하여 Toolbox App용 사용자 인터페이스를 빌드했고 비즈니스 로직에 기본 C++를 사용하여 모든 주요 데스크톱 운영 체제를 쉽게 지원할 수 있었습니다. (그 후로 많은 것이 바뀌었고 2020년에는 모든 C++ 비즈니스 로직을 JVM에서 실행되는 Kotlin으로 옮기기로 결정했습니다.)

2015년 당시에는 프로젝트를 시작하는 데 좋은 선택이었습니다. JetBrains에서 빌드한 웹 UI 구성 요소 라이브러리인 Ring UI의 구성 요소를 재사용할 수 있었습니다. 또한 저희는 웹 개발과 React 작업에 이미 많은 경험을 가지고 있었습니다.

그러나 단점도 없지 않았습니다.

  • Chromium Embedded Framework는 리소스 소비가 많은 것으로 잘 알려져 있습니다. 유휴 상태일 때도 JetBrains Toolbox는 최소 200MiB의 RAM을 사용하곤 했습니다. 또한 창이 보이지 않을 때 전체 프레임워크를 언로드할 수 없었습니다. 사용자가 앱과 상호 작용하려고 할 때 몇 초 정도 지연이 발생하기 때문입니다.
  • 저희에게는 단일 데스크톱 애플리케이션 내부에 완전한 클라이언트-서버 아키텍처가 필요했습니다. 임베디드 웹 UI와 비즈니스 로직은 서로 다른 언어로 서로 다른 사람에 의해 작성되었습니다. 이로 인해 개발 프로세스가 복잡해졌고 애플리케이션 내에서 수 메가바이트의 JSON을 주고 받기 위한 리소스가 필요했으며 이미 가지고 있던 데이터의 (역)직렬화에 CPU 리소스가 소진되었습니다.

이러한 상황은 애플리케이션을 100% Kotlin으로 이전한 후 크게 개선되었습니다.

  • Compose for Desktop은 리소스를 훨씬 적게 사용합니다. Compose 프레임워크는 JavaScript 구현에 비해 더 나은 런타임 성능을 제공하며 백그라운드에서 유휴 상태로 실행될 때 앱에서 사용하는 RAM을 크게 줄일 수 있었습니다.
  • 단일 언어를 사용한다는 것은 모든 개발자가 컨텍스트를 전환하지 않고 처음부터 끝까지 기능을 개발할 수 있음을 의미합니다. 더 빠르고 실수도 적게 발생하며 개발자 간에 원활한 지식 공유가 가능합니다. 또한 전체 애플리케이션이 메모리의 데이터에 대해 동일한 표현을 사용하므로 추가 (역)직렬화 단계가 필요하지 않습니다.

Toolbox에 Kotlin을 도입한 경험에 대해 말씀해 주시겠어요?

저희 앞에는 해결해야 할 많은 과제가 있었습니다. 우선, 만들어진 지 5년이 된 코드베이스를 모든 기능과 문제점을 포함한 상태로 다른 스택으로 마이그레이션해야 했습니다. 애플리케이션의 핵심 요소가 의도대로 작동하도록 모든 유닛 테스트를 마이그레이션했습니다. 그러나 저희 애플리케이션에는 에코시스템마다 확연히 다른 외부 종속 요소가 많이 필요합니다. 어떤 부분은 이전 구현에서 작동하지 않다가 새 구현에서는 작동하기 시작했습니다. 저희가 아무 조치도 취하지 않았는데도 말이죠. 이유는 단순히 새로운 종속 요소가 이를 지원했기 때문입니다. 그러나 당연히 작동하리라 여겼던 다른 것들은 더 이상 작동하지 않았습니다. 공개 릴리스가 출시된 후에도 이러한 차이점을 파악하지 못한 경우도 있었습니다. 두 범주의 사례는 시스템 트레이(메뉴 모음) 아이콘 또는 프록시 서버 및 SSL 인증서와 같은 운영 체제 통합의 다양한 측면들입니다. 다른 한편으로, Toolbox의 ‘Projects‘(프로젝트) 탭에서 IntelliJ IDEA의 프로젝트 검색을 지원하는 코드를 재사용하거나 특정 엔터프라이즈 설정을 탐지하는 것과 같이 JetBrains의 다른 팀이 작성한 Kotlin 코드를 재사용할 수도 있습니다.

저희는 Compose for Desktop를 공식 발표 전부터 사용하기 시작했기 때문에 프레임워크에서 발생하는 문제를 가장 먼저 접하는 경우가 많았습니다. Compose for Desktop의 최초 사용자로서, 저희는 사용 시작과 동시에 모든 종류의 문제를 확인하고 Compose Multiplatform 팀의 동료에게 모든 문제를 보고했습니다. 그들은 많은 도움을 주었고 빠르게 대응했으며 모든 문제를 매우 신속하게 수정했습니다. 심지어 같은 날 수정 사항이 포함된 새 릴리스를 받는 경우도 있었습니다. 매우 인상적이었죠! 또한 Compose를 채택할 때, 그리고 프레임워크에서 어려움을 겪고 있을 때도 많은 도움을 주었습니다.

저희는 이전 설계를 완벽하게 복제할 수 있었습니다. Compose는 언뜻 보기에 HTML/CSS에 비해 더 적은 기본 레이아웃 프리미티브를 제공하는 것 같지만 간단한 수평 및 수직 스택(Compose의 행 및 열)만으로 이미 모든 요구사항의 99%가 충족된다는 사실을 금세 알게 되었습니다. 처음 시작할 때 Compose for Desktop에는 SVG 그래픽 지원과 같은 일부 기능이 여전히 누락되어 있었으나 Compose 팀의 동료들이 고맙게도 이러한 부족한 부분을 매우 신속하게 해결해주었습니다.

처음에는 애플리케이션 전체에서 Compose의 Material 구성 요소를 사용했습니다. 이 구성 요소는 매우 다각적으로 고려하여 만들어졌지만 터치 인터페이스에 중점을 두고 있습니다. 이 때문에 모든 요소에 많은 여백이 있고(손가락으로 쉽게 누를 수 있도록), 마우스오버 상태가 없으며(터치 디스플레이에는 이러한 동작이 없으므로), 매우 눈에 띄는 시각적 터치 피드백이 제공됩니다. 데스크톱에서는 마우스를 가져가면 구성 요소가 반응하고 클릭에 대한 시각적 피드백이 현재 요소에만 영향을 미치는(손가락으로 가려지지 않으므로) 등 상황이 많이 다릅니다. 이 때문에 저희는 Material 구성 요소를 데스크톱에서 더 잘 작동하는 자체 구성 요소로 교체하고 있습니다. 또한 향후에는 구성 요소 라이브러리를 오픈 소스로 공개할 계획이 있으므로 계속 지켜봐 주시기 바랍니다.

Compose for Desktop을 선택하기 전에 다른 UI 프레임워크를 고려하셨나요?

한 가지 대안은 애플리케이션을 완전한 기본 인터페이스로 변환하는 것이었지만, 이렇게 했다면 기능마다 3배는 더 많은 노력이 필요했을 겁니다. 저희는 크로스 플랫폼인 동시에 보기에도 좋으며 Kotlin과 잘 작동하는 프레임워크를 원했습니다.

Swing은 너무 오래되었고 JavaFX는 사용 저변이 아직 부족하다고 느꼈습니다. 이것이 당시에 발표된 지 얼마 되지 않았음에도 불구하고 Compose for Desktop을 선택한 이유입니다. 해당 팀에게 직접적 지원을 받고 피드백이 순환적으로 긴밀하게 이루어진다는 점도 큰 이유를 차지했죠.

Kotlin이 해당 제품에 가져온 가장 큰 이점은 무엇인가요?

일상 작업이 훨씬 간편해졌습니다. 이제 전체 애플리케이션에서 동일한 언어를 사용하므로, 팀의 개발자들이 이전보다 코드와 지식을 더 잘 공유할 수 있게 되었습니다. 또한 C++ 및 JavaScript 대신 Kotlin으로 작성하면서 일하는 재미가 훨씬 커졌습니다!

저희 독자들에게 하고 싶은 조언이나 권장 사항이 있나요?

기존 애플리케이션을 새 프레임워크로 전환하려고 한다면 마이그레이션의 복잡성을 얕잡아보면 안 됩니다. 거의 처음부터 새로운 애플리케이션을 작성하는 것과 다르지 않습니다! 기능뿐만 아니라 의도적이든 아니든 앱 동작의 사소한 뉘앙스까지도 놓치지 않고 다시 구현해야 하거든요.

저는 Compose for Desktop이 2021년에 크로스 플랫폼 데스크톱 애플리케이션을 만드는 주된 방법이 될 것이라고 굳게 믿습니다. 유사한 기술과 비교할 때 Kotlin은 JVM에서 검증된 에코시스템에 대한 액세스를 제공하고 Dart 및 Flutter보다 채택률이 훨씬 높으며 React/JS를 사용하는 Electron보다 훨씬 효율적입니다.

Compose for Desktop으로 첫 데스크톱 앱 빌드하기

Victor Kropp은 JetBrains Toolbox App의 팀장입니다.

게시물 원문 작성자

Sebastian Aigner

Continue ReadingJetBrains Toolbox 사례 연구: 100만 사용자를 Kotlin 및 Compose Multiplatform으로 이동

JetBrains Toolbox Case Study: Moving 1M users to Kotlin & Compose Multiplatform

Victor Kropp, the Team Lead for the Toolbox team at JetBrains, shares the story of adopting Kotlin and Compose Multiplatform on desktop.

The JetBrains Toolbox App is the single entry point for developing using JetBrains IDEs. It serves as a control panel for tools and projects, and makes installing and updating JetBrains IDEs quick and easy. Originally started in 2015 as a hackathon project, the application now serves one million monthly active users, and helps them be more productive with their JetBrains products.

Read on to understand how the Toolbox team moved their application from C++ and JavaScript to 100% Kotlin and Compose Multiplatform, and ended up making their code easier to maintain and work with while shipping smaller artifacts with better runtime performance.

To hear the story directly from Victor Kropp, who leads the Toolbox team at JetBrains, check out Talking Kotlin #107:

Victor, can you introduce the architecture and tech stack used by JetBrains Toolbox?

The Toolbox App is a typical client-server application. The desktop app requests a list of available tools from the server, shows it to the user, and downloads updates for JetBrains products when required. We implemented the server-side part of our application in Kotlin from the very beginning. The desktop application, however, was a different story.

When we started building the desktop app for JetBrains Toolbox back in 2015, we used C++ to implement its business logic and used the Chromium Embedded Framework together with React and HTML/CSS/JS to build the user interface. We made this choice at a time when Kotlin 1.0 hadn’t been released yet – and neither was the modular JDK, which came with Java 9. We couldn’t afford bundling a Java Runtime Environment (JRE) weighing hundreds of megabytes for our small helper application, and we didn’t want to trouble our users with having to manually set up their environment. So, we chose a completely different approach.

In 2021, we completed the final step of making the desktop application 100% Kotlin by migrating the user interface from React to Compose Multiplatform, more specifically Compose for Desktop.

Visit the Compose for Desktop website

How do you use Kotlin and its libraries in your product?

With the migration to Kotlin completed, we use it everywhere. Besides Compose for Desktop powering the user interface, we make heavy use of kotlinx.coroutines for all asynchronous jobs. The Toolbox App manipulates a lot of JSON objects, so we naturally use kotlinx.serialization for (de)serialization.

The server side is kept as simple as possible. In fact, it isn’t an HTTP Server as you might imagine it. All of the information and descriptions for installable tools (called “feeds” in Toolbox) are generated statically and served as JSON files from the CDN. They don’t change often, so we update them only when a new version of any tool is released as part of the continuous delivery pipeline on TeamCity. The generator is a simple command line Kotlin program that is invoked as a “build configuration” (TeamCity’s name for a job), which is automatically triggered on each build of every supported product. A second job then periodically merges all newly generated feeds, discards the outdated ones, and performs validation.

Why did the Toolbox team decide to use Kotlin for Desktop application development?

Before moving to Compose for Desktop, we used the Chromium Embedded Framework to build the user interface for the Toolbox App, and using native C++ for our business logic helped us support all major desktop operating systems easily. (Since then, many things have changed, and we made the decision to move all C++ business logic to Kotlin running on the JVM in 2020.)

Back in 2015, those were great choices to kickstart the project! We were able to reuse components from Ring UI, a library of web UI components built by JetBrains. We also already had a lot of previous experience in web development and working with React.

However, it had its disadvantages:

  • The Chromium Embedded Framework is known for its resource consumption. Even when idle, JetBrains Toolbox would use at least 200 MiB of RAM. We also couldn’t unload the whole framework when the window was invisible, because it would result in a multi-second delay for our users when trying to interact with the app.
  • We needed a full-blown client-server architecture inside a single desktop application. The embedded web UI and the business logic were written in different languages and by different people. This complicated the development process and required the resources to send megabytes of JSON back and forth inside the application, using up CPU resources on the (de)serialization of data that was already there.

After moving our application to 100% Kotlin, that situation has improved significantly:

  • Compose for Desktop is now much less resource intensive. The Compose framework provides better runtime performance compared to our JavaScript implementation, and when running idly in the background, we managed to greatly reduce the RAM used by the app.
  • Using a single language means that every developer can make a feature from start to finish without switching contexts. It is faster, less error prone, and improves knowledge sharing among developers. The entire application also uses the same representation for data in memory, skipping the need for extra (de)serialization steps.

Can you share your experience of introducing Kotlin to your Toolbox?

We faced many challenges. First of all, we needed to migrate a five year-old codebase, with all its features and quirks, to a different stack. To ensure that the core of our application works as intended, we migrated all of our unit tests. However, our application requires a lot of external dependencies, which obviously vary in different ecosystems. Some things didn’t work in the previous implementation and started working in the new one without any action from our side, simply because the new dependency supported them. However, other things we took for granted stopped working. In some cases, we didn’t know about those differences until after a public release. Examples for both categories are the different aspects of operating system integration, like the system tray (menubar) icon, or proxy servers and SSL certificates. On the other hand, it also allowed us to reuse Kotlin code written by other teams at JetBrains, like reusing the code powering IntelliJ IDEA’s project search in the Toolbox’s “Projects” tab or detecting specific enterprise setups.

We started using Compose for Desktop before it was even publicly announced, so we were often the first to encounter any issues that arose with the framework. As pioneers of Compose for Desktop, we noted all sorts of problems when we started, and reported all of them to our colleagues in the Compose Multiplatform team. They were very helpful and responsive and fixed all of them very quickly. At times, we were able to get a new release with a fix on the same day – very impressive! They also greatly helped us with the adoption of Compose and in cases where we were struggling with the framework.

We were able to make a full clone of our previous design. At first glance, Compose offers fewer layout primitives compared to what we had in HTML/CSS, but it quickly became apparent that simple horizontal and vertical stacks (Row and Column in Compose) already covered 99% of all our needs. When we first started, Compose for Desktop was still missing some pieces, like support for SVG graphics, but our colleagues from the Compose team helped us cover these needs very quickly.

Initially, we used Compose’s Material components throughout the application. These are very well-thought-out components, but they focus on touch interfaces. This means that all elements have large paddings (so they can be easily pressed with a finger), don’t have hover states (given there is no such thing on touch displays), and have very prominent visual touch feedback. On desktop, the story is usually quite different, as components react when hovered over, and the visual feedback for clicks only affects the current element (because it is not covered by a finger). Because of that, we are replacing Material components with our own which work better on desktop. We also have plans to open-source our components library in the future, so stay tuned for that.

Did you consider any other UI frameworks before choosing Compose for Desktop?

One alternative would have been to convert the application to a fully native interface, but it would have required three times more effort per feature. We wanted something that would be cross-platform, look nice, and work well with Kotlin.

We felt that Swing was too old and the usage of JavaFX isn’t sufficiently widespread. That’s how we landed on Compose for Desktop, despite it just being announced at the time. Getting direct support from the team and a tight feedback loop also turned out to be a huge plus.

What are the biggest benefits that Kotlin has brought to your product?

Everyday work is just much simpler now. We use the same language across the entire application, meaning the developers on our team share code and knowledge better than before. We’re also having much more fun writing Kotlin instead of C++ and JavaScript!

Do you have any advice or recommendations for our readers?

If you are converting an existing application to a new framework, don’t underestimate the complexity of migration. It is almost like writing a new application from scratch and then some! You’ll inevitably need to re-implement not only the features, but also all of the little nuances in your app’s behavior, whether those are intentional or not.

I strongly believe that Compose for Desktop is the way to create cross-platform desktop applications in 2021. Compared to similar technologies, Kotlin provides access to a tried and tested ecosystem on the JVM, has much greater adoption than Dart and Flutter, and it is far more efficient than Electron with React/JS.

Build your first desktop app with Compose for Desktop

Victor Kropp is the Team Lead for the JetBrains Toolbox App.

Continue ReadingJetBrains Toolbox Case Study: Moving 1M users to Kotlin & Compose Multiplatform

Faire Сase Study: Kotlin Backend for a Disruptive SMB Marketplace

Like most startups, at the beginning of its journey Faire was looking for an efficient solution to base its tech stack on. Having started with Java, a year in, the company started looking for other options, and opted for Kotlin. They now use Kotlin for their Android app and for the website backend, which successfully handles up to 1K requests per second.

The current backend repo has 788,020 lines of code within 6,078 Kotlin files, with roughly 45 engineers actively committing code and more onboarding every week.

We chatted with Jeff Gulbronson, a software engineer who has been with Faire since it was a year old, about Faire and why it chose Kotlin. The key benefits of Kotlin he identified were:

  • Kotlin improves developers’ productivity thanks to its modern language features, and helps avoid common Java mistakes.
  • Interop with Java makes it easy to use existing Java libraries.
  • Easy to get started as a Java developer, making hiring easier.
  • Using Kotlin makes the engineering team happier.

Let’s look at Faire’s journey together with Jeff.


Kotlin is an excellent choice for server-side application development. Go to the Kotlin for server-side page to learn more.


About Faire

Originating in the US, Faire is a wholesale marketplace that aims to help small and medium businesses (SMBs) to compete against the likes of Amazon and Walmart and chase their dreams.

The platform is backed by investors, such as Y Combinator, Sequoia Capital, and DST Global. At the end of 2020, Faire raised 170M at a 2.5B valuation and is now looking to expand into Europe.

Architecture Overview

Faire’s backend monolith is written entirely in Kotlin, as are the new services they create as they seek to replace the old monolith system. They make use of both traditional Java libraries, such as Hibernate for ORM, and Guice for dependency injection, as well as libraries written in Kotlin such as Wire for protocol buffers and OkHTTP for network requests. The architecture is standard – a MySQL database, Redis for caching, and then Amazon’s Simple Queue Service (SQS) to run jobs asynchronously.

When an HTTP request comes in, it hits an external load balancer (an Amazon Elastic Load Balancer).

The request is routed to the Kubernetes cluster, where it arrives at an Nginx instance to see which service to route to.

The code is split into two main groups: web server and worker pods. Web server pods service incoming HTTP requests, and enqueue jobs. The jobs are handled by the worker pods, which also handle recurring tasks such as “Run this piece of code every day at 1 am”.

MySQL is the primary data store, and Redis is used for caching. Faire uses an event-streaming service (Kinesis Firehose) to stream data into their data warehouse.

Why Kotlin?

While Java was a fine language choice, Faire started looking for a programming language that would be more expressive and fix some of its shortcomings. Jeff worked with Kotlin at his previous company and had been exposed to how powerful it is. He suggested trying Kotlin and seeing if it would be a better fit for Faire to replace Java.

Kotlin had full interop with the JVM, behaved similarly to Java, but cut down on the rough edges with features such as nullable types, object keyword, mutable vs immutable collections, and more.

“We decided to switch because we liked the velocity of new Kotlin features, and felt the features available at the time made it worth switching to. The fact that the Java interop is first-tier made it extremely easy to introduce Kotlin to the codebase, as there was little to no risk if we decided to switch back to Java in the future.”

For Faire, Kotlin in many ways came across as a “better Java”, for Faire and they jumped into the migration process.

Java to Kotlin Migration: Challenges and Benefits

The initial commit to add Kotlin was only a few files: one to convert a simple existing Java file to Kotlin, and then a couple of updates to the team’s Maven files to update the build system.

They started the migration process by using the Java-to-Kotlin converter built into IntelliJ IDEA. Automated conversion isn’t perfect and requires some manual work to make the code fluent. There were cases where a Java Integer would be converted to a Kotlin Int, only for the team to find out that field is in fact nullable (sometimes in tests, other times in staging).

Migration to Kotlin helped to reveal previously made assumptions about the nullability of different variables. In Java, extra validation would have to be added to call-sites to catch and prevent errors; with Kotlin, this work could be delegated by leveraging the type system and relying on the compiler. This resulted in less boilerplate code for null checks and improved quality by eliminating human mistakes.

In early 2018 there weren’t many other companies using Kotlin for the backend, so it was tough to find external resources for specific issues. Faire developers overcame these issues through trial and error. For example, Kotlin leans towards final by default, which in some cases conflicts with how Hibernate works. They eventually learned how to properly integrate with Java libraries and built up best practices, and as more of the code was converted to Kotlin, they saw fewer and fewer NPEs.

“Finally Kotlin let us use a modern language that new hires are happy to use. Really it’s like ‘Java Next’, which I think is the sweet spot for server use cases.”

Today the community generates lots of helpful materials. But when it’s your first exposure to a technology, it can be tricky to navigate them. To get daily access to Kotlin news and discussions join our community Slack.

Favorite features

“Java Interop — it feels weird to call this a feature, but we would not have been able to migrate to Kotlin without it. I was extremely impressed by how thoughtful the language creators were around interop, which with the exception of a few nuances, made it extremely easy to migrate our codebase.”

  • Data classes — data classes were a godsend in terms of debuggability (via toString), but also in terms of correctness (via equals and hashCode). On the server, the team is constantly creating small classes to move data around.
  • Type system (including read-only collections) — Java libraries provided some of the features that Kotlin gives first-class support for. One such case is ImmutableList and ImmutableSet which are provided by Guava. Another is using the @Nullable and @NotNull annotations to document variables. Kotlin puts all of these into the type system with List vs MutableList, and List vs List?. Having first-class support for these in the type system means the language can offer support for them via the standard library, and it doesn’t feel like they’re hacked on to the language. Simply put, this makes the development experience much nicer and lets the language do more of the work.
  • Lambda expressions and type inference — these deserve a special mention, they are again another godsend for us coming from Java (this was pre-Java 11, so no var keyword). Passing a function around in Java was a nightmare from a type system perspective, which meant we very rarely did it. And having to declare all types (even though IntelliJ IDEA helped) was a drag. With those two features combined, it feels like we can write the code we want (e.g. pass a lambda to a function to be invoked), as there is Java to resist it with its lack of functional support.

Summary

Converting from Java to Kotlin was fun and easy for Faire thanks to the excellent interop between Java and Kotlin. It also brought an additional advantage to the startup in terms of recruiting. Being able to work in a more modern language was compelling to a lot of the developers. And for many it was a new opportunity to write Kotlin in a production environment. Eventually, Faire found almost all of its developers much happier and more productive.

Continue ReadingFaire Сase Study: Kotlin Backend for a Disruptive SMB Marketplace

Expedia Group: Bootiful APIs With GraphQL and Kotlin

About Expedia

Expedia Group is the world’s travel platform. We help knock down the barriers to travel, making it easier, more enjoyable, more attainable and more accessible. We are here to bring the world within reach for customers and partners around the globe. We leverage our platform and technology capabilities across an extensive portfolio of businesses and brands to orchestrate the movement of people and the delivery of travel experiences on both a local and global basis.


Kotlin is an excellent choice for server-side application development. Go to the Kotlin for server-side page to learn more.


The technology stack at Expedia Group

The JVM is the primary technology stack used by the backend services at Expedia Group. The individual teams can choose their technology stack outside of the JVM, but since most libraries are Java-based, most of the backend stack is JVM-based as well. With the microservice architecture, there are currently hundreds of Spring Boot apps powering various parts of the customer experience.

Some teams within Expedia began experimenting with Kotlin on the server side in late 2017. Thanks to the expressiveness of the language, Kotlin quickly gained popularity among developers, and many greenfield projects started adopting it. Soon after, Kotlin became part of the core technology stack. It has also now become the language of choice for developing the new GraphQL services. Kotlin adoption is growing steadily at Expedia, and it is used to power a number of services including GraphQL, REST, and gRPC-based APIs.

Why Kotlin?

Expedia adopted Kotlin because of its null-safety compiler guarantees, the conciseness of the language, and its full Java interoperability. Interoperability with Java made a gradual Kotlin integration possible without having to fully rewrite applications. Migrating existing Java applications to Kotlin generally followed the path of introducing Kotlin data classes first and then gradually migrating the rest of the source code. Java interoperability also allowed Expedia to easily integrate Kotlin applications with Java libraries and fully utilize the existing JVM ecosystem.

Kotlin Coroutines were a critical factor in the wide adoption of the language. They allow developers to write fully asynchronous code in an imperative way, which leads to more readable and maintainable code. The Spring Framework is used heavily at Expedia, and starting with version 5.2 it introduced interoperability between WebFlux and coroutines. For the engineers at Expedia, this was a game-changer that made it possible to leverage the Spring and Reactive stack in a more imperative way.

GraphQL with Kotlin

GraphQL was created to address the needs of mobile clients – it provides a single API for all the clients to integrate with that allows them to selectively ask for the data they need and that can be modified without breaking any of the existing clients. When Expedia started modernizing its frontend stack, they decided to move toward GraphQL and build a single API gateway to power all frontend applications. In order to streamline the development experience and ensure that the code is a single source of truth for the APIs, Expedia applies Kotlin’s powerful reflection library to generate the GraphQL schema directly from the source code.

“We believe that the ability to generate your GraphQL schemas directly from the source is useful functionality that can benefit the open-source community, so we open-sourced the resulting libraries as graphql-kotlin to help developers run GraphQL in Kotlin.” — Dariusz Kuc, Principal Software Engineer

Over time, the graphql-kotlin libraries grew to provide additional functionality, including a Spring Boot autoconfiguration library that eliminates all the boilerplate code needed to configure and run a GraphQL server. As a result, developers can simply write functions that return data classes, and the graphql-kotlin libraries will automatically convert them to a valid GraphQL schema and start a reactive Spring Boot web application.

At KotlinConf 2019, Dariusz Kuc and Guillaume Scheibel talked about how to utilize the power of Spring Boot together with graphql-kotlin. Watch the video:

The shift to Kotlin Coroutines

Expedia started the development of the new GraphQL services using Spring MVC, which relies on a blocking servlet threading model. While it worked, blocking threads was not the most efficient use of hardware resources. Since GraphQL services return data from some downstream services and data stores, whenever there is a dependency on a slow resource, underlying threads end up blocked as they wait for the data to arrive. Reactive frameworks allow you to process the data in a non-blocking way and are a good tool for approaching this problem.

Expedia’s first attempt with reactive frameworks was with RxJava, which helped to parallelize the downstream calls. While it worked for simple things, there were several issues that arose. Developers attempted to use traditional imperative programming models within the reactive paradigm. They were using incorrect operators or causing some unintended side effects. As a result, due to the different programming models, additional training was required, which slowed down the onboarding process of new developers.

That’s why, when Spring announced full interop between their reactive WebFlux framework and Kotlin coroutines, Expedia quickly switched. Thanks to the imperative programming model of Kotlin Coroutines, it was much easier for developers to learn and use it effectively. Coroutines quickly became the preferred way to write highly performant asynchronous code.

“Thanks to Kotlin’s conciseness and support for imperative programming style for writing fully asynchronous code, the resulting code is much more readable and maintainable. “ — Dariusz Kuc, Principal Software Engineer

Summary

In short, the following features make Kotlin an attractive programming language at Expedia:

  • Conciseness. The expressiveness of the language results in concise code, making it possible to write less code with fewer mistakes.
  • Null-safety. This extra safety feature is built into Kotlin’s compiler, resulting in fewer issues with dereferencing null values.
  • Java-interoperability. The fact that you can leverage the Java ecosystem, with all its frameworks and libraries, is a serious productivity booster! You also don’t have to rewrite the Java application fully in Kotlin – you can introduce Kotlin code gradually into your Java project and migrate slowly.
  • Kotlin Coroutines. These offer an easy way to master the asynchronous code with an imperative programming model. The fact that Coroutines support was added to the Spring Framework made it even easier to take advantage of this feature.
Continue ReadingExpedia Group: Bootiful APIs With GraphQL and Kotlin

End of content

No more pages to load