← Back to Portfolio NEW 2026 ADVANCED EDITION / OCTOBER 2026

System Design Sheet

New: 30 high-level and 20 low-level designs specific to Google, Amazon, Microsoft, Netflix, Apple, Cisco and more, with estimates, diagrams, deep dives, trade-offs and runnable LLD code. Plus the original HLD/LLD solutions, 12 worked case studies, company-preparation tracks, and a downloadable PDF. All included in the same ₹49 purchase.

30 + 20
New HLD + LLD designs
57
Design prompts
38
High-level designs
8
Low-level designs
11
AI-native systems

πŸ”’ Unlock System Design Sheet

Get the complete original design notes and the expanded design practice library with one purchase.

β‚Ή49
β‚Ή499

Already have an access code?

Original system design sheetThe original HLD and LLD notes remain included for quick revision.

1
URL Shortener (TinyURL)
HLD
GoogleAmazonMicrosoft
→

Problem

Design a URL shortening service like TinyURL/bit.ly that converts long URLs to short ones and redirects.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Client │────▢│ Load Balancer│────▢│ API Servers │────▢│ Redis Cache β”‚ β”‚ (Browser)β”‚ β”‚ (Nginx) β”‚ β”‚ (Stateless) β”‚ β”‚ (Hot URLs) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β”‚ write β”‚ miss β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Key Gen Svc β”‚ β”‚ Database β”‚ β”‚ (Base62 / ID) │────▢│ (Cassandra) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”‚ Analytics β”‚ β”‚ (Kafka β†’ β”‚ β”‚ ClickHouse)β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ FLOW: Shorten: Client β†’ LB β†’ API β†’ KeyGen (Base62) β†’ DB write β†’ return short URL Redirect: Client β†’ LB β†’ API β†’ Cache hit? return : DB lookup β†’ 301 redirect Analytics: Each redirect β†’ Kafka event β†’ ClickHouse for dashboards

Key Decisions

EncodingBase62 (a-z, A-Z, 0-9) β†’ 6 chars = 56 billion unique URLs
DatabaseCassandra β€” write-heavy, horizontally scalable, no single point of failure
CachingRedis with LRU eviction. 80/20 rule β†’ 80% reads from 20% of URLs
Scale100M URLs/day, 10:1 read:write ratio, 301 vs 302 redirect tradeoff
2
Twitter / X (Social Feed)
HLD
MetaGoogleAmazon
→

Problem

Design a social media platform with tweets, follows, news feed, and real-time updates for 500M+ users.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Client │────▢│ LB │────▢│ API Gateway β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β–Ό β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Tweet Service β”‚ β”‚ Feed Service β”‚ β”‚ User Service β”‚ β”‚ (write path) β”‚ β”‚ (read path) β”‚ β”‚ (profiles) β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Tweet DB β”‚ β”‚ Feed Cache β”‚ β”‚ (sharded by β”‚ β”‚ (Redis per β”‚ β”‚ userID) β”‚ β”‚ user) β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ fan-out β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Fan-out Svc β”‚ β”‚ Search Service β”‚ β”‚ (Kafka + │───▢│ (Elasticsearch) β”‚ β”‚ workers) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ FEED GENERATION: β€’ Normal users (<1K followers): Fan-out on WRITE β€” push to follower caches β€’ Celebrities (>100K followers): Fan-out on READ β€” pull at query time β€’ Hybrid approach combines both for optimal performance

Key Decisions

Feed StrategyHybrid fan-out: push for normal users, pull for celebrities. Avoids hot partition problem
StorageTweet DB sharded by userID + S3 for media + CDN for delivery
Real-timeWebSocket for live timeline, Kafka for async event processing
Scale500M DAU, ~600K tweets/sec read, 5K tweets/sec write
3
WhatsApp / Chat System
HLD
MetaGoogleMicrosoft
→

Problem

Design a real-time messaging system with 1:1 chat, group chat, read receipts, media sharing, and E2E encryption.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” WebSocket β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Client A │◀═══════════▢│ Chat Server │────────▢│ Message Queueβ”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ (stateful, β”‚ β”‚ (Kafka) β”‚ β”‚ session mgr) β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” WebSocket β”‚ β”‚ β”‚ β”‚ Client B │◀═══════════▢│ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β” β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ Message DB β”‚ β”‚ β”‚ (Cassandra) β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β” β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ Presence Svc β”‚ β”‚ (online/typing)β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ Push Notify β”‚ β”‚ (APNs / FCM) β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ Group Service β”‚ β”‚ β€’ Group metadata in MySQL β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β€’ Fan-out messages to members │────────▢│ Media Store β”‚ β”‚ β€’ Max 256 members per group β”‚ β”‚ (S3 + CDN) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ FLOW: 1. A sends message β†’ WebSocket β†’ Chat Server 2. Server checks B online? β†’ direct deliver via WebSocket 3. B offline? β†’ store in Kafka β†’ retry + Push Notification 4. Read receipts: B reads β†’ ack sent back β†’ A gets double-tick

Key Decisions

ProtocolWebSocket for persistent bidirectional. MQTT as fallback for low-bandwidth
StorageCassandra β€” write-heavy (billions of msgs/day), TTL for auto-cleanup
DeliveryAt-least-once via Kafka. Client-side dedup using message IDs
EncryptionSignal Protocol for E2E. Server never sees plaintext content
4
Netflix / YouTube (Video Streaming)
HLD
NetflixGoogleAmazon
→

Problem

Design a video streaming platform with upload, transcoding, adaptive playback, CDN delivery, and recommendations.

Architecture

UPLOAD PATH: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Creator │────▢│ Upload Service│────▢│ Transcoding Svc │────▢│ S3 β”‚ β”‚ β”‚ β”‚ (chunked) β”‚ β”‚ (FFmpeg workers) β”‚ β”‚ (multiple β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ 480p/720p/1080p β”‚ β”‚ resolutionsβ”‚ β”‚ 4K + thumbnails β”‚ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό PLAYBACK PATH: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ CDN β”‚ β”‚ Viewer │────▢│ API Gateway │────▢│ Manifest │───────▢│ (CloudFront) β”‚ β”‚ │◀════│ β”‚ β”‚ (HLS/DASHβ”‚ β”‚ edge caches β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ .m3u8) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ABR Player β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ (adapts quality β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” based on bandwidth) β”‚ Recommendationβ”‚ β”‚ (collaborativeβ”‚ β”‚ filtering + β”‚ β”‚ content-based)β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Decisions

StreamingHLS/DASH adaptive bitrate. Client measures bandwidth, switches resolution seamlessly
TranscodingPre-compute all resolutions. FFmpeg workers via queue. ~30 mins per hour of 4K video
CDNGlobal edge network. Open Connect (Netflix) / CloudFront. 95%+ cache hit rate
RecommendationCollaborative filtering + content-based. A/B tested. Drives 80% of content watched
5
Uber / Ride Sharing
HLD
GoogleAmazonMicrosoft
→

Problem

Design a ride-sharing platform with real-time driver matching, GPS tracking, ETA, surge pricing, and payments.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” GPS every 4s β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Driver App │══════════════▢│ Location Service β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ (QuadTree / β”‚ β”‚ Geohash index) β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” ride request β”‚ β”‚ nearby drivers β”‚ Rider App │──────────────▢│ │──────────────────┐ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β–Ό β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ Matching Service │◀────────│ Supply-Demand β”‚ β”‚ ride accepted β”‚ (assign closest β”‚ β”‚ Engine β”‚ │◀─────────────────────│ available driver)β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Pricing Svc β”‚ β”‚ β”‚ Trip Service │────────▢│ (surge based β”‚ β”‚ β”‚ (state machine: β”‚ β”‚ on demand/ β”‚ β”‚ β”‚ REQUESTED β†’ β”‚ β”‚ supply ratio)β”‚ β”‚ β”‚ MATCHED β†’ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ IN_PROGRESS β†’ β”‚ β”‚ β”‚ COMPLETED) β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”€β”€β”€β”€β”€β”€β”€β”€β–Άβ”‚ Payment Svc β”‚ β”‚ β”‚ β”‚ (Stripe/ β”‚ β–Ό β–Ό β”‚ Razorpay) β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ Notification β”‚ β”‚ ETA Service β”‚ β”‚ (WebSocket) β”‚ β”‚ (graph + traffic)β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Decisions

Location IndexQuadTree or S2 Geometry cells. Drivers update GPS every 4 seconds. Index ~1M active drivers
MatchingNearest available driver within radius. Consider direction, ETA, driver rating
Surge PricingDynamic multiplier based on demand/supply ratio per geo-cell. Updated every 5 mins
ETADijkstra on road graph + real-time traffic weights. Pre-computed for common routes
6
Google Drive / Dropbox
HLD
GoogleMicrosoft
→

Problem

Design a cloud file storage with upload/download, sync across devices, versioning, sharing, and real-time collaboration.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Client │────▢│ Block Server │────▢│ Object Storage β”‚ β”‚ (desktop β”‚ β”‚ (chunked β”‚ β”‚ (S3) β”‚ β”‚ sync β”‚ β”‚ upload, 4MB β”‚ β”‚ β€’ dedup via hashβ”‚ β”‚ agent) β”‚ β”‚ blocks) β”‚ β”‚ β€’ versioning β”‚ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ Metadata DB β”‚ β”‚ Sync Service β”‚ β”‚ β”‚ (file tree, │◀───▢│ (long-polling / β”‚ β”‚ β”‚ versions, β”‚ β”‚ WebSocket for β”‚ β”‚ β”‚ permissions) β”‚ β”‚ change notify) β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ │◀─────────────── change notification β”€β”€β”€β”€β”€β”˜ β”‚ (only changed blocks pulled) UPLOAD: file β†’ split into 4MB blocks β†’ hash each β†’ dedup β†’ upload new blocks β†’ update metadata SYNC: change detected β†’ Sync Service notifies other clients β†’ delta download (only changed blocks) SHARE: ACL stored in metadata β†’ generate share link with permissions (view/edit)

Key Decisions

Chunking4MB blocks with content-based hashing (SHA-256). Enables dedup & delta sync
SyncLong-polling for change notifications. Only changed blocks transferred (saves ~70% bandwidth)
ConflictLast-write-wins for simple files. OT (Operational Transform) for real-time collab docs
VersioningKeep last N versions per file. Incremental snapshots using block references
7
Rate Limiter
HLD
GoogleAmazonMicrosoft
→

Problem

Design a distributed rate limiter that throttles API requests per user/IP with minimal latency.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Client │────▢│ API Gateway │────▢│ Backend β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ Services β”‚ β”‚ β”‚ Rate Limiter Middleware β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ 1. Extract user/IP key β”‚ β”‚ β”‚ β”‚ 2. Check Redis counter β”‚ β”‚ β”‚ β”‚ 3. Allow or reject (429) β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”‚ Redis β”‚ β”‚ (counters β”‚ β”‚ per key) β”‚ β”‚ β”‚ β”‚ key: userID β”‚ β”‚ val: count β”‚ β”‚ TTL: window β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ALGORITHMS: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Token Bucket β”‚ Steady rate + allows burst. Best for APIs. β”‚ β”‚ Sliding Window β”‚ Precise, no edge spikes. Higher memory. β”‚ β”‚ Fixed Window β”‚ Simple. Risk of 2x burst at window boundary. β”‚ β”‚ Leaky Bucket β”‚ Constant output rate. Smooth but no burst. β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Decisions

AlgorithmToken Bucket (most common). Allows configurable rate + burst capacity
DistributedRedis for shared state across API servers. INCR + EXPIRE atomic ops
Race ConditionsLua scripts in Redis for atomic check-and-increment. Prevents TOCTOU bugs
HeadersReturn X-RateLimit-Remaining, X-RateLimit-Reset, Retry-After in 429 response
8
Notification System
HLD
AmazonMetaApple
→

Problem

Design a scalable notification service supporting push, SMS, email, and in-app channels for billions of notifications/day.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Event Source │────────▢│ Kafka / β”‚ β”‚ (any service β”‚ β”‚ Message Bus β”‚ β”‚ triggers β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ notificationβ”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Notification │────────▢│ User Preference β”‚ β”‚ Service β”‚ β”‚ DB β”‚ β”‚ (routing + β”‚ β”‚ (channel prefs, β”‚ β”‚ templating) β”‚ β”‚ quiet hours, β”‚ β””β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β”‚ frequency cap) β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ └──────────┐ β–Ό β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Push β”‚ β”‚ Email β”‚ β”‚ SMS β”‚ β”‚ (APNs/FCM)β”‚ β”‚(SES/SMTP)β”‚ β”‚ (Twilio) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β–Ό β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Delivery Tracking DB β”‚ β”‚ (sent/delivered/failed + retry queue) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Decisions

PrioritySeparate queues: P0 (security alerts, OTP) β†’ immediate. P1 (social) β†’ batched
DedupIdempotency key per notification. Prevents double-send on retry
Rate LimitingPer-user caps (max 5 push/hour). Respect quiet hours per timezone
RetryExponential backoff with DLQ (dead letter queue) for permanent failures
9
Search Autocomplete / Typeahead
HLD
GoogleAmazon
→

Problem

Design a real-time search autocomplete system that suggests top queries as users type, with <100ms latency.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” "app" β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ User │─────────▢│ API Server │────▢│ Trie Service β”‚ β”‚ (typing) β”‚ <100ms β”‚ β”‚ β”‚ (in-memory) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”‚ β”‚ β”‚ β”‚ top 10 results β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ Each node storesβ”‚ suggestions β”‚ top-K queries β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ periodic rebuild β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Aggregation Svc β”‚ β”‚ (MapReduce on β”‚ β”‚ query logs, β”‚ β”‚ every 15 mins) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Analytics DB β”‚ β”‚ (query counts, β”‚ β”‚ trending) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ TRIE STRUCTURE: root β”œβ”€β”€ a β”‚ β”œβ”€β”€ p β”‚ β”‚ β”œβ”€β”€ p β†’ ["apple", "app store", "apple watch"] (top-K cached) β”‚ β”‚ └── ... β”‚ └── m β†’ ["amazon", "amc", "amazon prime"] └── ...

Key Decisions

Data StructureTrie with top-K results pre-computed at each node. O(prefix length) lookup
FreshnessRebuild trie from query logs every 15 mins. Trending topics merged in real-time
CachingBrowser-side cache for recent prefixes. CDN edge cache for popular ones
ShardingShard by first character or consistent hashing. Each shard fits in memory (~10GB)
10
Instagram (Photo Sharing)
HLD
MetaGoogle
→

Problem

Design a photo/video sharing platform with feed, stories, likes, comments, explore, and reels.

Architecture

UPLOAD: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ User │────▢│ Upload │────▢│ Image Processing│────▢│ S3 + β”‚ β”‚ β”‚ β”‚ Service β”‚ β”‚ (resize, filter, β”‚ β”‚ CDN β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ thumbnails) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ FEED: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ User │────▢│ Feed Svc │────▢│ Feed Cache β”‚ β”‚ β”‚ β”‚ (ranked β”‚ β”‚ (Redis, per-user β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ by ML) β”‚ β”‚ pre-computed) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ EXPLORE: User Activity β†’ ML Ranking Pipeline β†’ Content Index β†’ Personalized Explore Page β€’ Sharded by userID for posts DB β€’ Separate counters service for likes (avoid write amplification) β€’ Stories: TTL 24h, stored in separate fast-expiry storage

Key Decisions

Feed RankingML model ranks posts by: recency, engagement probability, relationship strength
Likes/CountsSeparate counter service with Redis. Avoids row-level locks on posts table
Stories24h TTL. Stored in Redis/Memcached for fast reads, auto-expire
CDNMulti-region CDN. Images served at multiple resolutions. WebP format for 30% savings
11
Parking Lot System
LLD
AmazonGoogleMicrosoft
→

Problem

Design a multi-floor parking lot with entry/exit, automatic spot assignment, ticket, billing, and vehicle type support.

Class Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ ParkingLot β”‚ β”‚ - floors: List<ParkingFloor> β”‚ β”‚ - entryPanels: List<EntryPanel> β”‚ β”‚ - exitPanels: List<ExitPanel> β”‚ β”‚ + getAvailableSpot(vehicleType): ParkingSpot β”‚ β”‚ + issueTicket(vehicle): Ticket β”‚ β”‚ + processExit(ticket): Payment β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ ParkingFloor β”‚ β”‚ DisplayBoard β”‚ β”‚ - spots: Map β”‚ β”‚ - availableCounts β”‚ β”‚ + getAvailable() β”‚ β”‚ + update() β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ ParkingSpot β”‚ β”‚ Vehicle β”‚ β”‚ Ticket β”‚ β”‚ (Abstract) β”‚ β”‚ - plate β”‚ β”‚ - entryTimeβ”‚ β”‚ + isAvailable() β”‚ β”‚ - type β”‚ β”‚ - spot β”‚ β”‚ + assignVehicle() β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ - vehicle β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β”‚ CompactSpot β”‚ β”‚ β”‚ LargeSpot β”‚ β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”‚ HandicappedSpot β”‚ β”‚ Payment β”‚ β”‚ MotorcycleSpot β”‚ β”‚ - amount β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ - strategy β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ PATTERNS: β€’ Strategy β†’ PricingStrategy (hourly, flat, weekend rates) β€’ Observer β†’ DisplayBoard updates when spot status changes β€’ Factory β†’ SpotFactory assigns spot based on vehicle type β€’ Singleton β†’ ParkingLot instance

Key Decisions

Spot AssignmentFactory pattern: motorcycle→small, car→compact/large, bus→large. Nearest-to-exit priority
PricingStrategy pattern: HourlyPricing, FlatRate, WeekendPricing. Swap at runtime
ConcurrencyLock at spot level (not floor). CAS operation for atomic assign/release
DisplayObserver pattern: spots notify display boards on status change. Real-time counts
12
Elevator System
LLD
MicrosoftGoogle
→

Problem

Design a multi-elevator system with optimal dispatching, SCAN algorithm, and maintenance mode.

Class Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ ElevatorSystem β”‚ β”‚ - elevators: List<Elevator> β”‚ β”‚ - dispatcher: Dispatcher β”‚ β”‚ + requestElevator(floor, direction): void β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ delegates β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Dispatcher (Strategy) β”‚ β”‚ + selectElevator(request): Elevator β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ NearestIdleDispatcher β”‚ β”‚ SCANDispatcher (direction-based) β”‚ β”‚ ZoneDispatcher (floors 1-10, 11-20, etc.) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Elevator β”‚ β”‚ - id: int β”‚ β”‚ - currentFloor: int β”‚ β”‚ - direction: UP | DOWN | IDLE β”‚ β”‚ - state: RUNNING | STOPPED | MAINTENANCE β”‚ β”‚ - requests: PriorityQueue<int> β”‚ β”‚ + move(): void β”‚ β”‚ + addRequest(floor): void β”‚ β”‚ + openDoor() / closeDoor(): void β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ SCAN ALGORITHM: Floor: 1 2 3 4 5 6 7 8 9 10 ↑ E→→→→→→→→→→↑ β”‚ β”‚ (reverses at top) ↑←←←←←←←←←←←←←←←←←↓ Elevator moves in one direction, services all requests, then reverses β€” like a disk arm (elevator algorithm).

Key Decisions

DispatchStrategy pattern: swap SCAN/Nearest/Zone at runtime. SCAN minimizes total travel
State MachineState pattern: IDLE→MOVING→STOPPED→MAINTENANCE. Clean transitions
Priority QueueRequests sorted by floor in current direction. Reversal when no more ahead
OverloadWeight sensor β†’ reject if over capacity. Emergency stop via Command pattern
13
LRU Cache
LLD
GoogleAmazonMicrosoft
→

Problem

Design a Least Recently Used cache with O(1) get and put operations.

Design

DATA STRUCTURE: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ HashMap: { key β†’ Node pointer } O(1) lookup β”‚ β”‚ β”‚ β”‚ Doubly Linked List: HEAD ↔ [A] ↔ [B] ↔ [C] ↔ TAIL β”‚ β”‚ (LRU) (MRU) β”‚ β”‚ β”‚ β”‚ get(B): remove B from middle, move to tail (MRU) β”‚ β”‚ put(D): add at tail. If full, evict HEAD.next (LRU) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ class Node: def __init__(self, key, val): self.key, self.val = key, val self.prev = self.next = None class LRUCache: def __init__(self, capacity): self.cache = {} # key β†’ Node self.cap = capacity self.head = Node(0,0) # dummy self.tail = Node(0,0) # dummy self.head.next = self.tail self.tail.prev = self.head def _remove(self, node): # O(1) node.prev.next = node.next node.next.prev = node.prev def _add(self, node): # O(1) β€” add before tail node.prev = self.tail.prev node.next = self.tail self.tail.prev.next = node self.tail.prev = node def get(self, key): # O(1) if key in self.cache: node = self.cache[key] self._remove(node) self._add(node) return node.val return -1 def put(self, key, val): # O(1) if key in self.cache: self._remove(self.cache[key]) node = Node(key, val) self._add(node) self.cache[key] = node if len(self.cache) > self.cap: lru = self.head.next self._remove(lru) del self.cache[lru.key]

Key Decisions

Why DLL?Need O(1) removal from middle. Array can't do this. DLL + HashMap = O(1) for everything
Dummy NodesHead and tail sentinels eliminate null checks at boundaries. Cleaner code
Thread SafetyFor concurrent use: ReadWriteLock or ConcurrentHashMap + synchronized DLL ops
EvictionAlways evict head.next (oldest). Python alternative: collections.OrderedDict
14
Movie Ticket Booking (BookMyShow)
LLD
AmazonMicrosoft
→

Problem

Design a movie ticket booking system with seat selection, concurrent booking handling, and payment.

Class Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Theater │────▢│ Screen │────▢│ Show β”‚ β”‚ - name β”‚ 1:Nβ”‚ - capacity β”‚ 1:Nβ”‚ - movie β”‚ β”‚ - city β”‚ β”‚ - seats[] β”‚ β”‚ - timing β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β”‚ 1:N β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Seat β”‚ β”‚ User │────▢│ Booking │───▢│ - row, col β”‚ β”‚ - name β”‚ β”‚ - seats[] β”‚ β”‚ - type β”‚ β”‚ - email β”‚ β”‚ - status β”‚ β”‚ - status: β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ - payment β”‚ β”‚ AVAILABLE β”‚ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β”‚ LOCKED β”‚ β”‚ β”‚ BOOKED β”‚ β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ Payment β”‚ β”‚ - amount β”‚ β”‚ - method β”‚ β”‚ - status β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ CONCURRENCY FLOW: 1. User selects seats β†’ seats LOCKED (5 min TTL) 2. Other users see those seats as unavailable 3. Payment success β†’ seats marked BOOKED 4. Payment fail / timeout β†’ seats released back to AVAILABLE 5. Pessimistic locking: SELECT ... FOR UPDATE on seat rows

Key Decisions

ConcurrencyPessimistic lock (SELECT FOR UPDATE) on seats. 5-min TTL prevents abandoned locks
PricingStrategy pattern: WeekdayPrice, WeekendPrice, PremiumSeat, HolidayPrice
Seat StatusState machine: AVAILABLE β†’ LOCKED β†’ BOOKED. TTL auto-releases LOCKED seats
ScaleHot shows: thousands of concurrent users. Queue-based booking with position tracking
15
Tic-Tac-Toe Game
LLD
GoogleAmazon
→

Problem

Design an extensible Tic-Tac-Toe game with O(1) win detection, undo support, and AI opponent.

Design

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Game β”‚ β”‚ - board: Board β”‚ β”‚ - players: [Player1, Player2] β”‚ β”‚ - currentTurn: int β”‚ β”‚ - moveHistory: Stack<Move> (for undo) β”‚ β”‚ + makeMove(row, col): Result β”‚ β”‚ + undo(): void β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Board (n Γ— n) β”‚ β”‚ - grid: char[][] β”‚ β”‚ - rowCount: int[] ← +1 for X, -1 for O β”‚ β”‚ - colCount: int[] β”‚ β”‚ - diagCount: int ← main diagonal β”‚ β”‚ - antiDiagCount: int ← anti diagonal β”‚ β”‚ β”‚ β”‚ Win check: O(1) β€” if any counter reaches Β±n β†’ win β”‚ β”‚ Instead of scanning entire board each move β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ PATTERNS: β€’ Command pattern β†’ Move objects stored in stack for undo β€’ Strategy pattern β†’ Player can be HumanPlayer or AIPlayer (minimax) β€’ Observer pattern β†’ UI notified on board state change

Key Decisions

O(1) Win CheckRow/col/diag counters: +1 for X, -1 for O. Counter = Β±n β†’ someone wins. No board scan
UndoCommand pattern: each Move is an object. Stack-based history. Pop to undo last move
AIMinimax algorithm with alpha-beta pruning for AI opponent. Unbeatable on 3Γ—3
ExtensibleBoard size n is configurable. Win condition adapts to n. Same logic works for 4Γ—4, 5Γ—5
16
Library Management System
LLD
MicrosoftAmazon
→

Problem

Design a library system with catalog search, book checkout/return, reservations, and fine calculation.

Design

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Library (Singleton) β”‚ β”‚ - catalog: Catalog β”‚ β”‚ - members: Map<ID, Member> β”‚ β”‚ + searchBook(query): List<Book> β”‚ β”‚ + checkoutBook(member, book): Lending β”‚ β”‚ + returnBook(lending): Fine β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β–Ό β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Book β”‚ β”‚ Member β”‚ β”‚ Lending β”‚ β”‚ - isbn β”‚ β”‚ - name β”‚ β”‚ - book β”‚ β”‚ - title β”‚ β”‚ - maxBooks=5 β”‚ β”‚ - member β”‚ β”‚ - author β”‚ β”‚ - activeLoansβ”‚ β”‚ - dueDate β”‚ β”‚ - copies β”‚ β”‚ β”‚ β”‚ - returnDate β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β” β”‚ Fine Calc β”‚ β”‚ (Strategy) β”‚ β”‚ β€’ PerDayFine β”‚ β”‚ β€’ FlatFine β”‚ β”‚ β€’ NoFine β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β€’ Observer: notify waitlisted members when book returned β€’ Strategy: fine calculation swappable per library policy β€’ Singleton: one Library instance per branch

Key Decisions

SearchCatalog indexed by title, author, ISBN. Full-text search via inverted index
ReservationQueue per book. When returned, next in queue gets 24h to pick up
FineStrategy pattern: PerDayFine($1/day), FlatFine($5), StudentDiscount. Configurable
LimitsMax 5 active loans per member. Blocked from checkout if overdue books exist
17
Payment System (Razorpay/Stripe)
HLD
AmazonGoogleMicrosoft
→

Problem

Design a payment processing system with idempotent transactions, multi-currency support, and reconciliation.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Merchant │────▢│ Payment │────▢│ Payment Serviceβ”‚ β”‚ App β”‚ β”‚ Gateway β”‚ β”‚ (idempotency β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ (TLS, auth, β”‚ β”‚ key check) β”‚ β”‚ rate limit) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β” β”‚ Payment β”‚ β”‚ State β”‚ β”‚ Machine β”‚ β”‚ INITβ†’AUTHβ†’ β”‚ β”‚ CAPTUREβ†’DONE β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β–Ό β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ PSP β”‚ β”‚ Ledger β”‚ β”‚ Wallet β”‚ β”‚ (Visa/MC/ β”‚ β”‚ (double- β”‚ β”‚ Service β”‚ β”‚ UPI/PayPal) β”‚ β”‚ entry β”‚ β”‚ (refunds)β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ accountingβ”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Reconciliation β”‚ β”‚ (daily batch β”‚ β”‚ PSP vs ledger)β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Decisions

IdempotencyUnique idempotency key per payment. DB uniqueness constraint prevents double-charge
Saga PatternDistributed transaction: auth β†’ capture β†’ ledger. Compensating actions on failure
LedgerDouble-entry bookkeeping: every debit has a credit. Ensures books always balance
ReconciliationDaily cron: compare PSP settlement report vs internal ledger. Flag mismatches
18
E-Commerce Platform (Amazon)
HLD
AmazonMicrosoft
→

Problem

Design a full e-commerce platform with product catalog, cart, orders, inventory, and delivery tracking.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Client │────▢│API GW β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β–Ό β–Ό β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚Product β”‚ β”‚ Cart β”‚ β”‚ Order β”‚ β”‚ Search β”‚ β”‚Catalog β”‚ β”‚ Service β”‚ β”‚ Service β”‚ β”‚(Elastic- β”‚ β”‚Service β”‚ β”‚ (Redis) β”‚ β”‚ β”‚ β”‚ search) β”‚ β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β–Ό β–Ό β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚Product β”‚ β”‚Inventory β”‚ β”‚Payment β”‚ β”‚Delivery β”‚ β”‚ DB β”‚ β”‚ Service β”‚ β”‚Service β”‚ β”‚Tracking β”‚ β”‚(MySQL) β”‚ β”‚(prevent β”‚ β”‚(Stripe/ β”‚ β”‚(real-timeβ”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ oversell)β”‚ β”‚Razorpay)β”‚ β”‚ status) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ EVENT-DRIVEN (Kafka): Order placed β†’ Inventory reserved β†’ Payment charged β†’ Shipping notified β†’ Delivery assigned β†’ Status updates β€’ CQRS: write to MySQL, read from Elasticsearch (denormalized) β€’ Cart in Redis (fast R/W, auto-expire abandoned carts) β€’ Inventory: optimistic locking to prevent overselling

Key Decisions

MicroservicesEach domain (product, order, payment) is independent. Communicate via Kafka events
InventoryOptimistic lock: version check on decrement. Prevents overselling during flash sales
SearchElasticsearch with filters (price, rating, brand). Denormalized product docs for fast reads
CartRedis with TTL. Merge anonymous cart with user cart on login. Fast add/remove
19
Snake & Ladder Game
LLD
GoogleMicrosoft
→

Design

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Game β”‚ β”‚ - board: Board β”‚ β”‚ - players: Queue<Player> (turn-based) β”‚ β”‚ - dice: Dice β”‚ β”‚ + play(): void (main loop) β”‚ β”‚ + isWinner(player): bool β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Board β”‚ β”‚ - size: 100 β”‚ β”‚ - snakes: Map<head, tail> {16β†’6, 47β†’26, 97β†’78} β”‚ β”‚ - ladders: Map<bottom, top> {2β†’38, 7β†’14, 28β†’84} β”‚ β”‚ + getNewPosition(pos + dice): int β”‚ β”‚ β†’ if snake/ladder at position, teleport β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ GAME LOOP: while no winner: player = players.dequeue() roll = dice.roll() # 1-6 newPos = player.pos + roll newPos = board.getNewPosition(newPos) # check snake/ladder player.pos = newPos if newPos == 100: declare winner players.enqueue(player) # back in queue β€’ Queue for fair turn management β€’ Observer for UI updates on each move β€’ Strategy for Dice (fair dice, loaded dice, etc.)

Key Decisions

BoardHashMap for snakes/ladders. O(1) lookup. No need to store all 100 cells
TurnsQueue: dequeue current player, process turn, enqueue back. Fair round-robin
RulesExact 100 to win (overshoot = stay). Triple 6 = skip turn (configurable)
ExtensibleBoard size, number of players, snake/ladder placement all configurable
20
Chess Game
LLD
GoogleAmazon
→

Design

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Game β”‚ β”‚ - board: Board(8Γ—8) β”‚ β”‚ - players: [WhitePlayer, BlackPlayer] β”‚ β”‚ - currentTurn: Color β”‚ β”‚ - status: ACTIVE | CHECK | CHECKMATE | STALEMATE β”‚ β”‚ - moveLog: List<Move> β”‚ β”‚ + makeMove(from, to): bool β”‚ β”‚ + undo(): void β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Board (8Γ—8 Cell grid) β”‚ β”‚ + getPiece(row, col): Piece β”‚ β”‚ + movePiece(from, to): void β”‚ β”‚ + isKingInCheck(color): bool β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Piece (Abstract) β€” Strategy Pattern β”‚ β”‚ - color: WHITE | BLACK β”‚ β”‚ + getValidMoves(board, pos): List<Position> β”‚ β”‚ β”‚ β”‚ King β†’ 1 step any direction + castling β”‚ β”‚ Queen β†’ row + col + diagonal (unlimited) β”‚ β”‚ Rook β†’ row + col (unlimited) β”‚ β”‚ Bishop β†’ diagonal (unlimited) β”‚ β”‚ Knight β†’ L-shape (2+1), can jump β”‚ β”‚ Pawn β†’ forward 1 (2 from start), capture diag β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ MOVE VALIDATION: 1. Piece.getValidMoves() returns all legal squares 2. Filter out moves that leave own king in check 3. If no valid moves: checkmate (if in check) or stalemate β€’ Strategy pattern: each Piece subclass defines its own movement rules β€’ Command pattern: Move objects for undo/redo history β€’ Observer: UI updates, game status notifications

Key Decisions

Move ValidationPiece generates moves β†’ filter self-check β†’ validate. O(1) for knight, O(n) for queen
Special MovesCastling, en passant, pawn promotion β€” each as separate move handler with preconditions
Check DetectionAfter each move, scan opponent pieces' attack squares for king. Cache attacked squares
Draw50-move rule, threefold repetition (hash board states), insufficient material
21
Web Crawler
HLD
Google
→

Problem

Design a distributed web crawler that fetches billions of pages, respects robots.txt, and feeds a search index.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Seed URLs │────▢│ URL Frontier β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ (Priority Queue + β”‚ β”‚ politeness queue β”‚ β”‚ per domain) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ URL to crawl β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ DNS Resolver β”‚ β”‚ robots.txt β”‚ β”‚ (cached) β”‚ β”‚ cache β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ check β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”‚ Fetcher Workers β”‚ β”‚ (multi-threaded, 1000s of workers) β”‚ β”‚ β€’ Respect crawl-delay per domain β”‚ β”‚ β€’ Timeout + retry on failure β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ HTML β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ HTML Parser β”‚ β”‚ β€’ Extract links β”‚ β”‚ β€’ Extract content β”‚ β””β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”˜ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β” β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ URL Filter β”‚ β”‚ Content Store β”‚ β”‚ (Bloom β”‚ β”‚ (S3 / HDFS) β”‚ β”‚ Filter for β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ dedup) β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ Indexer β”‚ β–Ό β”‚ (inverted index) β”‚ Back to Frontier β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Decisions

PolitenessPer-domain queue with crawl-delay (default 1s). Respect robots.txt disallow rules
DedupBloom filter for URL dedup (100M URLs, 1% false positive). Content hash for page dedup
PriorityPageRank score, freshness, domain authority determine crawl priority. BFS for breadth
ScaleConsistent hashing to shard URLs across crawler nodes. ~1B pages/day at Google scale
22
Vending Machine
LLD
AmazonMicrosoft
→

Problem

Design a vending machine with product selection, coin/card payment, change dispensing, and inventory management.

Design

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ VendingMachine (Singleton) β”‚ β”‚ - inventory: Map<Product, count> β”‚ β”‚ - currentBalance: float β”‚ β”‚ - state: State (State Pattern) β”‚ β”‚ + insertMoney(amount): void β”‚ β”‚ + selectProduct(code): Product β”‚ β”‚ + dispense(): void β”‚ β”‚ + returnChange(): float β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ State (State Pattern) β”‚ β”‚ β”‚ β”‚ IdleState β”‚ β”‚ β†’ insertMoney() β†’ HasMoneyState β”‚ β”‚ β”‚ β”‚ HasMoneyState β”‚ β”‚ β†’ selectProduct() β†’ check inventory + balance β”‚ β”‚ β†’ sufficient? β†’ DispensingState β”‚ β”‚ β†’ insufficient? β†’ stay (show "add more") β”‚ β”‚ β†’ returnChange() β†’ IdleState β”‚ β”‚ β”‚ β”‚ DispensingState β”‚ β”‚ β†’ dispense item β†’ calculate change β†’ IdleState β”‚ β”‚ β”‚ β”‚ OutOfStockState β”‚ β”‚ β†’ all actions show "Out of stock" + return money β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ CHANGE CALCULATION (Greedy): change = balance - price coins = [25, 10, 5, 1] # denominations for coin in coins: count = change // coin change -= count * coin dispense(coin, count) β€’ State pattern for clean state transitions β€’ Singleton for machine instance β€’ Observer for admin alerts (low stock, coin box full)

Key Decisions

State MachineState pattern: Idle→HasMoney→Dispensing→Idle. Prevents invalid operations per state
ChangeGreedy algorithm with largest-denomination-first. Track available coins per type
ConcurrencySynchronized operations β€” only one transaction at a time per machine
AdminObserver alerts when inventory < threshold or coin box nearing capacity