Skip to main content
BLUEPRINT #03Mobile & Offline Architecture

Design Mobile Stock Trading & Market Ticker App

Target AWS Architecture:DynamoDBAuroraElastiCacheSQS
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 mission-critical, low-latency mobile stock trading application and real-time market data streaming pipeline supporting live price tickers, server-side data conflation, hardware-backed biometric cryptographic order signing, strict idempotent order routing, and zero double-execution guarantees during network transitions.

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

Functional Requirements

  1. Live Market Price Streaming: Stream real-time Level 1 quotes (Bid, Ask, Last Price, Volume) with sub-second chart updating for watchlists and detail views.
  2. Biometric Cryptographic Order Signing: Require biometric verification (FaceID / TouchID / Android BiometricPrompt) to sign order payloads using private keys locked inside hardware Secure Enclaves.
  3. Idempotent Order Placement: Support Market, Limit, and Stop orders with client-side purchasing power validation and bulletproof idempotency across network retries.
  4. Order State Lifecycle & Push Notifications: Track real-time order states (PENDING_SUBMISSION →\to RECEIVED →\to ROUTED_TO_EXCHANGE →\to FILLED / REJECTED) with instant push execution receipts.
  5. Stale Data Protection: Automatically flag market prices as "STALE" and disable order placement if market data heartbeat is interrupted for >2.5 seconds> 2.5\text{ seconds}.

Non-Functional Requirements (SLAs/SLOs)

  • Order Routing Latency: Client submission to exchange gateway receipt <150 ms< 150\text{ ms} (P99P99).
  • Zero Double-Execution: Absolute 100%100\% idempotency guarantee (zero duplicate orders created under network retransmission).
  • UI Responsiveness & Frame Rate: Strict 120 FPS rendering without frame stutter or battery drainage during extreme market volatility.
  • High Availability: 99.999%99.999\% uptime during active market trading hours (<1.5 seconds< 1.5\text{ seconds} downtime allowed/day).
  • Security & Compliance: Zero plaintext storage of API tokens; FIPS 140-2 Level 3 hardware security compliance.

Out-of-Scope

  • Complex algorithmic high-frequency options pricing Black-Scholes engines.
  • Decentralized crypto blockchain settlement layer.

2. Capacity & Scale Estimation

Traffic & Scale Math

  • Active Mobile Traders: 10 Million10\text{ Million} accounts (3 Million3\text{ Million} concurrent during market open/close).
  • Watchlist Symbol Distribution: Average trader watches 15 active symbols15\text{ active symbols}.
  • Raw Exchange Ticker Frequency: 100 ticks/sec100\text{ ticks/sec} per volatile symbol.
    • Raw Ticks/sec without Conflation: 3×106 users×15 symbols×100 ticks/s=4.5 Billion events/sec3 \times 10^6 \text{ users} \times 15 \text{ symbols} \times 100 \text{ ticks/s} = \mathbf{4.5\text{ Billion events/sec}} (Would destroy mobile batteries in 15 minutes).
  • Server-Side Conflation Engine:
    • The backend conflates raw ticks into 2 updates/sec per symbol per mobile client.
    • Conflated Stream: 3×106×15×2=90 Million events/sec3 \times 10^6 \times 15 \times 2 = \mathbf{90\text{ Million events/sec}} delivered via HTTP/2 Server-Sent Events (SSE) or WebSocket streams (98%98\% reduction in event traffic).
  • Order Placement Throughput:
    • Average 500,000 orders/day500,000\text{ orders/day}. Peak during market opening bell (9:30 AM EST9:30\text{ AM EST})   ⟹  5,000 orders/sec\implies \mathbf{5,000\text{ orders/sec}}.

3. High-Level Architecture & AWS Component Mapping

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

Component Responsibility Breakdown

ComponentTechnologyOperational Role & Configuration
Biometric Key VaultiOS Secure Enclave / Android KeyStoreGenerates non-exportable 256-bit ECDSA key pair (secp256r1). Private key is invoked only upon successful FaceID/TouchID prompt.
Market Conflation EngineAmazon ECS Fargate + Aggregates sub-millisecond market ticks into fixed 500ms snapshots per symbol before multicasting to connected mobile clients.
Idempotency RegistryEnforces strict conditional write locks on ( 24 hours), guaranteeing zero duplicate order executions.
Transactional LedgerAmazon Stores ACID-compliant double-entry account balances, buying power reservations, and order state audit histories.
Exchange Dispatch Queue Guarantees strictly ordered, exactly-once delivery of FIX (Financial Information eXchange) protocol messages to equity market makers.

4. API Interface Design & Wire Protocols

1. Submit Biometrically Signed Order

http
POST /v1/trading/orders HTTP/1.1
Host: trade.production.aws.internal
Idempotency-Key: mob_ord_88a91c74_f0b21a_20260904
Authorization: Bearer <jwt_session_token>
X-Biometric-Signature: MEUCIQDN3b6r8vK... (ECDSA P-256 Signature)
X-Client-Timestamp: 1718000005120
Content-Type: application/json

{
  "account_id": "acc_998124a87",
  "symbol": "NVDA",
  "side": "BUY",
  "order_type": "LIMIT",
  "limit_price": 125.50,
  "quantity": 100,
  "time_in_force": "DAY",
  "estimated_total_usd": 12550.00
}

Response: 201 Created

json
{
  "order_id": "ord_20260904_998124",
  "status": "ACCEPTED",
  "symbol": "NVDA",
  "side": "BUY",
  "quantity": 100,
  "limit_price": 125.50,
  "reserved_funds_usd": 12550.00,
  "created_at": 1718000005210
}

2. Market Ticker Stream (Server-Sent Events)

http
GET /v1/marketdata/tickers/stream?symbols=NVDA,AAPL,MSFT HTTP/1.1
Host: stream.trade.aws.internal
Accept: text/event-stream

Response Stream: 200 OK

text
event: tick
data: {"symbol":"NVDA","bid":125.48,"ask":125.52,"last":125.50,"vol":4829340,"ts":1718000005500}

event: tick
data: {"symbol":"AAPL","bid":220.10,"ask":220.15,"last":220.12,"vol":1928340,"ts":1718000005500}

5. Data Models & Storage Architecture

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

PostgreSQL Schema (trading_core_db)

sql
CREATE TABLE trading_orders (
    order_id VARCHAR(64) PRIMARY KEY,
    account_id VARCHAR(64) NOT NULL,
    idempotency_key VARCHAR(128) UNIQUE NOT NULL,
    symbol VARCHAR(16) NOT NULL,
    side VARCHAR(4) CHECK (side IN ('BUY', 'SELL')),
    order_type VARCHAR(16) CHECK (order_type IN ('MARKET', 'LIMIT', 'STOP')),
    limit_price NUMERIC(12, 4),
    quantity INTEGER NOT NULL CHECK (quantity > 0),
    filled_quantity INTEGER NOT NULL DEFAULT 0,
    status VARCHAR(32) NOT NULL CHECK (status IN ('PENDING', 'ACCEPTED', 'ROUTED', 'FILLED', 'REJECTED', 'CANCELLED')),
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_orders_account ON trading_orders(account_id, created_at DESC);

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 (~43%). 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