Skip to main content
BLUEPRINT #04Mobile & Offline Architecture

Design Mobile Paging & Infinite Scrolling Library Architecture

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 memory-efficient, flicker-free, bidirectional mobile pagination and prefetching library architecture capable of rendering lists with millions of items at 120 FPS, utilizing opaque cursor-based keyset pagination, database-backed single source of truth mediation, asynchronous UI diffing, and bounded RAM page eviction.

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

Functional Requirements

  1. Cursor-Based Keyset Pagination: Request sequential pages using opaque base64 cursor tokens containing composite (e.g. (timestamp, item_id)), preventing missing or duplicate items during real-time insertions.
  2. Predictive Boundary Prefetching: Trigger asynchronous background page fetches when the user scrolls within PP items of list boundary (e.g. prefetch_distance = 5).
  3. Database-Mediated Single Source of Truth: Network responses are written directly to local SQLite; UI observes reactive database streams (Room PagingSource / CoreData NSFetchedResultsController).
  4. Memory Bounding & Eviction: Cap maximum items loaded in memory (e.g. max_size = 200); automatically drop distant scrolled-out pages from RAM while preserving scroll position via placeholders.
  5. Bidirectional Scrolling: Seamlessly support scrolling both down (older items) and up (newer items) in infinite feed timelines.

Non-Functional Requirements (SLAs/SLOs)

  • UI Frame Rate Budget: Strict 120 FPS (8.33Β ms8.33\text{ ms} render budget); zero disk I/O, database queries, or diff computations executed on the main UI thread.
  • Client Memory Footprint: Local RAM heap usage bounded to <30Β MB< 30\text{ MB} regardless of whether the user scrolls through 100 or 100,000 items.
  • Backend Query Latency: Cursor seek query latency <5Β ms< 5\text{ ms} (P99P99) in (O(1)O(1) composite index seek).
  • Network Resilience: Granular load state tracking (IDLE, LOADING, ERROR) per boundary (prepend, append, refresh) with inline retry capabilities.

Out-of-Scope

  • Virtual list rendering for web HTML DOM tree optimizations (e.g. react-window DOM virtualization).
  • Server-side full-text lexical ranking algorithms.

2. Capacity & Scale Estimation

Device & Memory Calculations

  • Page Sizing: Standard page size =20Β items= 20\text{ items}.
  • Item Data Footprint:
    • In-memory data model =1Β KB/item= 1\text{ KB/item}.
    • Loaded into RAM with active UI viewholders (200 items capped): 200Γ—1Β KB=200Β KBΒ DataΒ Heap200 \times 1\text{ KB} = \mathbf{200\text{ KB Data Heap}}.
    • Decoded image bitmap cache (LRU cache capped at 20 visible items): 20Γ—1Β MB=20Β MBΒ BitmapΒ RAM20 \times 1\text{ MB} = \mathbf{20\text{ MB Bitmap RAM}}.
  • Backend Pagination :
    • 50Β MillionΒ DAU50\text{ Million DAU} scrolling an average of 10 pages/day β€…β€ŠβŸΉβ€…β€Š500Β MillionΒ PageΒ Requests/Day\implies \mathbf{500\text{ Million Page Requests/Day}}. AverageΒ PagingΒ QPS=500Γ—10686,400Β sβ‰ˆ5,787Β QPSΒ (Peak:Β 20,000Β QPS)\text{Average Paging QPS} = \frac{500 \times 10^6}{86,400 \text{ s}} \approx 5,787 \text{ QPS (Peak: } 20,000\text{ QPS)}
  • Network Payload Sizing:
    • 20 items Γ—1Β KB=20Β KBΒ compressedΒ payload\times 1\text{ KB} = \mathbf{20\text{ KB compressed payload}} per page request.

3. High-Level Architecture & AWS Component Mapping

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

Component Responsibility Breakdown

ComponentTechnologyOperational Role & Configuration
Paging Engine / RemoteMediatorAndroid Paging3 / iOS PagerCoordinates boundary detection, triggers network fetches, manages retry policies, and writes raw pages to local SQLite.
Async Diffing EngineDiffUtil / AsyncListDiffer (Myers Algorithm)Computes minimal item additions, removals, and position movements on a background background thread; dispatches batch animations to UI.
Local Persistent CacheRoom / SQLite / CoreDataStores pages on disk; invalidates reactive paging streams upon database updates.
Keyset Paging API GatewayAmazon API GatewayValidates cryptographic signature on opaque cursors, extracts , and routes requests to ECS workers.
Keyset Storage EngineAmazon Executes sub-millisecond B-Tree tuple comparison seeks: WHERE (created_at, id) < (:last_ts, :last_id) ORDER BY created_at DESC, id DESC LIMIT 20.

4. API Interface Design & Wire Protocols

1. Keyset Cursor Pagination Endpoint

http
GET /v1/feed/items?limit=20&cursor=eyJjcmVhdGVkX2F0IjoxNzE4MDAwMDAwLCJpdGVtX2lkIjoiODhhOTFjNzQifQ== HTTP/1.1
Host: api.app.aws.internal
Authorization: Bearer <jwt_token>
Accept: application/json

Response: 200 OK

json
{
  "items": [
    {
      "id": "item_88a91c74",
      "title": "Deep Dive into Keyset Pagination",
      "author": "Distributed Systems Staff",
      "created_at": 1718000000000,
      "thumbnail_url": "https://cdn.app.com/thumb/88a91.webp"
    }
  ],
  "page_info": {
    "page_size": 20,
    "has_next_page": true,
    "has_previous_page": true,
    "next_cursor": "eyJjcmVhdGVkX2F0IjoxNzE3OTk5ODAwLCJpdGVtX2lkIjoicG9zdF8wOTkifQ==",
    "prev_cursor": "eyJjcmVhdGVkX2F0IjoxNzE4MDAwMjAwLCJpdGVtX2lkIjoicG9zdF8xMDIifQ=="
  }
}

5. Data Models & Storage Architecture

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

1. PostgreSQL Composite Keyset Schema & Index

sql
CREATE TABLE feed_items (
    item_id VARCHAR(64) PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    content TEXT NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE NOT NULL,
    author_id VARCHAR(64) NOT NULL
);

-- Crucial: Composite B-Tree index matches exact ORDER BY and WHERE tuple syntax
CREATE INDEX idx_feed_keyset_pagination ON feed_items (created_at DESC, item_id DESC);

-- Keyset Query Seeking Page 10,000 in < 1ms:
SELECT item_id, title, content, created_at, author_id
FROM feed_items
WHERE (created_at, item_id) < ('2026-09-04 12:00:00+00', 'item_88a91c74')
ORDER BY created_at DESC, item_id DESC
LIMIT 20;

6. Core Algorithms & Deep-Dive Workflows

1. Database-Mediated Paging Lifecycle (RemoteMediator)

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

2. Myers Diff Algorithm & Memory Eviction Mechanics

When memory exceeds max_size = 200, the Paging engine trims distant pages:

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

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 (~49%). Spend 1 Coin to unlock the remaining 5 production deep-dive sections for a full 24 hours.

Sections Included in This 24-Hour Pass:
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