Reviewing the Microservices Architecture with Spring

Published: May 1, 2022

Spring Cloud

Spring Cloud Config

  • It handles the management of the application configuration data through a centralized service

  • This ensures that no matter how many microservice instances you bring up, they will always have the same configuration.

  • It provides server-side and client-side support for externalized configuration in a distributed system.

Spring Cloud Service Discovery

  • A service registry is useful because it enables client-side load-balancing and decouples service providers from consumers without the need for DNS.

  • You can abstract away the physical location (IP and/or server name) of where your servers are deployed from the clients consuming the service.

  • It also handles the registration and deregistration of service instances as these are started and shut down.

    • Service Registration - How a service registers with the service discovery agent

    • Client lookup of service address - How a service client looks up service information

    • Information sharing - How nodes share service information

    • Health monitoring - How services communicate their health back to the service discovery agent

Spring Cloud LoadBalancer and Resilience4j

  • Spring Cloud LoadBalancer library - It allows us to create applications that communicate with other applications in a load-balanced fashion. Using any algorithm we want, we can easily implement load balancing when making remote service calls

  • Resilience4j - It is a fault tolerance library which offers the following patterns for increasing fault tolerance due to network problems or failure of any of our multiple services

    • Circuit breaker - Stops making requests when an invoked service is failing

    • Retry - Retries service when it temporarily fails

    • Bulkhead - Limits the number of outgoing concurrent service requests to avoid overload

    • Rate limit - Limits the number of calls that a service receives at a time

    • Fallback - Sets alternative paths for failing requests

Spring Cloud Gateway

  • Mapping the routes for all the services in your application to a single URL

  • Building filters that can inspect and act on the requests and responses coming through the gateway. These filters allow us to inject policy enforcement points in our code and to perform a wide number of actions on all of our service calls in a consistent fashion. In other words, these filters allow us to modify the incoming and outgoing HTTP requests and responses.

  • Building predicates, which are objects that allow us to check if the requests fulfill a set of given conditions before executing or processing a requests

  • It is a reverse proxy. A reverse proxy is an intermediate server that sits between the client trying to reach a resource and the resource itself. The client has no idea it's even communicating with a server. The reverse proxy takes care of capturing the client's request andthen calls the remote resource on the client's behalf. Spring Cloud Gateway takes a microservice call from a client and forwards it to the upstream.

  • It integrates with Netflix's Eureka Server and can automatically map services registered with Eureka to a route.

    • Static routing - A service gateway places all service calls behind a single URL and API route. This simplifies development as we only have to know about one service endpoint for all of our services.

    • Dynamic routing - A service gateway can inspect incoming service requests and, based on the data from the incoming service, perform intelligent routing for the service caller.

    • Authentication and Authorization - Because all service calls route through a service gateway, the service gateway is a natural place to check whether the callers of a service have authenticated themselves.

    • Metric collection and logging - A service gateway can be used to collect metrics and log information as a service call passes through it.