dev-tools
Glossary ↗API Gateway
An API gateway is a server that sits in front of one or more backend services and acts as the single entry point for all API traffic, handling cross-cutting concerns centrally instead of duplicating that logic in every individual service. Common responsibilities include request routing (sending `/users/*` to the users service and `/orders/*` to the orders service), authentication and authorization (validating API keys or JWTs before a request ever reaches a backend), rate limiting (blocking a client that exceeds their quota), request/response transformation, and centralized logging and monitoring. Popular implementations range from managed cloud services (AWS API Gateway, Azure API Management) to open-source/self-hosted options (Kong, Tyk, Apache APISIX) to the API-gateway layer built into most modern serverless and edge platforms. Why it matters for AI/SaaS builders: an API gateway is especially critical once a SaaS product has multiple backend services (a microservices architecture) or wants to expose a public API to third-party developers, since it centralizes security and rate-limiting policy in one place rather than trusting every individual service to implement it correctly and consistently. It's also the natural place to enforce API monetization (metering usage per API key for billing) and to protect AI-powered endpoints specifically from abuse, since LLM API calls are expensive per-request compared to typical CRUD endpoints. How it works: every incoming request hits the gateway first. The gateway checks the request against configured rules — is the API key valid? has this client exceeded their rate limit? does the JWT's scope allow this action? — and only if all checks pass does it forward (proxy) the request to the appropriate backend service, often adding headers identifying the authenticated client. The backend's response flows back through the gateway, which may log it, transform it, or cache it before returning it to the original caller. Worked example: a SaaS company launches a public API for third-party developers to query their analytics data, priced per 1,000 requests. Every call to `api.example.com/v1/analytics` hits their API gateway first. The gateway validates the caller's API key against a database, checks that they haven't exceeded their plan's monthly quota (say, 100,000 requests), increments a usage counter for billing, and only then forwards the actual query to the internal analytics service — which never has to implement auth or rate-limiting itself, because the gateway already guaranteed only valid, in-quota requests reach it. If a caller exceeds their quota, the gateway itself returns a `429 Too Many Requests` without the internal service ever being touched.
Related terms