Microservice Patterns

  1. API Gateway:

  • Entry point for microservices with cross-cutting concerns.

  • Handles security, rate limiting, and load balancing.

  • Utilizes tools like Spring Cloud Zuul or Spring Cloud Gateway.

  1. Service Discovery:

  • Allows services to find each other by name.

  • Manages dynamic IP changes caused by container spin-ups.

  • Implemented with Spring Cloud Eureka or Kubernetes service.

  1. Circuit Breaker:

  • Prevents service failures by handling transient errors.

  • Offers fallback mechanisms or caches results.

  • Implemented using libraries like Hystrix or Resilient4J.

  1. Bulkhead:

  • Divides thread pools to isolate resources.

  • Prevents service failures from impacting others.

  • Implemented with Resilient4J for fault tolerance.

  1. CQRS (Command Query Responsibility Segregation):

  • Separates write and read operations for scalability.

  • Optimizes database tables differently.

  1. Event Driven Pattern:

  • Enables communication between services without coupling.

  • Uses event-driven messaging queues like RabbitMQ or Apache Kafka.

  1. Saga:

  • Manages distributed transactions scalably.

  • Offers Orchestration and Choreography options.

  1. Strangler Pattern:

  • Decomposes monolithic apps into microservices gradually.

  • Extracts features into separate microservices.

  1. Sidecar:

  • Attaches cross-cutting concern services alongside business services.

  • Deploys sidecar services in the same pod for seamless communication.

  • Utilizes tools like Envoy proxy.

  1. BFF (Backend for Frontend):

  • Customizes microservices for different platforms.

  • Optimizes performance based on platform requirements.

  • Ensures redundancy while avoiding resource waste.