Sheet 22

30 Core System Design Concepts & Mathematical Primer

Quantitative formulas, numbers to quote, trade-offs, and whiteboard talk-tracks for every essential system design topic.

Curated Concepts30 Applied Topics
🔌
Concept #01

APIs (REST, gRPC, GraphQL)

Ingress

Application programming interface contracts for client-to-server and internal service mesh communication.

Bandwidth & Serialization Overhead:
Network_Gbps = (Peak_RPS * Avg_Payload_KB * 8) / 1,000,000
Rule: Protobuf binaries are 3x–5x smaller than JSON; JSON serialization takes ~10µs CPU vs Protobuf ~0.8µs.
🚪
Concept #02

API Gateways

Ingress

Single ingress entrypoint managing TLS termination, JWT token validation, rate-limiting, and routing.

Gateway Pod Capacity (Multi-AZ):
Gateway_Pods = (ceil(Origin_Dynamic_RPS / Pod_Capacity_RPS) + 1) * 3 AZs
Rule: Target 60% CPU baseline utilization to leave 40% surge headroom during flash sales.
🔑
Concept #03

JWTs (JSON Web Tokens)

Ingress

Stateless, cryptographically signed tokens carrying user claims and permissions across microservices.

JWT Header Bandwidth & Verification Cost:
Daily_JWT_Bandwidth_GB = (Daily_Requests * JWT_Header_Bytes) / 10^9
Rule: Ed25519 signatures verify in ~50µs vs RSA-256 verifying in ~200µs.
🪝
Concept #04

Webhooks

Ingress

Asynchronous HTTP callbacks notifying external systems about events (payments, shipment tracking).

Outbound Webhook Worker Pool:
Webhook_Workers = ceil((Event_RPS * Timeout_Budget_Sec) / Worker_Concurrency)
Rule: Never call 3rd-party webhook endpoints synchronously on client checkout threads.
📊
Concept #05

REST vs GraphQL

Ingress

Resource-based REST endpoints vs client-driven declarative GraphQL query graphs.

Mobile Bandwidth Reduction:
Overfetch_Saved_MB = Daily_Requests * (REST_Size_KB - GQL_Size_KB) / 1024
Rule: GraphQL saves 40–60% payload bytes on mobile cellular networks, but increases server AST parse CPU.
⚖️
Concept #06

Load Balancing (L4 vs L7)

Ingress

Layer 4 TCP pass-through load balancing vs Layer 7 HTTP application-aware routing.

Load Balancer Concurrency & Line Speed:
Concurrent_Sockets = Peak_RPS * Avg_Connection_Hold_Sec
Rule: L4 NLB handles millions of RPS per static Anycast IP; L7 ALB inspects headers and paths at ~25k RPS/node.
🛡️
Concept #07

Proxy vs Reverse Proxy

Ingress

Forward proxy (protects & caches for clients) vs Reverse proxy (protects, balances & caches for servers).

Reverse Proxy SSL & Buffer Offload:
SSL_Handshakes_Sec = Peak_RPS * (1 - TLS_Session_Resumption_Pct / 100)
Rule: A reverse proxy hides backend server IPs, performs gzip/Brotli compression, and buffers slow client uploads.
📈
Concept #08

Scalability (Horizontal vs Vertical)

Reliability

Scaling up (larger CPU/RAM hardware) vs scaling out (adding more stateless commodity nodes).

Horizontal Pod Autoscaler (HPA):
Required_Replicas = ceil(Current_RPS / Target_RPS_Per_Pod)
Rule: Vertical scaling hits diminishing returns above 128 vCPUs ($5k+/mo); horizontal scaling provides linear cost elasticity.
⏱️
Concept #09

Availability & SLAs (The 9s Rule)

Reliability

Mathematical measurement of system uptime and allowable annual downtime budgets.

Downtime Budget Calculation:
Max_Allowed_Downtime_Minutes = 525,600 min/yr * (1 - Uptime_Pct / 100)
Rule: 99.9% (3 nines) = 8.76 hrs/yr; 99.99% (4 nines) = 52.6 min/yr; 99.999% (5 nines) = 5.26 min/yr.
⚠️
Concept #10

SPOF (Single Point of Failure)

Reliability

Identifying and eliminating architectural components whose failure halts the entire system.

System Reliability Product Rule:
System_Availability = Availability_Hop1 * Availability_Hop2 * ... * Availability_HopN
Rule: Every tier must have at least 3 nodes across 3 Availability Zones with automated health-check failover.
📐
Concept #11

CAP & PACELC Theorem

Reliability

Consistency vs Availability vs Partition Tolerance in distributed data storage.

PACELC Tradeoff Model:
If Partition (P) -> Tradeoff (A vs C) | Else (E) -> Tradeoff (Latency L vs Consistency C)
Rule: You cannot choose CA across network partitions; you must choose CP (Spanner, HBase) or AP (Cassandra, DynamoDB).
🗄️
Concept #12

SQL vs NoSQL

Reliability

Relational ACID structured databases vs non-relational distributed document/key-value stores.

Database Throughput Sizing:
DB_Nodes = ceil(Total_QPS / Single_Node_QPS_Capacity)
Rule: SQL excels for relational joins, ACID transactions, and complex filtering; NoSQL scales writes horizontally to 100k+ QPS.
🔒
Concept #13

ACID Transactions & Isolation Levels

Reliability

Atomicity, Consistency, Isolation, and Durability guarantees across relational databases.

MVCC Lock Contention & Transaction Latency:
Txn_Duration_ms = Lock_Wait_ms + Query_Execution_ms + WAL_Flush_ms
Rule: Read Committed is the default in PostgreSQL; Repeatable Read prevents non-repeatable reads; Serializable prevents phantom anomalies.
🔍
Concept #14

Database Indexes (B+ Tree Mechanics)

Storage

B+ Tree indexing structures accelerating search lookups from $O(N)$ table scans down to $O(\log N)$.

B+ Tree Height & Index RAM Size:
BTree_Height = ceil(log_Fanout(Total_Rows)) | Index_RAM = Rows * (Key_Bytes + Pointer_Bytes)
Rule: With a fanout of 100, a B+ Tree holds 100M rows in only 4 levels (maximum 4 disk I/O lookups).
🧩
Concept #15

Database Sharding

Storage

Horizontal partitioning of database rows across independent physical database servers.

Required Shard Count:
Shard_Count = max(ceil(Total_Write_QPS / Node_Write_Limit), ceil(Total_Storage_TB / Node_Disk_TB))
Rule: Shard by high-cardinality keys (`customer_id`, `uuid`) to ensure even write and storage distribution.
Concept #16

Consistent Hashing

Storage

Circular hash ring distributing keys across servers minimizing data remapping when nodes are added or removed.

Key Remapping Ratio & Virtual Nodes:
Keys_Moved_On_Node_Change = 1 / N_Nodes | Virtual_Nodes_Per_Server = 150 - 250
Rule: Standard modulo hashing ($K \bmod N$) remaps ~100% of keys on node failure; Consistent Hashing remaps only $1/N$ keys.
🔄
Concept #17

CDC (Change Data Capture)

Storage

Capturing row-level database changes directly from the Write-Ahead Log (WAL) to stream into downstream systems.

CDC Event Streaming Throughput:
CDC_MBps = (DB_Write_IOPS * Avg_Row_Size_KB) / 1024
Rule: CDC reads the database transaction log directly, imposing <2% CPU overhead on the primary database.
Concept #18

Caching Architecture & The 80/20 Rule

Storage

In-memory caching tiers (Redis/Memcached) storing hot query results to eliminate disk I/O.

Pareto Working Set Sizing:
Hot_Working_Set_RAM_GB = (Total_Catalog_SKUs * 0.20 * SKU_Size_KB * 1.30_Overhead) / 10^6
Rule: Pareto Principle: 20% of catalog items generate 80% of read traffic. Size RAM to hold 100% of that 20% working set.
🗂️
Concept #19

Caching Strategies

Storage

Cache-Aside, Write-Through, Write-Behind (Write-Back), and Refresh-Ahead data synchronization patterns.

Cache Miss Latency Impact:
Blended_Latency_ms = (Hit_Ratio * Cache_ms) + ((1 - Hit_Ratio) * (Cache_ms + DB_ms + Cache_Write_ms))
Rule: Use Cache-Aside for read-heavy workloads; use Write-Through for strictly consistent user sessions.
🧹
Concept #20

Cache Eviction Policies (LRU vs LFU)

Storage

Algorithms determining which data to evict when in-memory RAM reaches maxmemory capacity.

Redis Maxmemory Configuration:
Configured_Maxmemory_GB = Total_Host_RAM_GB * 0.75 (Leaves 25% for BGSAVE & replication buffer)
Rule: Use `allkeys-lru` for general web traffic; use `volatile-lru` if only specific temporary keys should expire.
🌐
Concept #21

CDN & Anycast Edge Points of Presence

Traffic

Global network of edge edge servers caching static media and accelerating dynamic API handshakes.

CDN Edge Traffic Offload:
Origin_RPS = Total_Client_RPS * (1 - CDN_Cache_Hit_Pct / 100)
Rule: A global CDN absorbs 85%+ of read traffic, protecting the origin API Gateway from volumetric surges.
🛑
Concept #22

Rate Limiting Algorithms

Traffic

Controlling client request frequency to prevent DDoS attacks, brute-forcing, and noisy-neighbor API abuse.

Sliding Window Counter Ops:
Redis_Memory_Per_User = 2_Keys * 64_Bytes | Token_Refill_Rate = Max_Requests / Window_Seconds
Rule: Token Bucket allows brief bursts; Sliding Window Counter provides strict rate enforcement with low memory.
📨
Concept #23

Message Queues & Streaming (Kafka vs RabbitMQ)

Messaging

Asynchronous event streaming and message queuing decoupling microservices and buffering load spikes.

Kafka Partition & Broker Sizing:
Partitions = ceil(Ingress_MBps / 10_MBps_Producer_Cap) | Brokers = max(3, ceil(Partitions / 24))
Rule: RabbitMQ is a push-based transient message broker; Kafka is an append-only distributed commit log.
🌸
Concept #24

Bloom Filters

Traffic

Space-efficient probabilistic data structure testing whether an element is definitely not in a set or possibly in a set.

Bloom Filter Bit Array & Optimal Hashes:
Bits_m = -(n * ln(p)) / (ln(2))^2 | Hashes_k = (m / n) * ln(2)
Rule: A Bloom filter uses only ~9.6 bits per item for a 1% false positive error rate ($p=0.01$).
🔁
Concept #25

Idempotency & Deduplication

Traffic

Ensuring an operation produces identical results regardless of how many times it is executed or retried.

Idempotency Key Cache Footprint:
Idem_Cache_RAM = Daily_Mutations * (UUID_Bytes + Status_Bytes + Response_JSON_Bytes)
Rule: Clients must pass a unique `Idempotency-Key: UUIDv4` header on all mutating POST and PUT requests.
Concept #26

Concurrency vs Parallelism (Little’s Law)

Messaging

Concurrency (dealing with lots of things at once) vs Parallelism (executing multiple things simultaneously).

Little’s Law (Inflight Request Concurrency):
Concurrent_Requests_L = Throughput_lambda (RPS) * Latency_W (seconds)
Rule: If your API handles 6,600 RPS with an average latency of 50ms (0.05s), there are exactly 330 concurrent requests inflight.
📡
Concept #27

Long Polling vs WebSockets vs Server-Sent Events (SSE)

Messaging

Protocols for real-time bi-directional and uni-directional server-to-client communication.

Concurrent WebSocket Memory Buffer:
WebSocket_RAM_GB = (Concurrent_Sockets * TCP_Socket_Buffer_KB) / 10^6
Rule: Use WebSockets for bi-directional real-time chat/gaming; use SSE for uni-directional live feeds/stocks.
🏢
Concept #28

Stateful vs Stateless Architecture

Messaging

Decoupling application compute from persistent session state to enable rapid auto-scaling and failover.

Session Externalization Throughput:
Session_Store_Ops = Peak_RPS * (1_Read_Per_Req + Auth_Write_Ratio)
Rule: Stateless pods can be terminated, updated, or autoscaled at any second without dropping user sessions.
🌊
Concept #29

Batch vs Stream Processing (Lambda vs Kappa)

Messaging

Real-time event-by-event stream processing (Flink/Kafka Streams) vs bounded batch processing (Spark/Snowflake).

Streaming Event Lag & Windowing:
Max_Event_Lag_Sec = (Queued_Messages / Consumer_Throughput_Per_Sec) + Processing_Window_Sec
Rule: Kappa Architecture uses a single streaming pipeline (Kafka + Flink) for both real-time and historical analytics.
📍
Concept #30

Geohashing & Spatial Proximity Indexing

Messaging

Hierarchical spatial indexing encoding latitude and longitude coordinates into short alphanumeric strings.

Geohash Precision & Bounding Box Area:
Geohash_Length_6 = ~1.2 km * 0.6 km area | Neighbor_Search = 8_Surrounding_Boxes + Center
Rule: Geohashing converts 2D (lat, lng) spatial queries into a 1D string prefix search indexed by standard B+ Trees.