BLUEPRINT #02Mobile & Offline Architecture
Design Mobile Chat Client 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 battery-optimized, ultra-responsive, offline-resilient mobile chat client architecture managing bidirectional persistent WebSocket connections, encrypted local SQLite storage (SQLCipher), end-to-end encryption (E2EE Signal Protocol / Double Ratchet), binary Protocol Buffers serialization, and silent background push synchronization.
Interactive Architecture DiagramSynthesizing vector architecture diagram...
Functional Requirements
- Real-Time 1:1 and Group Chat: Send and receive text, media pointers, reactions, and threaded replies over low-latency WebSockets.
- Offline-First Messaging & Local Outbox: Messages authored offline are immediately rendered in the UI with a "clock" icon, committed to local SQLite, and dispatched sequentially upon reconnection.
- Delivery & Read Receipts: Real-time multi-state message tracking (
SENDINGSENT_TO_SERVERDELIVERED_TO_DEVICEREAD_BY_RECIPIENT). - End-to-End Encryption (E2EE): Implement Double Ratchet (Signal Protocol) cryptographic session state with private keys stored in hardware keystores.
- Silent Push Background Synchronization: Receive background pushes (
content-available: 1), waking the app for 30s to decrypt and store incoming messages in SQLite prior to user interaction.
Non-Functional Requirements (SLAs/SLOs)
- Send-to-Display Latency: on 4G/5G; instant optimistic local UI rendering.
- Battery & Radio Overhead: total device battery consumption per day for background presence.
- Local Database Encryption: Full AES-256 encryption at rest (zero plaintext leakage in flash memory).
- Wire Payload Efficiency: payload size reduction via binary Protocol Buffers vs standard JSON.
- Reconnection Recovery: Automatic session resumption in after transient connection drop.
Out-of-Scope
- Voice/Video calling media streaming (WebRTC RTP/RTCP transport pipelines covered in dedicated VoIP blueprints).
- Complex channel broadcast feeds with concurrent subscribers.
2. Capacity & Scale Estimation
Device & Traffic Scale
- Mobile Active Installs: devices ( DAU).
- Concurrent Connected Sockets: Peak simultaneous WebSocket connections during peak hours.
- Daily Messages Processed: messages/day.
Bandwidth & Serialization Efficiency
- Serialization Comparison:
- Standard JSON Frame: (
message_id,conversation_id,sender_id,recipient_id,timestamp,body,signature). - Optimized Protobuf Binary Frame: ( bandwidth reduction).
- Standard JSON Frame: (
- Heartbeat Bandwidth: 10M connected clients sending a ping every 60s .
3. High-Level Architecture & AWS Component Mapping
Interactive Architecture DiagramSynthesizing vector architecture diagram...
Component Responsibility Breakdown
| Component | Technology | Operational Role & Configuration |
|---|---|---|
| Local Encrypted Store | SQLCipher (AES-256) | Encrypted relational store holding chat history, ratchet session keys, and pending outbound messages. |
| Hardware Key Vault | iOS Keychain Secure Enclave / Android Keystore | Stores root master identity keys; cryptographic signing occurs inside hardware security modules (HSM). |
| Connection Manager | Native Coroutines / Swift Concurrency | State machine controlling WebSocket lifecycle, exponential backoff reconnects, and battery-aware ping intervals. |
| WebSocket Cloud Gateway | Amazon API Gateway WebSocket | Manages 10M persistent TCP connections, performs TLS termination, and routes frames to ECS workers. |
| Push Notification Relay | Amazon SNS (APNs / FCM) | Emits silent push wakes (content-available: 1 / priority: high) for offline clients to download messages in background. |
4. API Interface Design & Protobuf Message Schema
1. Protocol Buffers Wire Schema (chat_protocol.proto)
protobufsyntax = "proto3"; package chat.mobile.v1; enum DeliveryStatus { STATUS_UNKNOWN = 0; SENDING = 1; SENT_TO_SERVER = 2; DELIVERED = 3; READ = 4; } message ChatMessageFrame { string message_id = 1; string conversation_id = 2; string sender_id = 3; int64 timestamp_ms = 4; DeliveryStatus status = 5; bytes encrypted_payload = 6; // Double Ratchet encrypted ciphertext bytes ephemeral_public_key = 7; // Ratchet ephemeral key (32 bytes) int32 ratchet_counter = 8; bytes hmac_auth_tag = 9; } message ReceiptBatchFrame { string conversation_id = 1; DeliveryStatus status = 2; repeated string message_ids = 3; int64 receipt_timestamp_ms = 4; }
2. WebSocket Frame Envelope
json{ "action": "send_message", "payload_base64": "Cg9tc2dfOTk4MTI0YTg3YzESCGNvbnZfMTAxEgh1c3JfMjAyGICAkL21sTIy..." }
5. Data Models & Storage Architecture
Interactive Architecture DiagramSynthesizing vector architecture diagram...
Local SQLCipher Schema (chat_encrypted_storage.db)
sql-- Encrypted Conversations Table CREATE TABLE conversations ( conversation_id TEXT PRIMARY KEY, peer_user_id TEXT NOT NULL, last_message_id TEXT, unread_count INTEGER NOT NULL DEFAULT 0, updated_at INTEGER NOT NULL ); -- Encrypted Local Messages Table CREATE TABLE local_messages ( message_id TEXT PRIMARY KEY, conversation_id TEXT NOT NULL, sender_id TEXT NOT NULL, plaintext_body TEXT NOT NULL, delivery_status TEXT CHECK (delivery_status IN ('SENDING', 'SENT', 'DELIVERED', 'READ')), is_outgoing INTEGER NOT NULL, -- 1=true, 0=false timestamp_ms INTEGER NOT NULL ); CREATE INDEX idx_conversation_timeline ON local_messages(conversation_id, timestamp_ms DESC); -- Double Ratchet Cryptographic Session State CREATE TABLE ratchet_sessions ( conversation_id TEXT PRIMARY KEY, root_key BLOB NOT NULL, sending_chain_key BLOB NOT NULL, receiving_chain_key BLOB NOT NULL, sending_counter INTEGER NOT NULL DEFAULT 0, receiving_counter INTEGER NOT NULL DEFAULT 0, last_updated INTEGER NOT NULL );
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 (~42%). 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