Communication
Protocol Choice
- HTTP over TCP: Default for most systems; well-understood and handles 90% of use cases.
- Server-Sent Events (SSE): Server-to-client pushes after one HTTP request; simpler than WebSockets.
- WebSockets: True bidirectional real-time; stateful and typically need Layer 4 balancing.
- gRPC: Fast internal service-to-service; not for public APIs because browsers lack native support.
API Defaults
Use REST for public APIs
Default for 90% of interviews; map resources to URLs with HTTP methods.
Add pagination for large results
Cursor-based for real-time additions; offset-based is fine for most cases.
Data Storage
Storage Model
- Relational databases: Default when data is structured with clear relationships and strong consistency.
- NoSQL databases: Use for flexible schemas or horizontal scale without complex joins.
Read Shape
- Normalization: Safe interview default; avoids duplication but joins can get expensive.
- Denormalization: Duplicate data for faster reads; updates must repair every copied value.
Index Choice
- B-tree indexes: Default relational index; supports exact lookups and range queries.
- Full-text indexes: Use Elasticsearch for searching tweets or documents; CDC sync can lag slightly.
Caching
Use cache-aside with Redis
Default for read-heavy data: check cache, fill from database on miss with TTL.
Invalidate after writes
Delete or update cached copies, or use short TTLs and accept staleness.
Prevent cache stampedes
Use locking, early recomputation, or staggered TTLs to avoid thundering herds.
Plan for Redis outage
Use in-process fallback cache, circuit breakers, or graceful degradation.
Scaling Data
Do capacity math first
Don't shard at 10K writes per second and 100GB; a tuned database can handle more.
Choose shard key by access pattern
A user_id key makes user-scoped reads fast; global queries must hit every shard.
Use hash-based sharding
Default for even distribution; hash the shard key and modulo to pick a shard.
Use consistent hashing for elasticity
Add or remove nodes by moving only the affected ring range, not most data.
Consistency
Consistency Models
- Eventual consistency: Safe default unless money, inventory, or limited-resource booking is involved.
- Strong consistency: Use when stale reads cause business harm, like balances, stock, or seats.
PACELC Tradeoffs
- During a Partition: Choose Availability or Consistency; partitions are relatively rare.
- Else (normal operation): Choose Latency or Consistency; strong consistency adds coordination latency.
Capacity Numbers
Latency Numbers
Cache hit
Redis cache hit around 1 ms.
In-DC network call
Network calls within a data center take 1-10 ms.
Database query
Typical database query takes 20-50 ms.
NY to London request
Minimum latency is around 80 ms before processing.
Throughput Numbers
Database server
A well-tuned database server handles up to 50k transactions/second.
Redis instance
A single Redis instance handles 100k+ operations/second.
Message queue broker
A broker handles up to 1 million msgs/sec per broker.

Your account is free and you can post anonymously if you choose.