System Design & Case Studies
Production architecture blueprints without fabricated claims or vendor hype. We examine back-of-the-envelope calculations, data flows, storage bounds, and real-world failure bottlenecks.
Core System Design Invariants
CAP Theorem & PACELC
Under network partitions, distributed systems must trade off between immediate strong consistency (CP) or continuous availability (AP). In the absence of partitions (PC), systems trade latency (L) against consistency (C).
Stateless Application Tiers
Never store user sessions in local server memory. Offload state to external datastores so any node can be terminated or autoscaled without impacting active client transactions.
Cache-Aside & Thundering Herds
Applications query the cache first; on a miss, they query the database and backfill the cache. Mutex locks or probabilistic early expiration prevent thousands of concurrent misses from crushing the database.
Database Sharding & Consistent Hashing
Distribute table rows across multiple database servers using hash partitions. Consistent hashing rings minimize data rebalancing when servers are added or removed.
End-to-End Architectural Case Studies
Step through requirements, high-level diagrams, and edge-case failure modes for real production architectures.
High-Throughput URL Shortener
Deconstructs Base62 token encoding, distributed counter ranges, cache-aside Redis clusters, and B-Tree indexing guarantees.
Architecture & Data Flow
- 1. Clients submit long URLs via API Gateway with sliding-window rate limiters.
- 2. Distributed Ticket Server or Snowflake worker generates sequential 64-bit ID.
- 3. Worker encodes ID into 7-character Base62 string (a-z, A-Z, 0-9 = 3.5 trillion unique keys).
- 4. Row persisted in PostgreSQL with UNIQUE index on short_code.
- 5. Redis cluster caches hot URLs with LRU eviction and 7-day TTL.
- 6. HTTP 301 Permanent vs 302 Temporary redirect trade-offs.
Production Bottlenecks & Failure Modes
Real-Time Chat & Direct Messaging
Persistent stateful WebSocket gateways, Redis Pub/Sub multiplexers, presence heartbeats, and append-only message stores.
Architecture & Data Flow
- 1. Clients maintain persistent bidirectional WebSocket connections to Gateway nodes.
- 2. Connection Manager service maintains ephemeral socket-to-user mappings in Redis.
- 3. Messages dispatched to Redis Pub/Sub or Kafka topics partitioned by channel_id.
- 4. Worker pools asynchronously archive messages to Apache Cassandra clustered by (channel_id, message_id).
- 5. Offline notifications routed to APNs/FCM via background worker queues.
- 6. Heartbeat probes detect dropped sockets within 15 seconds.
Production Bottlenecks & Failure Modes
Adaptive Bitrate Video Streaming
Chunked HLS/DASH media segmenting, distributed transcoding DAGs, multi-tier edge CDN caching, and origin shield protection.
Architecture & Data Flow
- 1. Raw video uploaded via chunked multipart upload directly to Object Storage (S3).
- 2. Message queue triggers distributed transcoding cluster creating multi-bitrate HLS streams (1080p, 720p, 480p, 360p).
- 3. Videos sliced into 4-second `.ts` or `.m4s` chunks with `.m3u8` master manifest.
- 4. Global Anycast CDN caches chunks at edge nodes closest to viewers.
- 5. Origin Shield protects storage bucket from cold cache misses.
- 6. Client media player dynamically switches bitrates based on local network throughput.
Production Bottlenecks & Failure Modes
Distributed Notification System
Priority queues, per-user rate limiters, template rendering engines, and third-party vendor fallbacks (Twilio, Sendgrid, APNs).
Architecture & Data Flow
- 1. Application services emit notification events with priority tags (Critical, Standard, Marketing).
- 2. RabbitMQ or SQS priority queues buffer events according to delivery urgency.
- 3. Deduplication worker verifies idempotency key in Redis to prevent duplicate sends.
- 4. User preference engine filters out opted-out channels and enforces quiet hours.
- 5. Vendor dispatch workers send payload via Twilio, SendGrid, or APNs with circuit-breaker fallbacks.
- 6. Dead-letter queues capture failed delivery attempts for automatic retry with exponential jitter.
Production Bottlenecks & Failure Modes
Want to explore the foundational socket mechanics first?
Step through our Structured Path from physical transport layers to global distributed systems.