9 API Gateway and Circuit Breakers

 

This chapter covers:

  • Implementing edge services with Spring Cloud Gateway and Reactive Spring
  • Configuring circuit breakers with Spring Cloud Circuit Breaker and Resilience4J
  • Defining rate limiters with Spring Cloud Gateway and Redis
  • Managing distributed sessions with Spring Session Data Redis

In the previous chapter, you learned several aspects of building resilient, scalable, and cost-effective applications using the reactive paradigm. The reactive Spring stack will be the foundation for implementing an API gateway for the Polar Bookshop system. The API gateway is a common pattern in distributed architectures like microservices to decouple the internal APIs from the clients. When establishing such an entry-point to your system, you can also leverage it to implement cross-cutting concerns, such as security, monitoring, and resilience.

This chapter will teach you how to use Spring Cloud Gateway to build an Edge Service application, implementing an API gateway, and some of those cross-cutting concerns. You’ll improve the resilience of the system by configuring circuit breakers with Spring Cloud Circuit Breaker, defining rate limiters with Spring Data Redis Reactive, and using retries and timeouts just like you learned in the previous chapter.

9.1 Edge server with Spring Cloud Gateway

9.1.1 Bootstrapping an edge server with Spring Cloud Gateway

9.1.2 Defining routes and predicates

9.1.3 Processing requests and responses through filters

9.2 Fault tolerance with Spring Cloud Circuit Breaker and Resilience4J

9.2.1 Introducing circuit breakers with Spring Cloud Circuit Breaker

9.2.2 Configuring a circuit breaker with Resilience4J

9.2.3 Defining fallback REST APIs with Spring WebFlux

9.2.4 Working with circuit breakers, retries, and time limiters together

9.3 Rate limiting with Spring Cloud Gateway and Redis

9.3.1 Running Redis as a Docker container

9.3.2 Integrating Spring with Redis

9.3.3 Using the RequestRateLimiter filter with Redis

9.4 Distributed session management with Redis

9.4.1 Handling sessions with Spring Session Data Redis

9.5 Summary

sitemap