System Design
87 flashcards by MentisLibrary
Scaling, caching, load balancing, sharding, queues, CAP, and consistency models, each card naming the tradeoff you are actually making. Written for design interviews and for real architecture decisions.
- Vertical scaling
- Making one machine more capable by adding CPU, memory, or faster storage.
- Horizontal scaling
- Adding more machines and spreading the work across them.
- Why does statelessness matter for scaling?
- If a server holds no session state, any request can go to any instance, so you can add, remove, or restart nodes freely.
- Load balancer
- A component that distributes incoming requests across a pool of backend servers and removes unhealthy ones from rotation.
- Common load balancing algorithms
- Round robin, least connections, weighted variants, and consistent hashing by a key.
- Health check
- A periodic probe the load balancer or orchestrator uses to decide whether an instance should receive traffic.
- Caching
- Storing the result of an expensive computation or query close to where it is needed so later requests skip the work.
- Cache-aside (lazy loading)
- The application checks the cache, and on a miss it reads the database and writes the result back into the cache.
- Write-through cache
- Every write goes to the cache and the database together, so the cache is never stale.
- Write-behind cache
- Writes go to the cache and are flushed to the durable store asynchronously.
- Cache eviction policies
- Rules for what to discard when a cache is full: LRU, LFU, FIFO, or random.
- Cache stampede (thundering herd)
- A popular key expires and many concurrent requests all miss and hit the database at once.
- TTL
- A time to live after which a cached entry is considered expired and is refetched.
- Cache invalidation strategies
- Expire by TTL, delete on write, or version the key so a new version is written instead of updated.
- CDN
- A geographically distributed network of edge caches that serves static and cacheable content close to the user.
- Content delivery cache key
- The set of request attributes that identify a cached variant at the edge, typically URL plus selected headers or query parameters.
- Database replication
- Copying data from a primary to one or more replicas, usually to serve reads and to provide failover.
- Replication lag
- The delay between a write committing on the primary and appearing on a replica.
- Synchronous versus asynchronous replication
- Synchronous waits for a replica to acknowledge before the write returns; asynchronous does not.
- Failover
- Promoting a replica to primary when the current primary fails.
- Sharding (partitioning)
- Splitting a dataset across multiple databases so each holds only part of the data.
- Shard key
- The field used to decide which shard a record lives on.
- Range-based versus hash-based sharding
- Range assigns contiguous key intervals to shards; hash spreads keys pseudo-randomly.
- Consistent hashing
- A hashing scheme placing nodes and keys on a ring so adding or removing a node moves only a small fraction of the keys.
- Hot partition
- A shard or key receiving a disproportionate share of traffic, becoming the system's bottleneck.
- Denormalization
- Deliberately duplicating data across tables or documents to avoid joins at read time.
- Normalization
- Structuring data so each fact is stored once, with relationships expressed by keys.
- Index
- A secondary structure that lets the database find rows by a column value without scanning the whole table.
- Composite index column order
- Order columns by equality predicates first, then the sort column, then range predicates.
- SQL versus NoSQL
- Relational databases offer schemas, joins, and strong transactions; NoSQL stores trade some of those for flexible schemas and easier horizontal scale.