Architecting Server-Driven UI (SDUI) in Jetpack Compose at 60fps
Shipping mobile features across multiple international markets exposes a fundamental bottleneck in traditional client engineering: the app store release cycle. When tier cards, regional pricing breakdowns, promotional banners, and compliance disclosures are hardcoded in client binaries, every layout experiment or regional launch has to wait on an app release and a multi-week adoption tail.
Server-Driven UI (SDUI) solves this by letting the server define what screen structure and components to render while the mobile client owns native rendering, state transitions, caching, and frame-rate guarantees.
Here is how I architect production SDUI systems on Android using Kotlin and Jetpack Compose without turning the mobile app into a slow, network-bound shell.
Key Takeaways
- Treat SDUI payloads as versioned, schema-validated contracts (Protobuf or strict JSON) where unknown node types degrade gracefully instead of crashing the screen.
- Map server nodes to pure, stateless Jetpack Compose design-system primitives with stable keys so Compose skips unnecessary recompositions.
- Route all user interactions through a typed
SduiActionDispatcherrather than embedding imperative callbacks inside UI nodes. - Pair SDUI with a local disk cache (
stale-while-revalidate) and optimistic state mutations so screens render on the first frame even on degraded networks.
1. Designing Forward-Compatible SDUI Contracts
The biggest risk in any Server-Driven UI system is schema drift: a backend service deploys a new component type (PROMO_COUNTDOWN_BANNER_V2) to users running a six-month-old Android binary that has never heard of it.
If your client deserializer throws an unhandled exception on unknown enum values, a single backend rollout can take down an entire flow. Instead, every SDUI node should deserialize into a sealed hierarchy with an explicit UnknownNode fallback:
sealed interface SduiNode {
val id: String
val analyticsTag: String?
data class HeroBanner(
override val id: String,
override val analyticsTag: String?,
val title: String,
val subtitle: String?,
val primaryCta: SduiAction?
) : SduiNode
data class TierCard(
override val id: String,
override val analyticsTag: String?,
val tierName: String,
val formattedPrice: String,
val benefits: List<String>,
val selectAction: SduiAction
) : SduiNode
data class Unknown(
override val id: String,
override val analyticsTag: String? = null,
val rawType: String
) : SduiNode
}When the validator encounters SduiNode.Unknown, it logs a non-fatal schema telemetry event and quietly omits (or renders a compact fallback for) that single subtree while keeping the rest of the screen intact.
2. Dynamic View Composition at 60fps in Jetpack Compose
A common mistake in Compose SDUI engines is recursively rendering raw JSON maps inside a LazyColumn without stable keys or immutable models. When the Compose compiler cannot prove that a node model is stable, every scroll frame triggers cascading recompositions and dropped frames.
To maintain a locked 60fps:
- Convert network DTOs into
@Immutabledomain nodes on a background dispatcher (Dispatchers.Default) before handing them to Compose. - Always supply deterministic
keyandcontentTypelambdas toLazyColumn.
@Composable
fun SduiScreenContent(
nodes: List<SduiNode>,
onAction: (SduiAction) -> Unit,
modifier: Modifier = Modifier
) {
LazyColumn(modifier = modifier.fillMaxSize()) {
items(
items = nodes,
key = { node -> node.id },
contentType = { node -> node::class.simpleName }
) { node ->
SduiNodeRenderer(
node = node,
onAction = onAction
)
}
}
}
@Composable
private fun SduiNodeRenderer(
node: SduiNode,
onAction: (SduiAction) -> Unit
) {
when (node) {
is SduiNode.HeroBanner -> HeroBannerPrimitive(
title = node.title,
subtitle = node.subtitle,
onCtaClick = { node.primaryCta?.let(onAction) }
)
is SduiNode.TierCard -> TierCardPrimitive(
tierName = node.tierName,
formattedPrice = node.formattedPrice,
benefits = node.benefits,
onSelect = { onAction(node.selectAction) }
)
is SduiNode.Unknown -> Unit // Safely skipped after schema telemetry
}
}Passing contentType to LazyColumn is critical: it allows Jetpack Compose to reuse composition slots across items of the same SDUI component type as the user scrolls through long feeds.
3. Typed Action Dispatch & Optimistic State
In a clean SDUI architecture, components never execute navigation or network mutations directly. Instead, server payloads attach declarative SduiAction descriptors to interactive elements:
sealed interface SduiAction {
data class Navigate(val deeplink: String) : SduiAction
data class MutateState(
val endpoint: String,
val payload: Map<String, String>,
val optimisticPatchId: String?
) : SduiAction
data class TrackEvent(
val eventName: String,
val properties: Map<String, String>
) : SduiAction
}When a user taps a membership enrollment toggle or tier selection button, the ViewModel intercepts SduiAction.MutateState, applies an optimistic patch to the local StateFlow<List<SduiNode>> immediately, and dispatches the network call in the background. If the network request fails, the client rolls back the snapshot and surfaces an inline retry action.
4. Caching & Degraded Network Resilience
If an SDUI screen shows a blank loading spinner every time the user opens the app on spotty cellular connectivity, you have traded developer velocity for user frustration.
Every production SDUI pipeline I build uses a three-tier loading strategy:
- In-Memory Snapshot Cache: Instant 0ms render when navigating back and forth within a session.
- Disk-Backed Payload Cache (
Room/DataStore): Renders the last validated screen tree immediately on cold start while a background coroutine fetches fresh layout definitions (stale-while-revalidate). - Deterministic Fallback Templates: Bundled offline-safe fallback nodes for critical flows so core user actions remain functional even when the device is completely offline.
5. Observability: Measuring What Matters
Because the server can change screen layouts at any time without a client code change, client observability has to monitor SDUI health in real time:
- Schema Validation & Fallback Rate: Spikes in
SduiNode.Unknownindicate a contract mismatch between backend and older client versions. - Deserialization & Time-to-First-Layout: Tracked at p50, p95, and p99 across flagship and budget Android devices.
- Frame Budget & Janky Frames: Measuring frame timing per SDUI screen route so heavy server-configured layouts are caught before full rollout.
When built with strict schema validation, immutable Compose models, and offline-first caching, Server-Driven UI gives teams the best of both worlds: instant global rollout velocity and the 60fps tactile feel of native Android.
Related posts.
Jetpack Compose Architecture Patterns That Scale
Practical architecture patterns for Jetpack Compose that work in real production Android apps at scale, covering state hoisting, navigation, and modularity.
How I Built AgentDroid: Fusing Android Accessibility Trees with Multimodal Vision
Inside the architecture of AgentDroid - an open-source Android AI agent framework for self-healing UI automation, multimodal screen grounding, and automated Appium codegen.
Ad Injection Strategies for Short-Form Video Feeds: Timing, Frequency, and Impression Recovery
How ad injection works in short-form video feeds: timing heuristics, frequency capping, impression recovery, and the trade-offs behind monetization.