Node.js › Microservices Architecture with Node.js
What is an API Gateway, and what role does it play in front of a collection of Node.js microservices?
IntermediateAnswer
An API Gateway acts as a single entry point for external clients, routing incoming requests to the appropriate backend microservice, while also centralizing cross-cutting concerns like authentication, rate limiting, request/response transformation, and aggregating responses from multiple services into a single response tailored for a specific client (like a mobile app needing a combined payload from three separate services) -- sparing individual microservices and external clients from needing to handle all of this routing and cross-cutting logic themselves.
// Simplified API Gateway routing logic
app.use('/api/users', authenticate, proxy('http://user-service:3001'));
app.use('/api/orders', authenticate, proxy('http://order-service:3002'));
app.use('/api/products', proxy('http://product-service:3003')); // no auth needed for public dataReal-world example A mobile app's dashboard screen calls a single API Gateway endpoint that internally fans out to the user, order, and notification microservices in parallel and combines their responses into one tailored payload, sparing the mobile client from needing to make and coordinate three separate network requests itself.