Case Study 01 · Library-Agnostic Mobile Architecture

Google Photos: Offline-First Media Sync

Architecting a resilient, cross-platform cloud photo gallery built on a Local SSOT Database, 3-Tier Media Cache Pipeline, idempotent Persistent Outbox Queue, and opaque delta cursor sync.

Scroll Frame Budget <16ms Scroll
Capture Durability 0% Photo Loss
Asset Pipeline 3-Tier Cache
Upload Semantics Idempotent Outbox
Act I · Scope, Constraints & Device Budgets

System Requirements & Hardware Envelope

Step 1 of 5

Functional & Non-Functional Requirements

Core SLAs
  • Offline Capture With Optimistic Visibility New photos render immediately from local storage while an atomic Persistent Outbox Queue schedules background upload.
  • Instant Grid Scroll Across 100K+ Assets Zero-jank timeline scrubbing powered by inline 28B BlurHash placeholders and downsampled L1/L2 thumbnail tiers.
  • Survive OS Process Termination (SIGKILL / Jetsam) Zero reliance on volatile RAM queues; every pending upload, retry timestamp, and sync cursor lives in the Local SSOT Database.
  • Battery-Safe & Power-Aware Uploads Defer non-urgent media backup under OS Power Saver (Doze / Low Power) and back off exponentially on transient 5xx responses.

Concrete Device Resource Budgets

Mobile Envelope
  • L1 RAM Bitmap Pool: 48–64 MB Bounded in-memory LRU cache sized to ~12–15% of app heap budget; evicts cleanly under OS memory pressure warnings.
  • L2 Disk LRU Cache: 500 MB Stores encoded WebP/HEIC thumbnails and viewport-sized previews on flash storage to absorb offline browsing and cold starts.
  • Inline Preview Payload: 28B BlurHash Delivered directly inside delta sync JSON so missing tiles render a smooth color-matched gradient in <0.5ms.
  • Max Concurrent Uploads: 2 Wi-Fi / 1 Cellular Caps radio contention, thermal throttling, and socket memory overhead while maximizing resumable chunk throughput.
Act II · API, Data Model & Storage Contract

Delta Cursor Protocol & Local SSOT Schema

Step 2 of 5
Delta Cursor API Contract
O(1) Keyset Seek
GET /v1/media/delta?cursor=opaque_b64&limit=50
{
  "next_cursor": "eyJ0cyI6MTc2MzgyMDAwMCwiaWQiOiJtXzg4MjEifQ==",
  "has_more": true,
  "items": [
    {
      "media_id": "m_8821",
      "taken_at_ms": 1763820000120,
      "thumb_url": "https://cdn.example/m_8821_320w.webp",
      "blurhash": "LEHV6nWB2yk8pyo0adR*.7kCMdnj",
      "width": 4032, "height": 3024
    }
  ],
  "tombstones": ["m_7402", "m_7419"]
}
Local SSOT & Persistent Outbox Schema
Atomic SQLite WAL
Table / Column Type & Constraint Architectural Role
media_items.id TEXT PRIMARY KEY Canonical server ID or local UUID
media_items.taken_at INT64 INDEX DESC Deterministic timeline sort key
media_items.blurhash TEXT (28B) Instant zero-RTT placeholder paint
upload_outbox.client_uuid TEXT PRIMARY KEY Idempotency key preventing dupes
upload_outbox.state ENUM (4 states) PENDING | UPLOADING | SYNCED | FAILED
upload_outbox.retry_count INT + next_retry_at Drives exponential backoff + jitter
Act III · Interactive 5-Node Architecture & Chaos Simulator

Live Topology, Telemetry HUD & Chaos Switchboard

SYSTEM NOMINAL
5-Node Topology · 3-Tier Media Fetch
Step 1 / 5
UI Viewport Reactive Media Grid IDLE · <16ms 3-Tier Cache (L1/L2) RAM 64MB · Disk 500MB L1 WARM · 42 MB Local SSOT + Outbox SQLite WAL · Durable DURABLE · READY Bg Scheduler Constrained Backoff STANDBY Cloud Media & CDN Delta API & Edge CDN ONLINE · 200 OK
Step 1 / 5
L1 LOOKUP

Loading simulator...

Invariant active
Live Terminal Event Stream
Live Telemetry HUD
Real-Time
L1 RAM Cache
42 / 64 MB
L1 LRU active
Outbox Pending
0 pending
Durable SSOT queue
Network State
ONLINE
Wi-Fi · 2 slots
Latency / Backoff
11 ms
Edge p95 RTT
Chaos Engineering Switchboard
0 Active
Act IV · Zero-Dependency Contract Blueprint

Library-Agnostic Contracts & Platform Mapping

Lines Synced to Simulator
Platform Mapping Strip (Android & iOS Equivalents) Cross-Platform Reference
Agnostic Primitive Android Equivalent iOS Equivalent
Local SSOT Database Room / SQLDelight Core Data / SwiftData / GRDB
Persistent Background Scheduler WorkManager BGTaskScheduler
3-Tier Media Cache Pipeline Coil / Glide Kingfisher / SDWebImage
Reactive UI Stream StateFlow / Compose AsyncStream / Combine / SwiftUI
OS Process Termination SIGKILL (LMKD) Jetsam
Act V · Architectural Tradeoffs & Observability

Engineering Tradeoffs & Production SLOs

Step 5 of 5
Tradeoff 01 O(1) Seek

Opaque Cursor vs. Offset Pagination

Opaque Cursor

Base64-encoded (taken_at, id) keyset stays O(1) at 100K+ rows with zero drift under live inserts.

Offset Limit

New cross-device uploads shift offsets, causing duplicated or silently skipped photos in the grid.

Defense: Pair opaque cursors with server-emitted tombstones[] so remote deletions converge cleanly in one atomic local transaction.

Tradeoff 02 Crash-Proof

Persistent Outbox vs. In-Memory Retry

Persistent Outbox

SQLite WAL row persisted before UI confirmation; survives OS process termination and device reboots.

In-Memory Queue

Volatile task queues vanish immediately when camera capture triggers OS memory termination.

Defense: Storing client_uuid as an idempotency key guarantees retried uploads after a dropped ACK never create duplicate cloud assets.

Tradeoff 03 Memory Safe

Downsampled Thumbnails vs. Full-Res Decode

Downsampled Grid

Decoding 256px grid tiles uses ~256 KB per bitmap, fitting 180+ tiles inside the 48–64 MB L1 RAM cap.

Full 12MP Decode

A single 4032x3024 RGBA bitmap consumes ~48 MB—instantly evicting the cache and triggering OOM.

Defense: Always decode to target viewport dimensions first, and reserve full-resolution tiled decoding strictly for pinch-to-zoom inspection.

Tradeoff 04 Resumable

Resumable Chunked Upload vs. Single Multipart

Chunked Sessions

2 MB chunks with persisted byte offset resume cleanly across elevator dead zones and Wi-Fi handoffs.

Single Multipart

Dropping a 45 MB video at 95% forces a full restart from byte 0, burning battery and cellular quota.

Defense: Persist the resumable session URI and acknowledged byte offset alongside the Outbox row so restarts pick up from the exact last committed chunk.

Production Observability SLOs
Client Telemetry Targets
P95 Grid Frame Time Zero jank during rapid scroll
<16.6ms
L1 + L2 Cache Hit Ratio Avoids redundant CDN fetches
>92%
Outbox Orphan Rate Zero lost photos across crashes
0%