Code-Memo

API Architecture Styles

REST vs GraphQL tradeoffs

  1. REST maps cleanly to HTTP caching and simple CDNs; multiple round trips can hurt mobile UIs.
  2. GraphQL reduces over-fetching with field selection but needs query cost limits and careful N+1 data loading.
  3. Pick per boundary: public mobile BFF might use GraphQL; internal infra often stays REST/gRPC.

gRPC basics

  1. IDL-first (Protobuf), binary on the wire, strong typing, streaming primitives.
  2. Excellent for low-latency service meshes; less browser-friendly than JSON HTTP.
  3. Version messages carefully; unknown fields are ignored by design in protobuf.

Webhooks (event-driven APIs)

  1. You push events to subscriber URLs over HTTPS with signatures and retries.
  2. Subscribers must be idempotent and fast (ack quickly, process async).
  3. Offer delivery logs, replay, and DLQ patterns for reliability.

Polling vs push models

  1. Polling is simple but wastes traffic; use conditional requests or cursors to reduce cost.
  2. Push (webhooks, SSE, WebSockets) improves latency when clients can receive inbound connections.
  3. Mobile often needs FCM/APNs instead of raw persistent sockets for background events.