Skip to main content
BLUEPRINT #01Mobile & Offline Architecture

Design Mobile News Feed with Offline-First Architecture

Target AWS Architecture:DynamoDBS3ElastiCacheCloudFront
10-Stage Structure:1. Requirements→2. Sizing→3. Topology→4. Data Model→5. AWS Topology→6. Deep-Dive→7. Failures→8. SRE Playbooks

1. Problem Statement & Scope

System Mission

Design a state-of-the-art, offline-first mobile news feed client and backend synchronization architecture delivering instantaneous (<16Β ms< 16\text{ ms}) feed rendering from local persistent cache, robust background delta synchronization via GraphQL/Protobuf, optimistic mutation pipelines with deterministic rollback, and intelligent battery/network-aware media prefetching.

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

Functional Requirements

  1. Zero-Latency Feed Rendering: Cold launch renders cached feed items from local SQLite storage instantly without waiting for network I/O.
  2. Bidirectional Delta Synchronization: Exchange only mutated/new posts since the client's last synchronized cursor/timestamp, including soft-deleted tombstone records.
  3. Optimistic Local Mutations: Post creations, likes, comments, and bookmark actions immediately update local SQLite and UI state; mutations queue in a durable local for background replay.
  4. Adaptive Media Prefetching: Prefetch high-resolution images/videos on unmetered high-speed WiFi; restrict prefetching to low-resolution WebP/AVIF thumbnails on cellular metered connections.
  5. Conflict Resolution & Monotonic Versioning: Resolve server-client data collisions deterministically using version vectors and monotonic entity timestamps.

Non-Functional Requirements (SLAs/SLOs)

  • App Cold Start Time-To-Content (TTC): <50Β ms< 50\text{ ms} read latency from local SQLite (P99P99).
  • UI Smoothness & Frame Rate: 120 FPS (8.33Β ms8.33\text{ ms} frame budget) on modern 120Hz ProMotion/LTPO displays; zero main-thread database or network disk I/O.
  • Bandwidth Consumption: Delta sync payloads ≀5Β KB\le 5\text{ KB} per poll (>90%> 90\% compression vs full JSON payload).
  • Battery & Thermal Budget: Minimized background wakeups utilizing WorkManager / BGAppRefreshTask; zero battery drain while app is suspended.
  • Offline Durability: Local mutation queue survives app crashes, OS process kills, and device reboots.

Out-of-Scope

  • Peer-to-peer (P2P) mesh feed distribution (e.g. Bluetooth LE mesh feed sharing).
  • Live real-time video stream broadcasting (covered in YouTube / Live Streaming blueprints).

2. Capacity & Scale Estimation

Device & Traffic Scale

  • Mobile Active Installs: 200Β Million200\text{ Million} devices (50Β Million50\text{ Million} DAU).
  • Daily Feed Refreshes: Average 20Β syncs/user/dayβ€…β€ŠβŸΉβ€…β€Š1Β BillionΒ DeltaΒ Syncs/Day20\text{ syncs/user/day} \implies \mathbf{1\text{ Billion Delta Syncs/Day}}. AverageΒ SyncΒ QPS=10986,400Β sβ‰ˆ11,574Β syncs/secΒ (Peak:Β 35,000Β syncs/sec)\text{Average Sync QPS} = \frac{10^9}{86,400 \text{ s}} \approx 11,574 \text{ syncs/sec (Peak: } 35,000\text{ syncs/sec)}

Bandwidth & Storage Calculations

  • Full Feed Payload vs Delta Sync Payload:
    • Full Feed Page (20 posts with author metadata): β‰ˆ60Β KB\approx 60\text{ KB}.
    • Delta Sync Payload (Protobuf delta with cursor): β‰ˆ4Β KB\approx 4\text{ KB} (93.3%93.3\% cellular data savings). DailyΒ IngestionΒ NetworkΒ EgressΒ (Delta)=109Γ—4Β KB=4Β TB/dayβ‰ˆ370Β MbpsΒ (Peak:Β 1.1Β Gbps)\text{Daily Ingestion Network Egress (Delta)} = 10^9 \times 4\text{ KB} = 4\text{ TB/day} \approx \mathbf{370\text{ Mbps (Peak: } 1.1\text{ Gbps)}}
  • Mobile Local Storage Budget:
    • Store max 500 cached posts in local SQLite: 500Γ—2Β KB=1Β MB500 \times 2\text{ KB} = 1\text{ MB}.
    • Local image/thumbnail LRU disk cache: 150Β MBΒ cappedΒ limit\mathbf{150\text{ MB capped limit}}.

3. High-Level Architecture & AWS Component Mapping

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

Component Responsibility Breakdown

Layer / ComponentTechnologyRole & Architectural Guarantees
Local Persistent StoreSQLite / Android Room / iOS CoreDataSingle Source of Truth. The UI never observes network responses directly; it binds reactively to local database tables.
Mutation State MachineLocal SQLite QueueManages lifecycle of offline mutations (QUEUED β†’\to IN_FLIGHT β†’\to COMMITTED / FAILED_RETRY).
Cloud Delta GatewayAWS AppSyncManaged GraphQL gateway supporting delta synchronization, automatic Conflict Detection & Resolution (Optimistic Concurrency / Auto-Merge).
Backend Data Store storage maintaining post data and a dedicated () Delta Table with -based tombstone tracking.
Media Delivery CDNAmazon CloudFrontEdge caching of resized, compressed WebP/AVIF images with Cache-Control: public, max-age=31536000, immutable.

4. API Interface Design & Wire Protocols

1. GraphQL Delta Sync Query

graphql
query SyncFeedTimeline($lastSyncCursor: AWSTimestamp!, $limit: Int!) {
  syncFeedPosts(lastSync: $lastSyncCursor, limit: $limit) {
    items {
      id
      authorId
      authorName
      content
      mediaUrl
      likesCount
      commentsCount
      userHasLiked
      version
      _deleted
      updatedAt
    }
    nextToken
    newSyncCursor
    serverTimestamp
  }
}

2. Optimistic Like Mutation

graphql
mutation OptimisticLikePost($postId: ID!, $clientMutationId: String!, $version: Int!) {
  likePost(input: {
    postId: $postId
    clientMutationId: $clientMutationId
    expectedVersion: $version
  }) {
    postId
    likesCount
    userHasLiked
    version
    updatedAt
  }
}

Mutation Response: 200 OK

json
{
  "data": {
    "likePost": {
      "postId": "post_881293a",
      "likesCount": 142,
      "userHasLiked": true,
      "version": 6,
      "updatedAt": 1718000045120
    }
  }
}

5. Data Models & Storage Architecture

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

Local SQLite Schema (mobile_feed_database.db)

sql
-- Cached Feed Posts Table
CREATE TABLE local_feed_posts (
    post_id TEXT PRIMARY KEY,
    author_id TEXT NOT NULL,
    author_name TEXT NOT NULL,
    content TEXT NOT NULL,
    media_url TEXT,
    likes_count INTEGER NOT NULL DEFAULT 0,
    user_has_liked INTEGER NOT NULL DEFAULT 0, -- 0 = false, 1 = true
    server_version INTEGER NOT NULL DEFAULT 1,
    sync_status INTEGER NOT NULL DEFAULT 1,     -- 1=SYNCED, 2=OPTIMISTIC_DIRTY, 3=FAILED
    is_deleted INTEGER NOT NULL DEFAULT 0,
    updated_at INTEGER NOT NULL
);
CREATE INDEX idx_feed_sort ON local_feed_posts(updated_at DESC);

-- Durable Mutation Queue Table
CREATE TABLE local_mutation_queue (
    mutation_id TEXT PRIMARY KEY,
    post_id TEXT NOT NULL,
    action_type TEXT CHECK (action_type IN ('LIKE', 'UNLIKE', 'CREATE_POST', 'COMMENT')),
    payload_json TEXT NOT NULL,
    state TEXT CHECK (state IN ('QUEUED', 'IN_FLIGHT', 'FAILED_RETRY')),
    retry_count INTEGER NOT NULL DEFAULT 0,
    created_at INTEGER NOT NULL
);
CREATE INDEX idx_mutation_state ON local_mutation_queue(created_at ASC);

Part 2: Production Deep-Dive Locked1 Coin = 24 Hours

Unlock Complete Architecture & Production Runbooks

Your Balance:40 Coins

You have explored the free architectural preview (~41%). Spend 1 Coin to unlock the remaining 6 production deep-dive sections for a full 24 hours.

Sections Included in This 24-Hour Pass:
6. Core Algorithms & Deep-Dive Workflows
7. Architectural Trade-Off Matrix & Primitive Links
8. Critical Failure Modes, Resiliency & Edge Cases
9. Production Pitfalls & Anti-Patterns (The "Top 5 Gotchas")
10. Production Runbook & Observability Guide
11. System Design Interview Rubric & Deep-Dive Strategy
Keeps page unlocked for exactly 24 hoursSpend coins to fund LLM & compute infrastructure