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
  • Routing application traffic with Kubernetes Ingress

In the previous chapter, you learned several aspects of building resilient, scalable, and cost-effective applications using the reactive paradigm. In this chapter, the Spring reactive stack will be the foundation for implementing an API gateway for the Polar Bookshop system. An API gateway is a common pattern in distributed architectures, like microservices, used to decouple the internal APIs from the clients. When establishing such an entry point to your system, you can also use it to handle 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 and implement 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 servers and 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 Combining circuit breakers, retries, and time limiters

9.3 Request rate limiting with Spring Cloud Gateway and Redis

9.3.1 Running Redis as a container

9.3.2 Integrating Spring with Redis

9.3.3 Configuring a request rate limiter

sitemap