When we work on microservices, there are often a number of common concerns / functionalities that should be shared amongst different services.
These common functionality include authentication, monitoring, logging, rate-limiting, IP whitelisting, and request transformations.
Instead of having each service verify their own request guarantees, it makes sense to offload these functionalities to a central gateway / proxy. This way, your engineering team is focused on building actual features/services and less boilerplate.
Most of the functionality of a service should be delegated to a proxy.
This pattern is often called the API Gateway.
Today, we’ll be building a simple API gateway from scratch. Alternatively, you can use some existing open source / commercial gateways from this curated list.
A Minimum Viable Gateway
For simplicity, we’ll work on just two core features:
Routing: We want to specify which services to forward requests to when a request hits a particular route at our gateway.