Part- I : Spring Cloud Gateway – An Introduction

Table of contents
Reading Time: 2 minutes

Cross-cutting requirements in Microservices like authentication, authorization, load balancing, rate limiting etc. also required to be implemented. But the question is where it needs to be implemented. Here, no prices for guesses, it should be thorough API Gateway or Edge server only. ‘Spring Cloud Gateway’, a successor of ‘Netflix Zuul’ and pretty good in fulfilling such demands.

The first level benefit of Spring Cloud Gateway is, it is a non-blocking API. So, what does it means actually? Non-blocking APIs processes requests asynchronously. Here, one thread is always available to address requests. All requests are getting processed in background asynchronously though multiple threads.

Zuul 1 which is having compatibility with Spring Cloud is a blocking API while Zuul 2 is a non-blocking approach but Zuul 2 is not having compatibility with Spring Cloud.

Spring Cloud Gateway has three building blocks,

1. Route

In a most simple way is a mechanism which routes incoming requests to the right destination. The important parameter for such routing are, URI of destination and a condition that needs to be fulfilled. So, technically a route consists of,

  1. ID, it is a unique identification of route. This can be any text of your choice.
  2. Destination URI, It is a URI of microservice which we want to forward the request.
  3. Set of Predicates/filters, here, predicates are condition which needs to be through to access microservice. Filter is kind of layer which allows to modify request or response of microservice.

2. Predicate

As mentioned above predicate is set of criteria and follows functional programming i.e. one can consider lambda expressions to implement functionality. Predicates can be a decision maker which service will be called. Predicate will help you to divert to microservices based on URI patterns. One can control route for microservice on the basis of headers, cookies or parameters as well.

3. Filter

Spring Cloud Gateway filters allows to manipulate request and response of microservices.

Filters are mainly of two type

1) Pre Filters, these filters are implemented between client and service which means after request sent by client and before service is called. So, these filters are for incoming request from client.

2) Post Filters, these filters are implemented between service and client which means after response sent to client(from microservice) and before client receives the response. So, these filters are for out going response from microservice.

Filters can be implemented through defining in properties file as well as through code implementation, choice will be as per need of time.

It is enough to introduce Spring Cloud Gateway. We need to have some deep dive to understand capability of this library of Spring Cloud. Please have patience Part-2 of this article is on the way …..

Written by 

Abhijna, A seasoned technologist holding 19+ years of industry experience. During major part of his career, he worked for finance domain. I-flex solution, Credit-Suisse, J P Morgan and Barclays Global Service Centre are the organizations where he had contributed his technical skills in finance domain. He is accomplished technologist in context of technologies like Java/J2EE platform covering Core Java, JSP/Servlet, Spring, Hibernate and Struts Framework. He knows REST Web Services, Axis2 (SOAP Engine), Informatica 8.6 and Pentaho ETL tools as well. Also, possess working knowledge of Micro-Services, Kafka and AWS as well. Since several years he had demonstrated successfully his technical ability in the form of architectural and leadership roles. Abhijna is very comfortable in ADM (Architecture Development Method) and Enterprise Continuum. Requirement Analysis and Design using UML are also part of his skill set. Abhijna is Certified TOGAF enterprise architect & has good hold on knowledge of PMBOK. He has proven track record of executing projects, interfacing with the customers, requirement analysis, transforming requirements to design and project implementation. He has successfully delivered projects in Financial Services, Investment Banking, Credit Card and Agriculture domains. Apart from this he has experience in risk-management with respect to BASEL-II norms. He is comfortable on financial topics like Bonds, Fixed Income, Corporate Finance, Financial Reporting and Analysis, Quantitative Methods etc.. During entire career in IT industries Abhijna has managed team from the size of 4 to 80 resources within one and multiple geographical locations. Abhijna holds very nice level of technical and management skills which makes his leadership actions more effective.