🧮 Back-of-the-Envelope Capacity Estimations
📐 High-Level Architecture Topology
flowchart TD
A[Client] --> B[CDN Edge]
B -->|Cache Hit| C[301/302 Redirect]
B -->|Cache Miss| D[API Gateway]
D --> E[Shortener Service]
E --> F[Redis Cluster]
E --> G[Snowflake ID Gen]
E --> H[PostgreSQL Sharded]
F -->|Miss| H
H --> I[Analytics Pipeline]
🏛️ Architecture Deep Dive & Component Topology
Ingestion & ID Generation
Writes are decoupled from reads. A centralized Snowflake ID generator (64-bit: 1-bit sign, 41-bit timestamp, 10-bit machine ID, 12-bit sequence) ensures global uniqueness without coordination. Base62 encoding converts the 64-bit ID into a 10-11 character string. Writes go to a single-writer PostgreSQL shard to maintain consistency, then asynchronously publish to Kafka for analytics.
Read Path & Caching
Reads are served by a CDN edge layer. The CDN caches 301 (permanent) redirects aggressively (TTL: 30 days) and 302 (temporary) redirects briefly (TTL: 5 min) to preserve analytics accuracy. On cache miss, requests hit the API Gateway, which queries a multi-tier Redis cluster. L1 Redis (hot keys, 512GB) handles 80% of traffic. L2 Redis (warm keys) handles 15%. Only 5% of requests hit PostgreSQL. Bloom filters are used in the Redis layer to quickly reject non-existent URLs, preventing database lookups for invalid keys.
Partitioning & Sharding
PostgreSQL is sharded by the first 2 characters of the Base62 ID (1,849 shards) to distribute load evenly. Each shard is a primary-replica pair. Reads are routed to replicas, writes to the primary. A consistent hashing ring ensures that data locality is maintained during shard scaling.
💾 Data Models (DDL/Schemas) & API Contracts
SQL DDL
CREATE TABLE urls (
short_code VARCHAR(11) PRIMARY KEY,
long_url TEXT NOT NULL,
created_at TIMESTAMP DEFAULT NOW(),
expires_at TIMESTAMP,
click_count BIGINT DEFAULT 0,
region VARCHAR(10)
) PARTITION BY LIST (LEFT(short_code, 2));
REST Endpoints
POST /v1/shorten
Body: {"url": "https://example.com/long/path"}
Response: {"short_url": "https://tinyurl.com/abc123"}
GET /{short_code}
Response: 301/302 Redirect to long_url
GET /v1/stats/{short_code}
Response: {"clicks": 12345, "first_click": "2023-01-01"}
🛡️ Extreme Failure Scenarios, Stampede Defense & Self-Healing
Split-Brain & Consistency
In a multi-region setup, split-brain can occur if a region becomes isolated. Mitigation: Use a quorum-based consensus protocol (Raft) for the Snowflake ID generator to ensure no duplicate IDs are issued. For data, use a primary-replica model with a single writer per shard. If a region fails, traffic is rerouted to the healthy region via DNS failover. Data is replicated asynchronously, so there is a risk of data loss (RPO: 1 min). For critical use cases, synchronous replication can be enabled, but this increases latency.
Cache Stampede
When a hot key expires, thousands of requests may hit the database simultaneously. Mitigation: Use a mutex lock in Redis to ensure only one request fetches the data from the database, while others wait. Alternatively, use a probabilistic early expiration (PEXPIRE) to stagger cache invalidations. Bloom filters also help by quickly rejecting non-existent keys, reducing the load on the database.
Disaster Recovery
Multi-region active-active deployment with DNS-based traffic routing. Each region has its own Snowflake ID generator, Redis cluster, and PostgreSQL shards. Data is replicated across regions using Kafka Connect. In the event of a regional failure, DNS is updated to route traffic to the healthy region. RTO: 5 min, RPO: 1 min. Regular chaos engineering tests (e.g., killing a region) are performed to validate the failover process.
🎯 Interview Evaluation Rubric: L4/Senior vs L6/Staff Architect
🌐 AirSOTA Cross-Domain Ecosystem Synergy
Empowering North American tech talent & families with integrated decision-making across Visa, Career, Wealth, Housing & Education.
Maintain long-term career resilience: real-time DOL PERM processing queues, EB-2/3 movements & AC21 portability.
Convert high software engineering salary into permanent tax-free wealth via annual $70,000 Mega Backdoor rollovers.
High-throughput rate limiters, distributed consensus, and Staff-level trade-off rubrics with interactive diagrams.



