Code-Memo

Performance & Scalability

Caching (HTTP caching headers)

  1. Use Cache-Control, ETag, and Last-Modified for GETs that are safe to cache at CDNs or browsers.
  2. Mark personalized responses private or no-store as appropriate.
  3. Invalidate or shorten TTL when correctness beats freshness (balances, entitlements).

ETags and conditional requests

  1. ETag lets clients send If-None-Match to skip large bodies when nothing changed (304).
  2. Strong vs weak ETags matter for byte-identical semantics; document which you emit.
  3. Combine with Range requests only when you fully understand intermediaries.

Rate limiting strategies

  1. Token bucket for smooth bursts; sliding window for fairness; per-tenant quotas for SaaS.
  2. Return structured quota headers (X-RateLimit-*, RateLimit-* drafts) when helpful.
  3. Coordinate limits with API gateway and service-level budgets.

Bulk operations vs single requests

  1. Bulk reduces round trips but increases payload size, timeouts, and partial failure complexity.
  2. Prefer bounded batch sizes and per-item error reporting in the response.
  3. For huge jobs, use 202 + async processing instead of multi-minute HTTP requests.

Payload optimization

  1. Enable gzip/Brotli at the edge; trim unused fields with sparse fieldsets or GraphQL-like projections if supported.
  2. Avoid N+1 chatty patterns; offer includes or dedicated aggregate reads when needed.
  3. Watch serialization cost on hot paths (large JSON maps, deeply nested objects).