I'm building something that requires a server, a w...
# multiplatform
l
I'm building something that requires a server, a web frontend, and an android app, but I'm not sure if I should go with KMP on this one. Sharing code seems nice, but I'm worried about the coupling. Ideally, the server and its web frontend should move independently from any client apps, but wouldn't it be possible that a change in a model or a DTO require a new release for the Android app? I don't even plan to share any logic with the app, just types and interfaces, but I can already see scenarios where the coupling might break something. I know I want both server and app to be in Kotlin, but I don't know if KMP is ideal in this situation. Any thoughts? This is the first time I'm planning to use KMP for server/android instead of the usual android/ios/desktop.
a
It sounds like there is some confusion here. You only need to use KMP specifically where you want to share code between platforms. Overall this is a good thing, but you will likely still have classes that exist only for your mobile app or only for your server model. DTOs can of course be shared, and if those need to change, they would likely have to change on the web server or other areas too I would imagine, because you're transferring them between your app and web server. There's no reason you couldn't write your webserver in straight Kotlin on the JVM for example, or as a ktor multiplatform app, but that doesn't force you into an architecture decision with your mobile app either.
l
I just don't see how sharing code between server and android could be good in this scenario where I need the server to be its own thing. The app is just a client, just like the web frontend. But the web frontend is bundled with the server since I'm building a self-hosted media library. Any updates in the server also updates the frontend automatically. The same isn't true for the android app. Sharing models, dtos, or actual business logic between server and app seems rather strange to me. Now whenever I change something in the server I have to be careful not to break the android app. I think I might just go with a normal ktor backend and a KMP android/ios app, but I wanted to know others' opinion on sharing code between server and android on a KMP project. Maybe there's a valid usecase for it, but it doesn't seem to apply to this project.
a
We do it all the time, but typically I would say we see it in the reverse. Because our app model is syncing data and often needs to interact with our server, we immediately want to update the Android/iOS app anytime we update our model with almost 100% certainty. That said, we often have servers that are jvm-only, that use the multiplatform libraries we create for each model that we use.
e
> Ideally, the server and its web frontend should move independently from any client apps Just make the server & web FE move independently 🙂. The only way in which they are coupled is when you, the developer, programs it that way. > I don't even plan to share any logic with the app, just types and interfaces, but I can already see scenarios where the coupling might break something. I think you do not want code sharing, which is fine. In this case client apps and web/BE stuff can diverge.
g
When you have central servers and distributed apps (desktop, mobile), since you can not actually keep your distributed code fully in sink with cloud based updates, then fundamentally you can not change a contract (DTOs) directly! Any changes become new endpoints and DTOs! Only when you are sure that no one is still using the previous 'deprecated' endpoints, can they be removed from the servers!