API Gateways and API Management Questions
The management layer in front of APIs: gateways for routing, authentication, rate limiting, request/response transformation, and observability. Covers API management concerns such as developer portals, key provisioning, plan/tier enforcement, analytics, and centralized policy. The operational and productization surface of an API program.
Compare a centralized API gateway approach versus decentralized client SDKs and Backend-For-Frontend (BFF) patterns. Discuss governance, latency, development velocity, deployment independence, security, and propose a migration path to evolve from a centralized gateway to a more modular architecture if needed.
Sample Answer
Centralized API Gateway vs Decentralized Client SDKs + BFFs
Summary: A centralized API gateway provides a single ingress for routing, auth, rate-limiting, and observability. Decentralized approach pushes protocol/aggregation logic closer to clients via BFFs and/or client SDKs, improving client-specific optimization and autonomy but increasing operational surface.
Governance
- Gateway: Strong centralized policy enforcement (auth, quotas, contract validation). Easier compliance and auditing.
- BFFs/SDKs: Governance must be distributed—use shared libraries, contract tests, and CI gates to ensure consistency. Requires strong platform tooling and policy-as-code.
Latency
- Gateway: Low hop-count for simple passthrough but can add processing latency at scale. Good for ingress-level caching.
- BFFs/SDKs: BFFs can reduce client-perceived latency by aggregating calls and serving tailored payloads; SDKs reduce client parsing work and enable optimistic/local caching.
Development velocity
- Gateway: Faster for cross-cutting changes (single place), but teams are blocked by central change cycles.
- BFFs/SDKs: Teams move faster (independent releases, domain-driven APIs), but risk duplication without shared components.
Deployment independence
- Gateway: Central point can be a release chokepoint.
- BFFs/SDKs: Independent deployability for each client surface improves rollout flexibility and experimentability.
Security
- Gateway: Centralized enforcement simplifies threat protection, TLS termination, WAF rules.
- BFFs/SDKs: Need consistent security libraries, token handling practices, and automated scanning; more endpoints to secure.
Migration path (from gateway → modular)
- Assess: Inventory routes, usage patterns, and consumer needs; identify high-latency or high-change areas.
- Stabilize contracts: Introduce API versioning, OpenAPI specs, and contract tests; enforce at gateway.
- Extract low-risk BFFs: Start with a single client (mobile/web) that needs tailored responses; implement BFF that calls existing backend via gateway or internal APIs.
- Introduce client SDKs gradually: Provide language-specific SDKs for common cross-cutting concerns (auth, retries, caching) to reduce duplication.
- Move routing incrementally: Use gateway for auth/edge concerns, route specific client traffic to BFFs via path or header-based routing. Canary and measure.
- Automate governance: Implement policy-as-code (Open Policy Agent), centralized observability (traces/metrics), and CI contract checks.
- Iterate: Promote successful patterns, decommission gateway responsibilities only once parity in security/compliance and monitoring exists.
Recommendation: Keep the gateway for edge responsibilities (auth, rate limits, TLS, WAF) while evolving to BFFs/SDKs for client-specific logic to maximize developer velocity and low-latency UX, backed by strong platform tooling for governance and security.
You're evaluating API management vendors. Create a checklist of technical criteria and non-technical factors (support, roadmap, pricing) that matter to enterprise customers concerned about security, scalability and multi-cloud deployment.
Sample Answer
High-level goal: pick an API management vendor that meets enterprise needs for security, scalability and multi‑cloud portability while fitting procurement, operations and roadmap expectations. Checklist below separates technical criteria and non‑technical factors, with why each matters and measurable examples.
Technical criteria (must-haves)
- Security
- OAuth2/OpenID Connect, mTLS, JWT validation, granular RBAC and key rotation (example: support for asymmetric key rotation without downtime).
- WAF/OWASP protections, bot detection, threat intel integration, IDS/IPS hooks.
- Data protection: TLS 1.3, field-level encryption, PII redaction and workload encryption at rest.
- Deployment & portability
- Support for hybrid and multi‑cloud: Kubernetes operators, Helm charts, Terraform providers, OCI/AMI artifacts.
- Ability to run in VPC/air‑gapped environments and consistent config-as-code.
- Scalability & resilience
- Horizontal scaling on K8s, autoscaling policies, global rate limiting, geo‑routing and active‑active deployment patterns.
- SLAs for throughput and latency; support for circuit breakers, retries, backpressure.
- Observability & operations
- End‑to‑end tracing (OpenTelemetry), request/response logging, metrics (Prometheus), dashboards and alerting.
- CI/CD integration, blue/green and canary deployment hooks.
- Extensibility & governance
- Policy engine for transformations, plugins (Lua/JavaScript/WebAssembly), API versioning and lifecycle management.
- Developer portal, API catalog, automated policy compliance, analytics for usage and cost.
- Performance & testing
- Benchmarks for p95/p99 latency under load, support for caching, request batching, and native CDN integrations.
- Compliance & certifications
- SOC2/ISO27001, GDPR, HIPAA (if relevant), evidence of pen tests.
Non-technical factors (selection & long‑term viability)
- Support & services
- 24/7 enterprise support, named TAM, escalation SLA, runbooks and onboarding assistance.
- Roadmap & community
- Public roadmap cadence, openness to feature requests, active community/contributor base, documented deprecation policy.
- Pricing & total cost of ownership
- Transparent pricing models (per request, per gateway, per developer), cost projections at projected scale, hidden costs (ingress/egress, feature add‑ons).
- Vendor stability & ecosystem
- Financial health, customer references in your industry, partner integrations (IDPs, observability, WAF, CDNs).
- Legal & procurement
- Contract flexibility, liability limits, data residency clauses, exit/transition plan and exportable configuration.
- Implementation risk
- Estimated time to production, required ops skills, training availability, professional services cost.
How to evaluate practically
- Create a scoring matrix with weightings tied to priorities (security 35%, scalability 25%, multi‑cloud 20%, cost 10%, support 10%).
- Run a focused PoC: deploy in two clouds, simulate 2–4M RPS patterns, validate auth flows, failover and monitoring.
- Ask for customer references with similar scale and compliance needs and request OLA/SLA drafts.
This checklist helps quantify trade-offs and reduces procurement risk while ensuring the chosen API platform meets enterprise security, scale and multi‑cloud requirements.
Design an API gateway and internal layered services to support A/B testing, traffic shaping, and request-level rewriting. Discuss where experiment assignment occurs, how services stay decoupled from experiment logic, the impact on caching and CDN behavior, and how to measure experiment impact while minimizing measurement bias.
Sample Answer
Goal: Support A/B testing, traffic shaping, and request rewriting while keeping services decoupled and minimizing bias.
Where Assignment Occurs:
- Do experiment assignment at the edge/API gateway or a dedicated experiment service. Use deterministic bucketing (client id + experiment id) to ensure sticky assignments.
Decoupling Experiment Logic:
- Gateway injects assignment metadata (headers) but services read only these headers and remain agnostic to experiment internals. Experiment rules live outside services in a feature-management system.
- Services implement hooks for behavior based on header flags; no direct feature code branching on experiment config.
Traffic Shaping & Rewriting:
- Perform request-level rewriting at gateway or edge workers. For rewrites that affect caching keys, include experiment id in cache key to avoid contamination.
Impact on Caching/CDN:
- Use cache key partitioning: append experiment id or variant tag to cache key only for experiments that change response semantics.
- Where experiments don't change response, avoid adding noise to cache keys to preserve cache efficiency.
Measurement & Minimizing Bias:
- Randomize assignment at edge before routing; ensure logging of assignment at source and consistent user identity across layers.
- Use holdout groups, traffic-split controls, and differential logging to detect instrumentation bias. Avoid sampling skew by ensuring experiment-enabled traffic distribution mirrors production.
- Instrument telemetry for feature exposure, downstream effects, latency, and success metrics; use denoising techniques (covariate adjustment) in analysis.
Operational Controls:
- Offer kill-switch at gateway, automated rollback thresholds, and canary ramps. Keep experiment configs versioned and audited.
This design supports sales conversations by enabling experiments safely across customers with clear metrics and rollback capabilities.
Design an API Gateway for a multi-tenant B2B SaaS platform that supports per-tenant routing, per-tenant rate limits, OAuth2 authentication, and tenant isolation. Describe key components, how to implement tenant-aware policies, caching, failover, and how to ensure high performance under peak load while preventing noisy-tenant impact.
Sample Answer
Requirements (clarify): per-tenant routing to different backend clusters/features, per-tenant OAuth2 auth, per-tenant rate-limits and quotas, strict tenant isolation (security + noisy-tenant protection), high availability and low latency at peak.
High-level architecture:
- Edge layer: Global load balancer (Anycast/Cloud LB) → API Gateway fleet (stateless, autoscaling).
- Auth & policy service: OAuth2 token introspection/authorization, tenant metadata store.
- Control plane: Tenant config store (consul/etcd/DB), policy management UI/CI.
- Data plane: Gateway plugins (routing, rate-limit, caching, observability) → Tenant-specific backend clusters (or shared with logical isolation).
- Observability/Quota DB: high-throughput time-series DB and Redis for counters.
Key components & implementation:
- API Gateway (Envoy/NGINX/Traefik or managed APIGW) with dynamic config; use xDS or service mesh for pushing per-tenant routes.
- Tenant metadata: store tenant_id, routing rules, rate-limit tiers, OAuth client config, isolation level.
- OAuth2: gateway validates access tokens via introspection or JWT verification using tenant-specific keys; support token audience/claims checks.
Tenant-aware policies:
- At request arrival, gateway extracts tenant_id (subdomain, header, token claim).
- Lookup policy cache (local LRU + warm-up) for routing, rate-limits, feature flags.
- Apply per-tenant rate limiter (Leaky Bucket/Token Bucket implemented in Redis or local + Redis sync for distributed limits). For strict isolation, route to dedicated backend pool.
Caching:
- Edge-level CDN for static/responses; gateway-level response cache keyed by tenant+URI+auth-scope.
- Use per-tenant cache TTLs and size limits; cache partitioning by tenant namespace to prevent eviction storms.
Failover & resilience:
- Circuit breakers per backend and per-tenant to prevent cascading failures.
- Fallback responses or degraded feature routes.
- Multi-AZ deployment, active-active; health checks and quick failover.
High performance & noisy-tenant mitigation:
- Autoscale gateway pods based on RPS and latency; pre-warm capacity for major tenants.
- Token bucket limits per tenant with “guaranteed/borrowing” model: reserve baseline capacity, allow burst capacity if unused, and enforce hard caps.
- Prioritization: assign priority queues; throttle low-priority tenants under overload.
- Resource isolation: for top-tier tenants consider dedicated gateway/compute pools.
- Instrumentation + alerts for noisy behavior; automated quarantine: reduce burst window, move to dedicated backend, or require upgrade.
Trade-offs:
- Strong isolation (dedicated infra) increases cost; shared infra with strict soft/hard limits balances cost and fairness.
- Use of Redis for distributed counters gives accuracy but adds latency; consider local counters with periodic sync for lower latency.
Operational considerations:
- CI/CD for policy updates with validation tests, canary rollout of tenant rules.
- RBAC in control plane so tenant admins can manage configuration without affecting others.
- Regular load testing and chaos drills to validate noisy-tenant protections.
A misbehaving client is overwhelming your service causing resource exhaustion. Design a throttling and rate-limiting strategy to protect the platform while minimizing impact to well-behaved clients. Compare token-bucket and leaky-bucket approaches, explain per-client vs global limits, tiered limits, 429 semantics, and backpressure techniques.
Sample Answer
Requirements & goals:
- Protect overall platform availability and CPU/memory while minimizing false positives for good clients.
- Provide fair-share, predictable degradation, visibility, and configurability per customer/tier.
High-level strategy:
- Multi-layer limits:
- Edge/global ingress (fast, coarse): protect network & common pools.
- Per-tenant / per-client limits (fine-grained): protect backend resources and ensure fairness.
- Per-endpoint or per-API-key limits for hot paths.
Token-bucket vs Leaky-bucket:
- Token-bucket: allows bursts up to bucket size while enforcing average rate (good for user-facing APIs that need transient bursts). Implementation: refill tokens at rate r; each request consumes token(s).
- Leaky-bucket: enforces constant outflow (smooths traffic) — better for steady backend processing, easier to bound resource usage.
- Trade-off: token-bucket favors latency/UX (burst tolerance); leaky-bucket favors predictability and easier backpressure control. Combine: token-bucket at edge for burst absorb, leaky-bucket or queueing at service for smoothing.
Per-client vs Global limits:
- Per-client: prevents noisy neighbor; set based on client SLA/tier and observed patterns. Include dynamic adjustments (adaptive throttling) based on recent error/latency signals.
- Global: emergency circuit-breaker to protect the whole cluster; triggered when aggregate CPU/latency thresholds hit.
- Enforce both: evaluate per-request against per-client then global quota; if either exceeded, deny or degrade.
Tiered limits and fairness:
- Map account tiers → base-rate and burst-size. Use weighted fair-queuing for proportional allocation when overloaded.
- Provision soft vs hard limits: soft triggers warnings/slowdowns; hard rejects.
- Graceful degradation: reduce feature-level rates (e.g., lower-fidelity responses, batch endpoints) before outright rejections.
429 semantics & client guidance:
- Use HTTP 429 for rate-limited responses.
- Provide Retry-After header with seconds or HTTP-date.
- Include structured body: current-rate, limit, retry-after, request-id, quota-window. Example: {"error":"rate_limited","limit":100,"remaining":0,"retry_after":30}
- Differentiate 429 for transient burst (Retry-After short) vs sustained quota (longer, include link to docs/account upgrade).
Backpressure techniques:
- Push slower response codes (202 Accepted) for async work; provide job-id and status endpoint.
- Server-driven throttling: reduce concurrency, return 429 or 503 depending on severity.
- Client-cooperative backoff: exponential backoff with jitter; expose server-suggested backoff via Retry-After and recommended backoff algorithm docs.
- Queueing with bounded in-memory queues + persistent task queues for non-latency-sensitive work.
- Circuit breakers & hysteresis: open circuits when backend latency/queue-length crosses thresholds; close gradually.
Observability & operations:
- Emit per-key metrics: requests/sec, 429 count, avg latency, tokens consumed.
- Alerting on rising 429 rates, error-rates, and saturation metrics.
- Support dynamic config: rate limits via central config/feature flags and per-tenant overrides.
Implementation notes:
- Use distributed counters (Redis with Lua for atomicity) or token-bucket libraries with local caching + periodic sync for low latency.
- For high scale, use local token-buckets per node + centralized leakproof quota coordinator (allow short bursts local, reconcile centrally).
- Ensure idempotency and retries safe; document idempotency keys for clients.
Example enforcement flow:
- Authenticate → determine client_id & tier.
- Check per-client token-bucket (local fast path).
- If tokens exhausted → respond 429 with Retry-After.
- If passes, forward; monitor downstream latency and if cluster overloaded trigger global reject or route to async queue.
This combination protects platform health, preserves UX for good clients, and provides operational controls to tune behavior per customer and workload.
Unlock Full Question Bank
Get access to all 11 API Gateways and API Management interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.