Microservice architecture involved breaking down a complex application into small self-contained applications so that each one of them can be scaled and maintained independently. With the plethora of benefits that comes with the microservice architecture, it is no wonder why everyone in the IT sector is moving towards this new architecture!
At the core of microservice architecture is the concept of reverse proxying. A reverse proxy plays a pivotal role in directing traffic among different microservices, as well as distributing the workload across multiple instances of a microservice. Without the reverse proxy, the intricate web of interactions and load distribution within the microservice architecture as we understand it today would simply not be feasible!
Let us dive deep into the role of a reverse proxy in a microservices settings!
A proxy is a server that sits between a client’s computer and internet. Any traffic that comes out of client’s machine passes through the proxy server. For the rest of the internet, it appears as though the proxy server is initiating the requests.
There are several reasons why one would use a proxy server. Some of them are as follows -
A reverse proxy is a server that sits between the internet and backend servers. Any traffic that is destined for the servers must pass through the reverse proxy. For the rest of the internet, it appears as though the reverse proxy is serving the requests.
There are several benefits to using reverse proxies in general. You may find some listed here.
The concept of a reverse proxy breathes life into the microservice architecture, enabling the client to navigate the dynamic environment of microservices by determining which servers to access. Without this vital component, the client would be left without the means to effectively navigate the intricate landscape of the microservices architecture.
Services in a microservice architecture scales up and down based on the load. This means that replicas of a service may come and go anytime during the lifetime of an application. Reverse proxy detects the servers of a service and effectively directs client’s traffic to these.
Since a service may have several replicas running, it becomes important that the client’s requests are properly distributed across available servers. Load balancing is just another feature of revere proxy that comes to use here. Reverse proxy smartly distributes the load across available replicas of a service.
Since any request entering our application goes through the reverse proxy, it is a good place to monitor requests and perform logging. It helps in gaining crucial insights about the number of services present in the system.
In a microservices setting, a reverse proxy is also used to route the internal traffic of the cluster. This is specially useful for the case of service-to-service communication.
Caching is a general advantage that comes with the use of reverse-proxy. The proxy server can return cached results for similar queries, thus improving the time to response for the client.
A single client’s request may require response aggregation from more than one service at the backend. Such aggregation can be performed by the reverse proxy leaving the client with a clean endpoint to use!
A reverse proxy can be used in different configuration. These configurations usually dictates the OSI layer at which the routing decision is taken. Popularly there are two famous proxying - (1) Proxying at Layer 4, and (2) Proxying at Layer 7. As we move up the layers, we decode more information from the internet packets that can be used for routing decision.
Layer 4 in the OSI model is the transport layer. From an application developer’s perspective, the things available at layer 4 for routing decision are -
Thus a layer 4 proxy can only make routing decisions based on IP and port of server and client. It cannot look into the contents of the requests and thus can make limited routing decisions.
There are several reasons as to why one would use layer 4 proxy -
There are several downsides to the layer 4 proxy as well -
Layer 7 in the OSI model is the application layer. From an application developer’s perspective, the things available at layer 7 for routing decision are -
Since a lot more content for decision making is available at layer 7, smarter routing can be performed.
Here are some reasons why one would use a layer 7 proxy -
Here are some downsides to using a layer 7 proxy -
Reverse proxy is undoubtedly one of the important piece in a microservice architecture. Without it, the true benefits of microservice architecture can never be realised in their entirety.
With this we reach the end of this blog! I hope you learned something new today.