BLUEPRINT #04Mobile & Offline Architecture
Design Mobile Paging & Infinite Scrolling Library Architecture
Referenced Architecture Primitives (4)
Click any primitive to study its algorithmic deep dive10-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 DiagramSynthesizing vector architecture diagram...
Functional Requirements
- Cursor-Based Keyset Pagination: Request sequential pages using opaque base64 cursor tokens containing composite sort keys (e.g.
(timestamp, item_id)), preventing missing or duplicate items during real-time insertions. - Predictive Boundary Prefetching: Trigger asynchronous background page fetches when the user scrolls within items of list boundary (e.g.
prefetch_distance = 5). - Database-Mediated Single Source of Truth: Network responses are written directly to local SQLite; UI observes reactive database streams (Room
PagingSource/ CoreDataNSFetchedResultsController). - 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. - 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 ( 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 regardless of whether the user scrolls through 100 or 100,000 items.
- Backend Query Latency: Cursor seek query latency () in Aurora PostgreSQL ( 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-windowDOM virtualization). - Server-side full-text lexical ranking algorithms.
2. Capacity & Scale Estimation
Device & Memory Calculations
- Page Sizing: Standard page size .
- Item Data Footprint:
- In-memory data model .
- Loaded into RAM with active UI viewholders (200 items capped): .
- Decoded image bitmap cache (LRU cache capped at 20 visible items): .
- Backend Pagination QPS:
- scrolling an average of 10 pages/day .
- Network Payload Sizing:
- 20 items per page request.
3. High-Level Architecture & AWS Component Mapping
Interactive Architecture DiagramSynthesizing vector architecture diagram...
Component Responsibility Breakdown
| Component | Technology | Operational Role & Configuration |
|---|---|---|
| Paging Engine / RemoteMediator | Android Paging3 / iOS Pager | Coordinates boundary detection, triggers network fetches, manages retry policies, and writes raw pages to local SQLite. |
| Async Diffing Engine | DiffUtil / AsyncListDiffer (Myers Algorithm) | Computes minimal item additions, removals, and position movements on a background background thread; dispatches batch animations to UI. |
| Local Persistent Cache | Room / SQLite / CoreData | Stores pages on disk; invalidates reactive paging streams upon database updates. |
| Keyset Paging API Gateway | Amazon API Gateway | Validates cryptographic signature on opaque cursors, extracts sort keys, and routes requests to ECS workers. |
| Keyset Storage Engine | Amazon Aurora PostgreSQL | 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
httpGET /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 DiagramSynthesizing vector architecture diagram...
1. PostgreSQL Composite Keyset Schema & Index
sqlCREATE 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 DiagramSynthesizing vector architecture diagram...
2. Myers Diff Algorithm & Memory Eviction Mechanics
When memory exceeds max_size = 200, the Paging engine trims distant pages:
Interactive Architecture DiagramSynthesizing 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