RecapsKayavak

Kayavak / Recaps / Mobile Engineering

Recaps · Volume 22

Mobile Engineering

The revision sheet of every chapter, on one page: the key ideas, the numbers worth knowing, the pitfalls and the words. Use it before an interview, after a chapter, or to find which chapter to reread. Each title opens its chapter; below each sheet are its exercises, companion and TiffinBox stage, and the misconceptions the companion corrects.

Open the volume

01

Platforms, Lifecycle and the Main Thread

Key ideas

  • The OS controls your process; one UI thread draws everything; networks and batteries are unreliable and scarce; shipped versions live on.
  • Android: activities, configuration changes, ViewModel vs SavedStateHandle, process death, WorkManager, foreground services.
  • iOS: active, inactive, background, suspended, terminated; scenes; BGTaskScheduler; state restoration.
  • Frame budgets: 16.7 ms at 60 Hz, 8.3 ms at 120 Hz; keep I/O, parsing, decoding and computation off the main thread.
  • Runtime permissions in context, least precise; private sandboxed storage.

Numbers to remember

  • Lab: 40 ms parse on the UI thread → ~7% of frames missed, worst gap 53–63 ms; on a worker → ~0%.
  • ANR after ~5 s of unhandled input on Android.

Glossary

  • Process death: the OS killing a backgrounded app's process.
  • Configuration change: rotation, locale, theme or size change that recreates Android activities.
  • Jank: visible stutter from missed frames.
  • ANR: Application Not Responding.
  • Foreground service: Android work the user is aware of, with a notification.

02

Native UI and App Architecture: Android and iOS

Key ideas

  • Declarative UI: screens are functions of state; frameworks re-run what changed (recomposition / body re-evaluation).
  • Stable identity (keys) and stable, equal inputs let frameworks skip work.
  • Unidirectional data flow: ViewModel owns immutable UI state; UI sends events; repositories hide data sources; local DB as source of truth.
  • Kotlin coroutines and Flow with structured scopes; Swift async/await, actors, main actor, Sendable.
  • Persistence: Room/DataStore/Keystore; SwiftData/Core Data/UserDefaults/Keychain; test migrations.
  • Navigation with deep links; DI for testability; feature and core modules.

Numbers to remember

  • Lab: no keys or unstable callbacks → 1,000 re-renders per change; keys + stable inputs → 1.

Glossary

  • Recomposition: Compose re-running composables whose inputs changed.
  • Stable type: a type whose equality Compose can rely on to skip.
  • StateFlow: a Kotlin observable state holder.
  • Actor: a Swift type serialising access to its state.
  • UDF: unidirectional data flow.

03

Cross-Platform Frameworks

Key ideas

  • Every approach chooses where the shared/native boundary sits; crossing it costs time.
  • React Native: JS/TS with native views; New Architecture (JSI, Fabric, TurboModules, Codegen); Hermes; Expo.
  • Flutter: Dart widgets drawn by its own engine; platform channels and FFI.
  • Kotlin Multiplatform: shared Kotlin logic; native UI or Compose Multiplatform.
  • PWAs and web shells for content-heavy apps.
  • Choose by team skills, UI fidelity needs, device APIs, performance and upgrade cost; always budget native code.

Numbers to remember

  • Lab: direct 0.23 µs; JSON bridge 34.7 µs (150×); batched 1.17 µs; ~480 bridge calls per 16.7 ms frame.

Glossary

  • JSI: JavaScript Interface, direct JS–C++ calls in React Native.
  • Fabric: React Native's new renderer.
  • TurboModules: lazily loaded native modules called via JSI.
  • Platform channel: Flutter's messaging between Dart and platform code.
  • expect/actual: KMP's mechanism for platform-specific implementations.

04

Networking on Mobile Networks

Key ideas

  • Latency and round trips dominate; mobile RTTs are high and variable; radios wake slowly; networks change and drop.
  • Reuse connections; HTTP/2 multiplexing; HTTP/3/QUIC for loss, 0-RTT and migration; TLS resumption, DNS caching.
  • Screen-shaped APIs, cursor pagination, prefetching, partial responses, compression, binary formats for parsing and schemas.
  • Evolve APIs additively for old app versions; idempotency keys on writes.
  • HTTP caching, ETags, app-level caches with background refresh; CDNs.
  • Mobile-appropriate timeouts, safe retries with jitter, connectivity-aware queues.
  • Images sized for slots in modern formats; real-user network telemetry by percentile.

Numbers to remember

  • Lab: 20 requests at 600 ms RTT: 24.1 s (new connections) vs 1.2 s (one request); JSON 4,640 B → 264 B gzipped.
  • New HTTPS connection over TCP: ≥ 3 RTTs before data (TCP, TLS 1.3, request).

Glossary

  • RTT: round-trip time.
  • Keep-alive: reusing a TCP connection for several requests.
  • QUIC: UDP-based transport under HTTP/3.
  • 0-RTT: sending data in the first flight on resumed QUIC/TLS connections.
  • BFF: a backend shaped for a specific client.

05

Offline-First and Sync

Key ideas

  • Local database as the UI's source of truth; local-first writes; pending operations with idempotency keys; background sync.
  • Push operations in order; pull deltas since server-issued cursors; tombstones for deletes.
  • Conflict policies: whole-document LWW (avoid), per-field LWW, server-authoritative rules, operation merges, CRDTs, ask the user.
  • Never trust device clocks for ordering; server versions or hybrid logical clocks.
  • Old app versions and schemas sync too; resumable initial sync.
  • Visible pending/failed states; local data security; server re-checks everything.

Numbers to remember

  • Lab: whole-document LWW lost edits in 90% of syncs; per-field LWW 0% with correct clocks, 12% with a 30-minute skew.

Glossary

  • Offline-first: designing the app to work locally and sync opportunistically.
  • Pending operations queue: a device-side outbox of user actions.
  • Cursor: a server-issued position for delta sync.
  • Tombstone: a record that something was deleted.
  • CRDT: conflict-free replicated data type.

06

Performance and Memory

Key ideas

  • Users notice startup, smoothness and crashes; memory problems show as background kills and OOM crashes.
  • Startup: process and code loading, app initialisation, first screen; lazy init, Baseline Profiles, cached first screens; budgets in CI.
  • Size: App Bundles, R8, resource shrinking, thinning; audit SDKs.
  • Memory: bitmaps are pixels × 4; decode at display size; bounded caches; respond to memory warnings; find leaks with LeakCanary and Instruments.
  • Lazy lists with keys; flat layouts; cheap animations.
  • Field metrics (Android vitals, MetricKit) by device class and version.

Numbers to remember

  • Lab: 12 MP photo → 48 MB decoded; ¼-scale decode 3 MB in 36 ms vs 104 ms; 50 full-size cards 2.4 GB.
  • Play bad-behaviour thresholds ≈ 1.09% user-perceived crash rate, 0.47% ANR rate (at the time of writing).

Glossary

  • Cold / warm / hot start: from no process / recreated UI / resumed UI.
  • Baseline Profile: a list of hot code compiled at install time.
  • inSampleSize / thumbnail decoding: decoding images at reduced resolution.
  • Retain cycle: mutual strong references preventing deallocation (ARC).
  • MetricKit: Apple's on-device performance and diagnostics reports.

07

Background Work, Push and Battery

Key ideas

  • Radio promotion and tail make many small transfers expensive; batch, coalesce, push, prefetch on Wi-Fi/charging.
  • Android: Doze, App Standby buckets, WorkManager with constraints, foreground services with types, inexact alarms.
  • iOS: suspension; BGTaskScheduler, background URL sessions, rate-limited background push, reviewed modes.
  • Push: tokens and refresh, payloads with deep links, priority, collapse keys, TTL, channels/categories, permission in context, server-side dedupe and limits.
  • Live tracking: Live Activities (iOS) and ongoing progress notifications (Android), updated by push, with meaningful updates only.
  • Location matched to need; approximate in the customer app; foreground service or background mode only for the rider during deliveries; geofences.

Numbers to remember

  • Model (assumed LTE values): polling every 30 s ≈ 366 mWh/h; polling + per-minute analytics ≈ 539 mWh/h (~3% battery/h); batching + push ≈ 43 mWh/h.
  • Push payloads ≈ 4 KB.

Glossary

  • Doze: Android's idle mode restricting background activity.
  • App Standby bucket: Android's usage-based priority class for background work.
  • FCM / APNs: Firebase Cloud Messaging / Apple Push Notification service.
  • Collapse key: replaces earlier undelivered messages of the same kind.
  • Live Activity: iOS's live lock-screen and Dynamic Island view of an ongoing event.

08

Mobile Security

Key ideas

  • The client is untrusted; anything in the app is public; the server enforces everything.
  • Tokens in Keystore/Keychain-protected storage; sensitive caches private, encrypted if needed, wiped on sign-out; nothing sensitive in logs, clipboard or screenshots.
  • Sign-in via the system browser with authorization code + PKCE; passkeys; rotating refresh tokens.
  • HTTPS only; pin SPKI with backups when the risk justifies it; know platform CA trust rules.
  • Verified App Links/Universal Links; untrusted deep-link input; private components; careful WebViews.
  • Attestation (Play Integrity, App Attest) as an abuse signal; obfuscation as a speed bump.
  • Privacy: minimal data, honest declarations, SDK inventory; MASVS/MASTG as the checklist.

Numbers to remember

  • Lab: interceptor read OTP and address without pinning; pinned client refused; embedded key found in 0.2 ms.

Glossary

  • SPKI pin: a hash of a server's public key the app accepts.
  • PKCE: proof key for code exchange, protecting the authorization code.
  • App Links / Universal Links: domain-verified deep links.
  • Attestation: a platform-signed statement about an app's and device's integrity.
  • MASVS: OWASP Mobile Application Security Verification Standard.

09

Testing, Release and Observability

Key ideas

  • Shipped builds can't be rolled back; test more, release gradually, keep risk switchable from the server.
  • Test pyramid: unit, integration, UI, screenshot, device farms, manual on real modest devices; mobile-specific scenarios (process death, offline, permissions, upgrades).
  • CI builds, signing keys in secret managers, increasing build numbers, mapping files and dSYMs uploaded.
  • Store tracks, review, staged rollouts (Play) and phased release (App Store, 7 days), halt criteria written in advance, release trains.
  • Feature flags, remote config, kill switches, OTA JS updates within rules, in-app update prompts; minimum versions as a last resort.
  • Field observability: symbolicated crashes, ANRs/hangs, non-fatals, performance, schema'd analytics, release-health dashboards per version.

Numbers to remember

  • Simulation: staged rollout limited a bad build to ~2,500 of 50,000 users; 20% of users still on the bad version 7 days after the fix (assumed adoption).
  • Apple phased release: 1, 2, 5, 10, 20, 50, 100% over 7 days.

Glossary

  • Staged rollout / phased release: gradually increasing the share of users receiving a version.
  • Symbolication: mapping obfuscated or stripped stack traces back to source.
  • Remote config: server-delivered settings that change app behaviour without a release.
  • Release train: releases on a fixed schedule.
  • Crash-free users/sessions: release-health metrics per version.