SlideShare a Scribd company logo
Kotlin Backend Development 5 Yrs Recap.
The Good, the Bad and the Ugly
Haim Yadid VP Technology @ Next Insurance
Kotlin Backend Development 6 Yrs Recap.
The Good, the Bad and the Ugly
Haim Yadid VP Technology @ Next Insurance
NEXT
3
@lifexy
NEXT
4
NEXT
5
Prelude
So… decisions
NEXT
6
Decisions
NEXT
7
NEXT
8
NEXT
9
NEXT
#Backend Developers
1
2016 2017
8 150
2022
This is important
NEXT
#LOC
10k
2016 2017
100K 1.2M
2022
NEXT
Kotlin Version
1.0.2
2016 2017
1.1.50 1.6.10
2022
NEXT
JVM
1.8
2016 2017
1.8 17
2022
NEXT
14
● Working flawlessly in production
● Smooth Onboarding of Java
developers
● Good IDE support
● Community Adoption is growing
● Selling point for hiring
NEXT
15
Huge Success
NEXT
16
Some Short stories:
Kotlin Promises
Are mostly kept
NEXT
Main Tech Stack Components
AWS EC2
K8s
JVM
Kotlin
Dropwizard
Jetty Jersey Logback JDBI
Guice
JUNIT
Flyway
RDS
Kotlin
Script
17
Jackson
NEXT
Main Tech Stack Components
AWS EC2
K8s
18
NEXT
Main Tech Stack Components
JUNIT
19
NEXT
Main Tech Stack Components
JVM
Kotlin
20
AWS EC2
K8s
NEXT
Main Tech Stack Components
JVM
Kotlin
Kotlin
Script
21
Policy
Rating
Formula
Rating
Formulas
Other versions
AWS EC2
K8s
NEXT
Main Tech Stack Components
Dropwizard
Jetty Jersey Logback JDBI
Guice
22
Jackson
NEXT
Main Tech Stack Components
Flyway
RDS
23
NEXT
Main Tech Stack Components
AWS EC2
K8s
JVM
Kotlin
Dropwizard
Jetty Jersey Logback JDBI
Guice
JUNIT
Flyway
RDS
Kotlin
Script
24
Jackson
NEXT
25
Data classes - The Prince that was Promised
data class AddressInfo(
val telephone: String,
val street: String,
val num: Int,
val city: String,
val zipCode: String,
val state: State?
)
● Widely used >6100 data classes
● Used for DTO, DAO
● Rest API Serialization / deserialization with jackson
● hashcode/equals/(se|ge)tters saves a lot of boilerplate
● copy() helps working with immutable objects
NEXT
26
Data Classes - Jackson Serialization
fun ObjectMapper.applyNiSettings(): ObjectMapper {
NEXT
27
Data Classes - Jackson Serialization
fun ObjectMapper.applyNiSettings(): ObjectMapper {
return this
.registerModule(KotlinModule())
NEXT
28
Data Classes - Jackson Serialization
fun ObjectMapper.applyNiSettings(): ObjectMapper {
return this
.registerModule(KotlinModule())
.configure(
DeserializationFeature
.FAIL_ON_UNKNOWN_PROPERTIES, false)
NEXT
29
Data Classes - Jackson DeSerialization
fun ObjectMapper.applyNiSettings(): ObjectMapper {
return this
.registerModule(KotlinModule())
.configure(
DeserializationFeature
.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(
DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES,
true) }
NEXT
30
The Promise of Null Safety
val productVersion:String = versions[versionId]
Map<String,Sting>
NEXT
31
The Promise of Null Safety
val productVersion:String? = versions[versionId]
Map<String,Sting>
NEXT
32
The Promise of Null Safety
val productVersion:String = versions[versionId]!!
NullPointerException
NEXT
33
The Promise of Null Safety
val productVersion:String =
versions.require(versionId)
A better
NullPointerException
NEXT
34
The Promise of Null Safety
val productVersion:String = versions[versionId]!!
require(productVersion.status == Staged) {
"Version $versionId: Can't unstage status…" }
versions[versionId] = productVersion.copy(
status = ProductVersionStatus.Draft,
updatedBy = updatedBy)
NEXT
35
The Promise of Null Safety
● Null Safety Mechanisms baked in the type system
● No more NPEs ?
● ( not really) >11052 invocations of !!
● Where do they come from
○ interacting with Java based third party libraries
○ Getting values from maps
NEXT
36
<|*|>
NEXT
37
Operator Overloading
● 155 overloads (plus,minus,times,get,invoke)
● Most usages makes sense
operator fun times(factor: BigDecimal) = …
operator fun plus(toAdd: AmountWithAttribution) = …
operator fun minus(toSubtract: AmountWithAttribution) =
operator fun compareTo(other: AmountWithAttribution) =
NEXT
38
Extension Functions
fun MutableList<Int>.swap(index1: Int, index2: Int) {
val tmp = this[index1] // 'this' corresponds to the list
this[index1] = this[index2]
this[index2] = tmp
}
NEXT
39
Extension Functions
private fun String.
NEXT
40
Extension Functions
private fun String.isVersionLowerThan(
thatVersion: String) =
when {
isValidSpecificBranchVersion(thatVersion) &&
this==thatVersion -> false //same branch
isValidSpecificBranchVersion(thatVersion) -> true
NEXT
41
Extension Functions
fun String.isVersionLowerThan(
thatVersion: String) =
when {
isValidSpecificBranchVersion(thatVersion) &&
this==thatVersion -> false //same branch
isValidSpecificBranchVersion(thatVersion) -> true
NEXT
42
Extension Functions - my preferance
private fun isVersionLowerThan(
thisVersion:String , thatVersion: String) =
…
NEXT
43
Extension Functions
data class WhateverDTO(val state: State,
@field:NotBlank val zipCode: String,
@field:NotBlank val city: String,
@field:NotBlank val streetAddress: String
)
NEXT
44
Extension Functions
data class WhateverDTO(val state: State,
@field:NotBlank val zipCode: String,
@field:NotBlank val city: String,
@field:NotBlank val streetAddress: String
)
fun WhateverDTO.getAsParamValue() =
"${streetAddress}$EOL${city}, ${state.dbName} $zipCode"
NEXT
45
Our concurrency model & Tx Ctx
Jetty
Worker
Thread
CTX
Worker
Thread
CTX
Worker
Thread
CTX
Worker
Thread
CTX
Thread Pool(s)
Worker
Thread
CTX
Worker
Thread
CTX
Worker
Thread
CTX
Worker
Thread
CTX
Ctx: (MDC)
TransactionID
Caller
Flow
OpenID Span
NEXT
46
Executors - fixing context
fun Executor.executeWithContext(r: Runnable) {
execute(r)
}
NEXT
47
Executors - MDC Usage
fun Executor.executeWithContext(r: Runnable) {
val mdcContextInfo = MDCContextInfo.fromMDC()
val activeSpan = GlobalTracer.get().activeSpan()
val rWithContext = Runnable {
mdcContextInfo.populateMDC()
GlobalTracer.get().activateSpan(activeSpan)
r.run()
}
execute(rWithContext)
}
NEXT
48
Coroutines : launch
fun CoroutineScope.launchWithContext(
): Job =
launch( )
also async ,runBlocking, flowOn
NEXT
49
Coroutines : launch
fun CoroutineScope.launchWithContext(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
block: suspend CoroutineScope.() -> Unit
): Job =
launch(MDCContext() + context, start, block)
also asyncWithContext,runBlockingWithContext, flowOnWithContext
NEXT
50
Type Aliases
From Kotlin documentation:
Type aliases provide alternative names for existing types. If the type name is
too long you can introduce a different shorter name and use the new one
instead.
It's useful to shorten long generic types. For instance, it's often tempting to
shrink collection types:
typealias NodeSet = Set<Network.Node>
typealias FileTable<K> = MutableMap<K,
MutableList<File>>
NEXT
51
Type Aliases - The feature we use too much
typealias AffiliateId = Int
typealias AgencyId = Int
typealias AgencyAggregatorId = Int
typealias AgentId = String
typealias BundleId = Int
typealias BusinessId = String
.
.
.
// additional 50 type aliases
Controversial in the community as
well
○ https://medium.com/@amlcurran/a
voiding-primitive-obsession-in-swift
-5325b65d521e
○ https://medium.com/@jerzy.chalup
ski/kotlin-the-missing-parts-67645d
9a02f4
NEXT
52
typealias ZipCode = String
typealias Address = String
fun main() {
var zip: ZipCode = "56934"
val addr: Address = "bb"
zip = addr
}
Type Aliases - Are not Type Safe
NEXT
53
abstract class SomeClassResponse(
open val success: Success,
open val responseMessage: ResponseMessage)
Type Aliases - What is behind the magic
typealias Success = Boolean
typealias ResponseMessage = String
NEXT
54
abstract class SomeClassResponse(
open val success: Boolean,
open val responseMessage: String)
Type Aliases - What is behind the magic
NEXT
55
@Deprecated("Stop using me")
data class DeprecateMe(val a: String, val b: String)
typealias IamNotDeprecatedAndILikeIt = DeprecateMe
fun main() {
val a = DeprecateMe("a", "b")
val c = IamNotDeprecatedAndILikeIt("a", "b")
Type Aliases - Hides Deprecation
NEXT
56
private typealias ValidationResults =
List<Pair<OTPValidationResponse, DigitsPasswordData>>
Put Type Aliases to Good Use
typealias Row = Array<String>
typealias StringMatrix = List<Array<String>>
NEXT
57
@JvmInline
value class NiJexlExpression(
val expressionString: String)
Inline Classes to the rescue
● Prefer inline classes instead of typealias
● Type safety at compilation
● Migration is not so easy.
● There is a problem with inline classes and our current Jackson Version
● Type erased at runtime ….(Heap Dumps ?)
NEXT
58
A Migration Story
Java11 -> Java 17
NEXT
59
Migrations along the Years
● Migration to Kotlin 1.1.0 ( Java8 support ) was smooth
● Migration to (almost) every version of kotlin immediately
● Migration to Java 11 – only a year ago )
● Migration to Java 17 – 5 months ago
NEXT
NEXT
Build Time
Gradle
7.2
Compiler
&
Bytecode
11
Kotlin
Compiler
1.4
libraries
1.5.21
Run Time
Kotlin
Runtime
1.5.21
JVM
11 / 16
JRE
11 / 16
60
September
2021
NEXT
Proprietary
&
Confidential
NEXT
Kotlin - Java Bytecode Compatibility
● Kotlin 1.4.10 supports Java 14 Bytecode (class version)
● Kotlin 1.4.21 supports Java 15 Bytecode (class version)
● Kotlin 1.5.21 supports Java 16 Bytecode (class version)
● By the time java 17 was released 1.7 bytecode was not
supported
61
Kotlin
NEXT
NEXT
Gradle - Java bytecode Compatibility
Gradle
https://docs.gradle.org/current/userguide/compatibility.html 62
NEXT
Kotlin API deprecation
@Deprecated("Use minOrNull instead."
,
ReplaceWith("this.minOrNull()"))
@DeprecatedSinceKotlin
(warningSince = "1.4", errorSince =
"1.5", hiddenSince = "1.6")
@SinceKotlin("1.1")
public fun Iterable<Double>.min(): Double? {
return minOrNull()
}
min()
max()
minBy()
maxBy()
minOrNull()
maxOrNull()
minByOrNull()
maxByOrNull()
63
NEXT
Detaching gradle compiler version
64
val kotlinVersion = libs.findVersion("kotlin").get()
// 1.6.10 opposed to 1.5.31 from gradle
implementation("org.jetbrains.kotlin:kotlin-gradle-plug
in:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-script-runt
ime:$kotlinVersion")
NEXT
NEXT
Build Time
Gradle
7.4
K1.5.31
Compiler
&
Bytecode
17
Kotlin
Compiler
1.6
libraries
1.6.10
Runtime
Kotlin
Runtime
1.6.10
JVM
17
JRE
17
65
THANKS.

More Related Content

PDF
Native Java with GraalVM
PDF
JVM Mechanics: When Does the JVM JIT & Deoptimize?
PDF
Android RenderScript on LLVM
PDF
XebiCon'16 : Server-Side Swift. Par Simone Civetta, Développeur iOS chez Xebia
ODP
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
PDF
Silicon Valley JUG: JVM Mechanics
PDF
How Triton can help to reverse virtual machine based software protections
PPTX
Building High-Performance Language Implementations With Low Effort
Native Java with GraalVM
JVM Mechanics: When Does the JVM JIT & Deoptimize?
Android RenderScript on LLVM
XebiCon'16 : Server-Side Swift. Par Simone Civetta, Développeur iOS chez Xebia
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Silicon Valley JUG: JVM Mechanics
How Triton can help to reverse virtual machine based software protections
Building High-Performance Language Implementations With Low Effort

Similar to Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly (20)

PDF
Productive Debugging
PDF
Andrea Lattuada, Gabriele Petronella - Building startups on Scala
PDF
Eclipse Day India 2015 - Java bytecode analysis and JIT
ZIP
Google Developer Fest 2010
PDF
Entender React Native
PDF
Tips and tricks for building high performance android apps using native code
PDF
Shiksharth com java_topics
PDF
Profiling distributed Java applications
PDF
ez-clang C++ REPL for bare-metal embedded devices
PPTX
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
ZIP
Building Web Apps Sanely - EclipseCon 2010
PPTX
Kotlin / Android Update
PPT
JavaFX - Next Generation Java UI
PPTX
Crossing Abstraction Barriers When Debugging In Dynamic Languages
PPT
00_Introduction to Java.ppt
PDF
UniRx - Reactive Extensions for Unity(EN)
PDF
Eric Lafortune - The Jack and Jill build system
PPTX
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PDF
Jvm profiling under the hood
PPTX
Node.js - Advanced Basics
Productive Debugging
Andrea Lattuada, Gabriele Petronella - Building startups on Scala
Eclipse Day India 2015 - Java bytecode analysis and JIT
Google Developer Fest 2010
Entender React Native
Tips and tricks for building high performance android apps using native code
Shiksharth com java_topics
Profiling distributed Java applications
ez-clang C++ REPL for bare-metal embedded devices
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Building Web Apps Sanely - EclipseCon 2010
Kotlin / Android Update
JavaFX - Next Generation Java UI
Crossing Abstraction Barriers When Debugging In Dynamic Languages
00_Introduction to Java.ppt
UniRx - Reactive Extensions for Unity(EN)
Eric Lafortune - The Jack and Jill build system
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
Jvm profiling under the hood
Node.js - Advanced Basics
Ad

More from Haim Yadid (20)

PDF
On-Call AI Assistant: Streamlining Production Error Investigation with LLM
PDF
Loom me up Scotty! Project Loom - What's in it for Me?
PDF
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
PPTX
“Show Me the Garbage!”, Understanding Garbage Collection
PDF
Java Memory Structure
PDF
Basic JVM Troubleshooting With Jmx
PDF
The Freelancer Journey
PDF
Building microservices with Kotlin
PDF
Taking Kotlin to production, Seriously
PDF
Let's talk about Garbage Collection
PDF
JVM Garbage Collection logs, you do not want to ignore them! - Reversim Summi...
PDF
mjprof: Monadic approach for JVM profiling
PDF
Java 8 Launch - MetaSpaces
PDF
Java 8 - Stamped Lock
PDF
The Future of Futures - A Talk About Java 8 CompletableFutures
PDF
Concurrency and Multithreading Demistified - Reversim Summit 2014
PDF
A short Intro. to Java Mission Control
PDF
Java Enterprise Edition Concurrency Misconceptions
PDF
Tales About Scala Performance
PDF
Israeli JUG - IL JUG presentation
On-Call AI Assistant: Streamlining Production Error Investigation with LLM
Loom me up Scotty! Project Loom - What's in it for Me?
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Understanding Garbage Collection
Java Memory Structure
Basic JVM Troubleshooting With Jmx
The Freelancer Journey
Building microservices with Kotlin
Taking Kotlin to production, Seriously
Let's talk about Garbage Collection
JVM Garbage Collection logs, you do not want to ignore them! - Reversim Summi...
mjprof: Monadic approach for JVM profiling
Java 8 Launch - MetaSpaces
Java 8 - Stamped Lock
The Future of Futures - A Talk About Java 8 CompletableFutures
Concurrency and Multithreading Demistified - Reversim Summit 2014
A short Intro. to Java Mission Control
Java Enterprise Edition Concurrency Misconceptions
Tales About Scala Performance
Israeli JUG - IL JUG presentation
Ad

Recently uploaded (20)

PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
System and Network Administraation Chapter 3
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Introduction to Artificial Intelligence
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Nekopoi APK 2025 free lastest update
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
AI in Product Development-omnex systems
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
L1 - Introduction to python Backend.pptx
Understanding Forklifts - TECH EHS Solution
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Operating system designcfffgfgggggggvggggggggg
Upgrade and Innovation Strategies for SAP ERP Customers
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
System and Network Administraation Chapter 3
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Introduction to Artificial Intelligence
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Navsoft: AI-Powered Business Solutions & Custom Software Development
Nekopoi APK 2025 free lastest update
Which alternative to Crystal Reports is best for small or large businesses.pdf
AI in Product Development-omnex systems

Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly