SlideShare a Scribd company logo
Migrating our micro services
from Java to Kotlin
Yet another awesome journey
2
Björn Wendland
Full-Stack Developer
@BjoernWendland
3
M|SHOP Picture
Our Migration Journey
Why we migrated from Java to Kotlin
5
Controversial
Java Features
Checked exceptions
7
public static void refundExcessMoney() throws ExternalPspFailureException {
// try to refund money
throw new ExternalPspFailureException();
}
try {
refundExcessMoney()
} catch (ExternalPspFailureException e) {
// log or rethrow
}
Single abstract method types
8
public interface Comparator<T> {
public boolean compare(T a, T b);
}
public class PaymentComparator implements Comparator<PaymentInformation> {
@Overwrite
public boolean compare(PaymentInformation a, PaymentInformation b) {
...
}
}
Wildcard-types
9
// use-site wildcard
List<?> paymentRawTypes = new ArrayList<Integer>();
void original(List<Number> paymentRawTypes) { }
void withWildcard(List<? extends Number> paymentRawTypes) { }
// Kotlin use-site variance
var paymentRawTypes = listOf(1, 2, 3)
Beneficial
KotlinFeatures
Null-safety
11
// non null-able
var paymentInformationId: UUID = UUID.randomUUID()
paymentInformationId = null // compilation error
// null-able
var paymentInformationId : UUID? = UUID.randomUUID()
paymentInformationId = null // ok
Extension functions
12
// Java
List<OrderId> orderIds = new ArrayList( Arrays.asList(id1, id2, id3) );
return JsonUtils.toJson(orderIds);
// Kotlin
val orderIds = listOf(id1, id2, id3)
return orderIds.toJson()
Smart casts
13
// Java
if (payment instanceof CreditCardPayment) {
CreditCardPayment ccPayment = (CreditCardPayment) payment;
return ccPayment.getCardHolder();
}
// Kotlin
if (payment is CreditCardPayment) {
return payment.cardHolder
}
Coroutines
Payment capture flow
15
PAY FEED PSPOM
write
feed
poll
status
request
capture
capture
poll
feed
fun capturePayment() {
val lastKnownEventId = feedsService.getLatestEventId()
paymentService.capture()
val feedStatus = getFeedStatus(lastKnownEventId)
feedStatus.whenError {
throw CreditCardCaptureException()
}
}
Request capture
16
Asynchronous feed reader
17
fun getFeedStatus(lastKnownEventId: UUID?): PaymentFeedStatus {
return runBlocking {
withTimeout(syncClientTimeout) {
var paymentFeedEvent: PaymentFeedEvent?
do {
paymentFeedEvent = feedsService.getSuccessorEventFor(lastKnownEventId)
delay(200)
} while (paymentFeedEvent.isNull())
paymentFeedEvent?.getStatus()
}
}
}
18
Our Journey Continues
What did we migrate
19
How did we migrate
20
refactor to
idiomatic
Kotlin
verify
using tests
fix invalid
code
automatic
code
conversion
Rewrite
everything
Switching to Kotlin frameworks
22
 KTOR - asynchronous Kotlin web framework
 Spring Boot - established Java web framework
 Often less matured
 Often less documented
No need to forcefully use
Kotlin libraries and frameworks
Review and Outlook
Review
24
 Challenge which we mastered as team
 Migrating was worth the effort
 Improved design and new focus on language
 Quality of life update
10/10 would use Kotlin again
A heads up
25
 Test coverage is a must have
 Consider your people and eco system
 Consider language and framework maturity level
 Amount of new things can be overwhelming
Outlook
26
 Establish Kotlin at METRONOM
 Help others introduce Kotlin
 Introduce more native Kotlin frameworks
 Find new passionate developers
Follow us on Twitter and Instagram
@bjoernwendland
@joinmetronomnow
#METRONOMians #wearedevs19 #passion #ambition #purpose
Hall A
Booth A11
@BjoernWendland
28
Thank you for
your attention!

More Related Content

What's hot (16)

PPTX
Accessing decentralized finance on Ethereum blockchain
Gene Leybzon
 
PDF
The evolution of java script asynchronous calls
Huy Hoàng Phạm
 
PDF
MongoDB World 2016: Implementing Async Networking in MongoDB 3.2
MongoDB
 
PPTX
Hello world contract
Gene Leybzon
 
PDF
Advanced functional programing in Swift
Vincent Pradeilles
 
PDF
Programming clients-slides
MasterCode.vn
 
PDF
Introducing wcf-slides
MasterCode.vn
 
DOCX
Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp
 
PDF
Grailsでドメイン駆動設計を実践する時の勘所
Takuma Watabiki
 
PPT
Lecture04
elearning_portal
 
DOCX
Assignement of programming & problem solving
Syed Umair
 
PDF
Design Patterns in .Net
Dmitri Nesteruk
 
PPTX
RxJS ‘Marble’ programming
Stas Rivkin
 
PDF
openconfigd
Masakazu Asama
 
PPT
Velocity 2014: Accelerate Your User Experience With Client-side JavaScript
Intuit Inc.
 
Accessing decentralized finance on Ethereum blockchain
Gene Leybzon
 
The evolution of java script asynchronous calls
Huy Hoàng Phạm
 
MongoDB World 2016: Implementing Async Networking in MongoDB 3.2
MongoDB
 
Hello world contract
Gene Leybzon
 
Advanced functional programing in Swift
Vincent Pradeilles
 
Programming clients-slides
MasterCode.vn
 
Introducing wcf-slides
MasterCode.vn
 
Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp
 
Grailsでドメイン駆動設計を実践する時の勘所
Takuma Watabiki
 
Lecture04
elearning_portal
 
Assignement of programming & problem solving
Syed Umair
 
Design Patterns in .Net
Dmitri Nesteruk
 
RxJS ‘Marble’ programming
Stas Rivkin
 
openconfigd
Masakazu Asama
 
Velocity 2014: Accelerate Your User Experience With Client-side JavaScript
Intuit Inc.
 

Similar to Migrating our micro services from Java to Kotlin 2.0 (20)

PDF
From Java to Kotlin - The first month in practice
StefanTomm
 
PDF
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PDF
Why Spring <3 Kotlin
VMware Tanzu
 
PDF
Be More Productive with Kotlin
Brandon Wever
 
PPTX
Kotlin for android
Shady Selim
 
PPTX
Kotlin for all the Things
Eamonn Boyle
 
PPTX
Building Mobile Apps with Android
Kurt Renzo Acosta
 
PDF
Java To Kotlin A Refactoring Guidebook 1st Edition Duncan Mcgregor
daiziyuleth25
 
PDF
From Java to Kotlin - The first month in practice v2
StefanTomm
 
PPTX
Intro to kotlin 2018
Shady Selim
 
PDF
Building microservices with Kotlin
Haim Yadid
 
PDF
Evolutionary architecture: evolving even the language
Luram Archanjo
 
PDF
Rapid Web API development with Kotlin and Ktor
Trayan Iliev
 
PPTX
Why kotlininandroid
Phani Kumar Gullapalli
 
PPTX
Kotlin. One language to dominate them all.
Daniel Llanos Muñoz
 
PDF
TMPA-2015: Kotlin: From Null Dereference to Smart Casts
Iosif Itkin
 
PPTX
Kotlin
YeldosTanikin
 
PPTX
Kotlin: lo Swift di Android (2015)
Omar Miatello
 
PDF
From Java to Kotlin
João Ferrão
 
PPTX
Kotlin - A language to dominate them all
Sergio Casero Hernández
 
From Java to Kotlin - The first month in practice
StefanTomm
 
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Why Spring <3 Kotlin
VMware Tanzu
 
Be More Productive with Kotlin
Brandon Wever
 
Kotlin for android
Shady Selim
 
Kotlin for all the Things
Eamonn Boyle
 
Building Mobile Apps with Android
Kurt Renzo Acosta
 
Java To Kotlin A Refactoring Guidebook 1st Edition Duncan Mcgregor
daiziyuleth25
 
From Java to Kotlin - The first month in practice v2
StefanTomm
 
Intro to kotlin 2018
Shady Selim
 
Building microservices with Kotlin
Haim Yadid
 
Evolutionary architecture: evolving even the language
Luram Archanjo
 
Rapid Web API development with Kotlin and Ktor
Trayan Iliev
 
Why kotlininandroid
Phani Kumar Gullapalli
 
Kotlin. One language to dominate them all.
Daniel Llanos Muñoz
 
TMPA-2015: Kotlin: From Null Dereference to Smart Casts
Iosif Itkin
 
Kotlin: lo Swift di Android (2015)
Omar Miatello
 
From Java to Kotlin
João Ferrão
 
Kotlin - A language to dominate them all
Sergio Casero Hernández
 
Ad

Recently uploaded (20)

PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PPTX
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PDF
Français Patch Tuesday - Juillet
Ivanti
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
Top Managed Service Providers in Los Angeles
Captain IT
 
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Français Patch Tuesday - Juillet
Ivanti
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
Ad

Migrating our micro services from Java to Kotlin 2.0

  • 1. Migrating our micro services from Java to Kotlin Yet another awesome journey
  • 5. Why we migrated from Java to Kotlin 5
  • 7. Checked exceptions 7 public static void refundExcessMoney() throws ExternalPspFailureException { // try to refund money throw new ExternalPspFailureException(); } try { refundExcessMoney() } catch (ExternalPspFailureException e) { // log or rethrow }
  • 8. Single abstract method types 8 public interface Comparator<T> { public boolean compare(T a, T b); } public class PaymentComparator implements Comparator<PaymentInformation> { @Overwrite public boolean compare(PaymentInformation a, PaymentInformation b) { ... } }
  • 9. Wildcard-types 9 // use-site wildcard List<?> paymentRawTypes = new ArrayList<Integer>(); void original(List<Number> paymentRawTypes) { } void withWildcard(List<? extends Number> paymentRawTypes) { } // Kotlin use-site variance var paymentRawTypes = listOf(1, 2, 3)
  • 11. Null-safety 11 // non null-able var paymentInformationId: UUID = UUID.randomUUID() paymentInformationId = null // compilation error // null-able var paymentInformationId : UUID? = UUID.randomUUID() paymentInformationId = null // ok
  • 12. Extension functions 12 // Java List<OrderId> orderIds = new ArrayList( Arrays.asList(id1, id2, id3) ); return JsonUtils.toJson(orderIds); // Kotlin val orderIds = listOf(id1, id2, id3) return orderIds.toJson()
  • 13. Smart casts 13 // Java if (payment instanceof CreditCardPayment) { CreditCardPayment ccPayment = (CreditCardPayment) payment; return ccPayment.getCardHolder(); } // Kotlin if (payment is CreditCardPayment) { return payment.cardHolder }
  • 15. Payment capture flow 15 PAY FEED PSPOM write feed poll status request capture capture poll feed
  • 16. fun capturePayment() { val lastKnownEventId = feedsService.getLatestEventId() paymentService.capture() val feedStatus = getFeedStatus(lastKnownEventId) feedStatus.whenError { throw CreditCardCaptureException() } } Request capture 16
  • 17. Asynchronous feed reader 17 fun getFeedStatus(lastKnownEventId: UUID?): PaymentFeedStatus { return runBlocking { withTimeout(syncClientTimeout) { var paymentFeedEvent: PaymentFeedEvent? do { paymentFeedEvent = feedsService.getSuccessorEventFor(lastKnownEventId) delay(200) } while (paymentFeedEvent.isNull()) paymentFeedEvent?.getStatus() } } }
  • 19. What did we migrate 19
  • 20. How did we migrate 20 refactor to idiomatic Kotlin verify using tests fix invalid code automatic code conversion
  • 22. Switching to Kotlin frameworks 22  KTOR - asynchronous Kotlin web framework  Spring Boot - established Java web framework  Often less matured  Often less documented No need to forcefully use Kotlin libraries and frameworks
  • 24. Review 24  Challenge which we mastered as team  Migrating was worth the effort  Improved design and new focus on language  Quality of life update 10/10 would use Kotlin again
  • 25. A heads up 25  Test coverage is a must have  Consider your people and eco system  Consider language and framework maturity level  Amount of new things can be overwhelming
  • 26. Outlook 26  Establish Kotlin at METRONOM  Help others introduce Kotlin  Introduce more native Kotlin frameworks  Find new passionate developers
  • 27. Follow us on Twitter and Instagram @bjoernwendland @joinmetronomnow #METRONOMians #wearedevs19 #passion #ambition #purpose Hall A Booth A11

Editor's Notes

  • #2: About Metronom ‚The biggest software company you never heard about‘ METRO’s tech unit providing solutions to customers and employees 'Setting the pace in food an technology‘ About Metro German global diversified retail and wholesale/cash and carry group based in Düsseldorf
  • #3: About me Joined METRONOM last july as Full Stack Developer Became Kotlin Ambassador at METRONOM over the cause of the last year
  • #5: Reasoning behind migrating to Kotlin How to approach the task What we’ve learned in the process
  • #6: Why did we choose Kotlin? A developers curiosity Java 2.0 It is close enough to the previous eco system (JVM / Spring Boot/ PostgresDB) Justification: “Setting the pace in food and technology” About the design Started with Java microservices based on proprietary (yet open source) web framework Unhappy with Java’s design Feeling of being outdated and heavy Finally tipping the scale Google announcing Kotlin as officially supported for Android Level of maturity By now Kotlin became the suggested language for Android development
  • #7: Checked exceptions Single Abstract Method Types (SAM Types) Wildcard Types
  • #8: Benefit: compiler error if exception is not handled Disadvantage: laborious and results in harder to read code Kotlin has unchecked exceptions
  • #9: Lambda expressions are considered a SAM type and can be freely converted SAM Type not bad in general, but propper function types are prefered Kotlin has proper function types opposed to SAM-conversions
  • #10: Not explicit / lacking information Unsafe (needs casting) Can be confusing Kotlin has use-site variance without wildcards
  • #11: Null-safety support in Kotlin typing system Extension functions Smart casts Coroutines
  • #12: ATTENTION: Java libraries null-safety can not be infered
  • #13: ATTENTION: How to manage extension functions?
  • #15: Using Coroutines See how async code is composed in real world code
  • #18: runBlocking launches coroutine withTimeout keeps runtime in check and throws exception of needed Read new event Delay:programmer allowes code to be scheduled at this point Infinite loop And return value Still reads like sync code, but allowes to be yielded It handles waiting for a response very greaceful Safe against infinite loops
  • #20: Why did we choose Kotlin? A developers curiosity Java 2.0 It is close enough to the previous eco system (JVM / Spring Boot/ PostgresDB) Justification: “Setting the pace in food and technology” About the design Started with Java microservices based on proprietary (yet open source) web framework Unhappy with Java’s design Feeling of being outdated and heavy Finally tipping the scale Google announcing Kotlin as officially supported for Android Level of maturity By now Kotlin became the suggested language for Android development
  • #21: Structured process Intellij’s automatic code conversion for class Fix non compiling code / non translatable language constructs Refactor, even partially rewrite methods Verify correctness using unit tests Convert unit tests
  • #23: Migrate to Kotlin libraries Goal was a 100% Kotlin micro service Mockk, Asskertk, Klaxon, etc. Add a library / framework next to existing one Phase out previously used Java framework Goal was a 100% Kotlin micro service Spiked KTOR and Spring Boot We decided to use Spring Boot, because it is fully documented and it enforces the project structure KTOR not yet mature enough and lacks documentation also does not enforce a project structure Will be considered again, since it is more lightweight and has better performance
  • #24: Finally a look back And one ahead
  • #25: Disclaimer Does not only plly to Kotlin
  • #27: If anyone is looking for a new job and wants to work with Kotlin
  • #30: Structured process Intellij’s automatic code conversion for class Fix non compiling code / non translatable language constructs Refactor, even partially rewrite methods Verify correctness using unit tests Convert unit tests