API Gateway
Overview
An Express-based API Gateway for routing requests to microservices, handling authentication, logging, and error management. It serves as the entry point for client requests and coordinates communication between the gateway and underlying services.
Request Life-Cycle Summary
| 1. | Client request | Includes API key in header |
| 2. | Middleware | Hashes and verifies key (Cache --> Supabase) |
| 3. | Metrics | Logged for Prometheus |
| 4. | Rate limiter | Enforces request quotas |
| 5. | Request | Proceeds to endpoint handler if verified |
| 6. | Supabase RPC | Updates usage counters asynchronously |
| 7. | Grafana dashboard | Visualises metrics and logs |
Service-Routing
The Servie Routing Map defines how incoming routes on the API Gateway are fowarded to corresponding microservices.
Each API Gateway route prefix (e.g. /synthesis) is mapped to the actual URL of its corresponding microservice.
const SERVICE_MAP = {
"/users": `http://users_service:${process.env.USERS_PORT}`,
"/products": `http://products_service:${process.env.PRODUCTS_PORT}`,
"/synthesis": `${process.env.SYNTHESIS}`,
};