In a recent talk reflecting on Rust in the LLM age, Bryan Cantrill described the essence of software systems as the creation of abstractions that get to the essential complexity of a problem. Poor abstractions and accidental complexity are a structural cause of brittle and unmaintainable systems.
Shipping Germ on Android was an exercise in moving toward the essential complexity of our app, which I'd characterize as:
One app logic codebase, in a modern, type and memory safe language
Adopting platform idioms with a thin user presentation through the platform's declarative UI framework
Directly interacting with platform features through the platform SDK
That manifested as a mostly new cross-platform headless app in Swift, leaning on many components we're developing in open source. That headless app is then consumed by thin platform-specific wrappers that provide the user interface, hook into the platform for features like notifications, secrets store, and persistence.
On iOS, this wrapper is in Swift, using SwiftUI and Swift Data. On Android, a Kotlin wrapper builds on Jetpack Compose + Room. This is enabled by the Swift on Android SDK that launched earlier this year.
Swift is a fantastic modern systems language, and we're glad it's turning out to be an excellent cross-platform language as well.
Choice 1: Consolidate in Swift
Type and memory safety are table stakes requirements. Today, Swift and Rust are the main options for systems languages. Rust is a great language, and we've done some work in it. As an application developer, Swift has the advantage that there are two major OS's whose platform SDK is in Swift1, giving us one stack without any cross language Foreign Function Interface (FFI).
We've worked a bit with FFI's in our iOS app, primarily to bring in an existing MLS library in Rust. It's unwieldy to work with importing compiled frameworks, and is brittle as toolchains evolve — more so than source importation. It's always been our long-term goal to move our core dependencies into Swift
Coding agents helped us accelerate that. We ported portions of libjxl to Swift, allowing us to remove our only C++ dependency. Image decoding is a well-known attack vector, particularly for encrypted messengers, and we were happy to drop the remaining unsafe C in our codebase.
We also created a Swift implementation of MLS, and ported our Rust implementation of post-quantum 1:1 rekeying sessions on top of MLS.
The result is that our core app logic is fully a composition of Swift packages.
Choice 2: Functional Modules
Across the libraries we've ported to Swift, we've adopted a functional pattern prevalent in our code. In the reflection on Rust linked above, Cantrill describes a pattern of software choices through the 90's and 2000's that favored developer convenience over operational risk.
One pattern that we've struggled with are libraries that take injected persistence. They're very developer friendly in that the API's are simple, but has proven to be especially difficult to debug when persistence is a side effect. We've previously taken to wrapping our own fake store so we can intercept the writes and expose a functional interface.
Building our own libraries allowed us to write them with the functional API's we prefer, allowing us to more cleanly handle atomic operations.
This is a tradeoff to give up some developer convenience for operational simplicity. If coding agents make it easier to generate and comprehend code, then we can use that to pay down the operational debt that we've built up for developer convenience.
Choice 3: Write different code
We were already in the process of modularizing our iOS app in preparation for cross-platform. It's a structured task that coding agents are well suited for and is easy to verify.
A lot of code didn't make the transition. In particular, we took the opportunity to ship a Messaging AppView for atproto. This offloads the computation of public atproto data to a persistently online helper without compromising privacy.
Lessons
A few more lessons from our foray into Android:
Concurrency
Our adoption of platform idioms turned out to be more than UI deep. There's one important difference between our iOS and Android apps: our iOS app runs on the main thread; our Android app doesn't. This is a direct consequence of the persistence library paired with each platform's declarative UI.
The platform pattern on iOS is to default to the main thread, lazily optimizing by shifting expensive work to the background. This makes for simple app logic and allows for synchronous interactions between the UI and app logic. It's developer friendly, assuming hardware optimized for single threaded performance.
Google's recommended persistence for Jetpack Compose, Room, doesn't permit database access on the main thread. Instead, Room explicitly provides a stream of object updates for the UI to consume asynchronously. This makes sense if you want to prioritize UI responsiveness across a broader range of hardware, making it harder for developers to accidentally block the main thread. We prioritized synchronous access to persistence to limit data and logic races, which meant that our primary app logic moved to a single background isolation.
Confusingly, @MainActor in Swift doesn't actually run on the main thread in Android. This may actually be an accommodation of this difference, but we didn't want to depend on this as intentional behavior.
This sounds like it would be difficult to implement, but we were able to express this with nonisolated, non-Sendable protocols and default implementations carrying the bulk of the shared logic. Each platform defines a conformer - @MainActor on iOS, a global actor on android, and we rely on isolated conformance to conform our two different global actors to the shared protocols.
Better Notifications
Android recently shipped an improved notifications API, AndroidConfigV2, to better support timely notifications - even client-decrypted notifications like ours. We're early adopters of this modern notifications API.
We're excited to be on the Android platform, and we're looking forward to exploring what's unique about it.