Interview Notes Search

Hello InterviewQuick Reference

Full Article

Core Concepts

Communication

Protocol Choice

HTTP over TCP is the default for most systems, Server-Sent Events push server-to-client updates, WebSockets support bidirectional real-time, and gRPC is fast for internal service-to-service calls.

  • 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 fit structured data with relationships and strong consistency, while NoSQL databases fit flexible schemas or horizontal scale without complex joins.

  • 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 is the safe interview default and avoids duplication, while denormalization duplicates data to speed reads at update cost.

  • 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 are the default relational index for lookups and ranges, while full-text indexes use Elasticsearch for document search with slight CDC lag.

  • 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 is the safe default unless money, inventory, or booking is involved, while strong consistency is for stale reads that cause business harm.

  • 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

PACELC names two tradeoffs: during a partition choose availability or consistency, and else, in normal operation, choose latency or consistency because strong consistency adds coordination latency even on a healthy network.

  • 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 hits are around 1 ms, in-data-center network calls take 1-10 ms, typical database queries take 20-50 ms, and New York to London has around 80 ms minimum latency before processing.

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.