---
title: "Rewriting the CloudX SDK Core in Rust"
description: "Why CloudX moved the ad logic of its Android and iOS SDKs into one shared Rust core, how a prototype settled the decision, and what we measured in the first beta."
url: "https://www.cloudx.ai/posts/one-sdk-core-in-rust"
published: "2026-11-30T12:00:00-05:00"
authors:
  - "Andrew Konecny"
category: "Engineering"
---

# Rewriting the CloudX SDK Core in Rust

One Rust core now keeps our Android and iOS SDKs from drifting apart.

*By Andrew Konecny · Published Nov 30, 2026*

*Prototype first, argue later: how we chose Rust for our SDK core. The Android shell in Kotlin and the iOS shell in Objective-C both exchange events and commands with a single shared Rust core, so both platforms make the same decisions.*

Our Android and iOS SDKs were built from the same spec by people who talk to each other every day. When we sat down and compared them closely, we still found somewhere between 80 and 90 places where a publisher could see them behave differently. For example: different error codes for the same failure, a banner resuming refresh one interval later on one platform, and a retry on Android but not on iOS.

None of these was deliberate. Each came from a reasonable local choice, in two codebases that stayed in sync only when someone noticed a difference.

Today, the CloudX SDK beta on both platforms runs its ad logic on one shared core, written in Rust.

## Where Steffan left off

In July, my colleague Steffan Chartrand wrote about [how cross-platform mobile engineering works at CloudX](https://www.cloudx.ai/posts/how-cross-platform-mobile-engineering-works-at-cloudx). Our engineers had stopped staying in their platform lanes. An Android engineer could make a well-scoped change on iOS, a specialist would review it, and a fix on one SDK became a pointer to what needed checking on the other.

That way of working is what made this project possible. You can’t merge two implementations into one unless the team knows both well enough to say what “the same behavior” means, case by case.

Steffan’s post also contains the sentence that stuck with me: many components were “implemented nearly identically” on both platforms, and bugs were often mirrored. The team worked across platforms, but the code was still written twice.

## My background

I’ve spent the past decade in ad tech, working on monetization and user acquisition from both the product and the engineering side. I started as an engineer writing SDK code, went on to manage engineering teams at Unity, and then led product and engineering at Playgap before joining CloudX. The thread through all of it has been SDKs: how fast they start, how stable they are, and what that does to revenue.

Some of those SDKs ran on a shared core written in TypeScript: one body of logic for every platform, which could be updated without shipping a new SDK. That approach has real benefits.

It also has costs. A core in a scripting language brings a runtime with it, and you pay for that at startup, in memory, and every time a call crosses into native code. A core that updates itself has to be fetched over the network when it changes, and that request sits in front of the first ad. We’re a guest inside someone else’s app, so those costs matter.

## Why Rust

We wanted the core as close to the hardware as we could get it without giving up memory safety. We looked at Kotlin Multiplatform and other cross-platform options, which would have kept us in languages the team already knew. We decided against them in favor of the option with the highest performance ceiling, even though it was the less familiar one.

The core compiles to machine code on both platforms, with no virtual machine and no garbage collector, and we choose what is allocated and when. The compiler also rejects the mistakes that usually come with that control, such as using memory after it has been freed or sharing it unsafely between threads. Our code runs inside a publisher’s app, so a crash in our code crashes their app. We wanted speed and safety.

Instead of weeks of debate about what each option would probably do, we started with a one-day spike: one self-contained piece of the SDK, rewritten in Rust on the side, to check that it would work for us. It did, so we kept going.

The spike also settled a question we would otherwise have argued about. The cautious plan was a dual mode, with the native implementation and the Rust one living side by side behind a remote switch so we could A/B test them. We realized quickly that we didn’t want it. Carrying both implementations made the numbers worse for each, and a remotely configured split was hard to measure cleanly. We chose a straight before-and-after comparison instead.

Over the next week we built a first version that covered effectively the whole core, benchmarked it on real devices, and shipped it in a non-public release to a single publisher’s app. The full build, at parity with the previous SDK, took about one more week.

Most of the second week went into checking the result. The native SDKs were our oracle: we recorded their sessions as golden files, and the core had to replay every one and make the same decisions. An AI agent coordinated subagents to build and run a real-device harness that checked the two SDKs behaved the same on actual phones. That build is the beta now running in the same app. Anthropic, writing about [moving its own API to Rust](https://www.anthropic.com/research/migrating-api-to-rust), put it well: “Verification, not generation, had become the bottleneck.”

Having numbers from real devices made the discussions shorter and more concrete.

Rewriting things in Rust is very much the Zeitgeist. Anthropic’s move landed the same season as ours, and like us with dual mode, they found a partial port cost about as much as it gained. Still, I’m wary of doing anything because it’s in the air. What changed is cost. A couple of years ago, a team our size rewriting the core of two production SDKs in a third language, while still shipping both, would have been hard to defend. The expensive parts are now the parts AI tooling is good at: porting well-specified behavior, generating the glue between languages, and checking the result against the old system. It is also why a prototype could come before the debate.

## How it works

The core makes the decisions; the platform carries them out.

*The core makes the decisions; the platform carries them out. The platform shell, written in Kotlin on Android and Objective-C on iOS, owns network calls, partner SDKs, views, timers, storage, and publisher callbacks. It reports events such as a bid response arriving, an ad closing, or a timer firing to the shared Rust core. The core updates its state and returns commands such as load this adapter, start this timer, or tell the publisher the ad is ready. The core makes no network calls, starts no threads, and never reads the clock.*

The Kotlin and Objective-C layers still own everything that touches the device. Network calls, partner SDKs, views, timers, storage, and every callback a publisher sees are native code, and the public API hasn’t changed. When something happens, such as a bid response arriving, an ad closing, or a timer firing, the native side reports it to the core as an event. The core updates its state and hands back commands: load this adapter, start this timer, tell the publisher the ad is ready.

Three rules for the core:

- **One schema.** The messages that cross the boundary are defined once, and the Rust, Kotlin, and Objective-C code that reads and writes them is generated from that definition.
- **No side effects in the core.** It makes no network calls, starts no threads, and never reads the clock. Time is something the platform tells it.
- **Same input, same output.** A recorded session can be replayed through the core and must produce exactly the same decisions, on a laptop, on Android, or on iOS.

## Laws instead of more tests

Because the core is deterministic and does nothing on its own, we can drive it through every order of events a platform could send and check what comes out.

We write the publisher contract down as laws: properties that must hold for every order of events, not only the orders an example test happens to try. Each `load()` gets at most one load callback. Each show ends with exactly one callback. Nothing reaches the publisher after `destroy()`. Revenue is paid at most once per show.

*Laws checked on every order of events. The publisher contract is written as laws, such as: each load gets at most one load callback, each show ends with exactly one callback, nothing reaches the publisher after destroy, and revenue is paid at most once per show. An explorer drives the shared core through every legal sequence of events from 44 starting states, about 180,000 sequences for fullscreen ads in about six seconds on a laptop. When a law breaks, it prints the shortest sequence that breaks it. Simplified example: one terminal callback per show was broken by the sequence ad shown, ad pulled by the quality check, network error, which gave both a hidden and a display failed callback for one show.*

An explorer then walks every legal sequence of events, up to a fixed depth, from 44 starting states: loaded, showing, expired and reloading, app in the background, and so on. For fullscreen ads that is about 180,000 sequences, and it finishes in about six seconds on a laptop, so it runs on every pull request. When a law breaks, it prints the shortest sequence that breaks it.

On its own, it rediscovered an Android case we had introduced in the rewrite: if our ad-quality check pulled an ad while it was on screen and the ad network then reported an error, the publisher got two endings for one show, a hidden callback and a failed-to-display callback. Audits of the rest of the core with the same approach surfaced more edge cases, several of them inherited from the native SDKs we replaced. Their fixes ship in follow-up builds.

We expect laws to replace many example-based unit tests. A law states the contract once and checks it against every order of events, where a unit test tries one order. And because the core is shared, each law protects Android and iOS at once.

## What it gives us

*Before and after. Before: one spec was implemented twice, as Android logic in Kotlin and iOS logic in Objective-C, and the two drifted into 80 to 90 publisher-visible differences. After: the Android shell and the iOS shell both call one shared Rust core, which makes the same decisions from the same inputs on both platforms.*

The two SDKs now behave the same, because auctions, caching, refresh, expiry, retries, consent decoding, and telemetry are the same code. A class of fringe issues that only ever showed up on one platform can no longer happen. What still needs checking per platform is the part that should differ: rendering, partner adapters, and how each OS reports what’s on screen.

Changes are also made once. A fix, a feature, or an optimization in the core ships to both platforms together, with no second implementation to update.

## What we’ve measured

The goal for the first round was to match the native SDKs or beat them.

### Startup and stability

On Android, in one game running the beta in production, median SDK startup went from **1.82 s** to **1.56 s** compared with the last native-only build that game ran. The share of startups where a partner SDK timed out during initialization fell from **9.4%** to **6.8%**. Fill, show rate, and show failures stayed level.

*Production read from one Android game, comparing the Rust core beta with the last native-only build that game ran. Median SDK startup went from 1.82 seconds to 1.56 seconds. The share of startups where a partner SDK timed out during initialization went from 9.4% to 6.8%. Fill, show rate, and show failures stayed level. The two builds ran at different times on different app versions, not as a randomized split, and results from one app may not generalize.*

On iOS we expected less headroom. Objective-C is fast, and that SDK was already tight. Even with the core’s own startup added, initialization and first load on our test devices matched native.

We saw no crashes in our own code on either platform. This is one app, and results elsewhere will vary, but the direction matches what we benchmarked on real devices before release. An SDK that is ready sooner, with more of its demand partners ready, can fill more of the requests made early in a session.

### Memory, measured locally

Tuning used to mean making the same careful change twice, in two languages, and proving both still matched. That cost was high enough that some inefficiencies were simply left alone. With one core, they became worth going after, and the first ones landed within days of the beta. We measured each on our test devices and on a desktop build of the same core.

A new core instance now holds **12 KB** before any ad loads, down from **67 KB**. Most of the old figure was space reserved for commands that rarely needed it.

A second pass went after layout rather than data. A heap profile showed that much of what the core kept alive was empty space and copies. Large per-ad state sat inline in hash tables, so an empty slot cost as much as a live ad. The buffer that hands commands to the platform kept a copy of every batch and never shrank, so one large batch set the memory floor for the whole session. Our recordings suggested batches of about 2.5 KB; captures from real devices showed 27 to 176 KB. Fixing the layout cut what the core holds in a typical session from **83 KB** to **53 KB**, and by 22 to 36% across the states we measured. Behavior did not change: every golden recording still replays the same.

The largest saving was on iOS, in code older than the rewrite. Each auction left a 26 KB record behind that was never freed; it now leaves 4 KB. Publishers rarely hold one ad: they keep several formats and placements loaded, often at once, and a long session runs auction after auction. For a single banner refreshing every 30 seconds, memory growth dropped from about **3 MB** an hour to about **0.5 MB**.

*Memory measured locally, before and after the first memory work. A new core instance holds 12 KB instead of 67 KB. The core keeps 53 KB alive in a typical session instead of 83 KB. On an iPhone, one banner refreshing 20 times leaves 82 KB of auction records instead of 527 KB. Lower is better.*

## What comes next

The memory work above ships in follow-up builds. We expect larger gains from the next step: the data itself, meaning how the core holds what it needs to deliver an ad and how that data moves between the core and the platform. Every gain there reaches Android and iOS in the same release.

## Try it

The Rust core is available now in the beta releases of the CloudX SDK for [Android](https://docs.cloudx.io/en/android/changelog) and [iOS](https://docs.cloudx.io/en/ios/changelog). The beta label is a precaution ahead of the holiday season; it becomes the regular release for all publishers after that. If you’d like to integrate it before then, talk to your CloudX account manager first, or reach us at [hello@cloudx.io](mailto:hello@cloudx.io).
