Terminologies in Microservices

Terminologies in Microservices

What is a Microservice?

· Microservices are a software development technique — a variant of the service-oriented architecture (SOA) architectural style that structures an application as a collection of loosely coupled services.

· In a microservices architecture, services are fine-grained..

· The benefit of decomposing an application into different smaller services is that it improves modularity This makes the application easier to understand, develop, test, and become more resilient to architecture

· It parallelizes development by enabling small autonomous teams to develop, deploy and scale their respective services independently.

Component and Terminologies in Microservices

  1. Eureka Discovery

What is Service Discovery?

In a microservices architecture, each microservice is a standalone application with specific business functionality. Since these microservices need to communicate with each other to function as a complete application, they need to know each other’s network locations. Service Discovery comes into play here, maintaining a record of these services’ locations, helping them find each other, and enabling communication.

What is Spring Cloud Eureka?

Spring Cloud Eureka, part of the Spring Cloud Netflix project, is a service registry that allows microservices to register themselves and discover other services. In essence, it acts like a phone directory for your microservices, providing a mechanism for service-to-service discovery and registration.

2.API Gateway

An API gateway in microservices is a server that acts as a single entry point for clients to access microservices. It acts as a reverse proxy, forwarding client requests to the appropriate microservice instance.

API gateways can help simplify development and improve the efficiency of microservice architecture. They can also help manage and protect microservices by providing functions such as:

1.Authentication

An API gateway can provide an authentication layer to ensure only authorized users can access backend APIs.

2.Rate limiting

An API gateway can limit access to the API by only allowing a certain number of requests per period, user, or group of users.

3.API monitoring and logging

An API gateway can track requests, response times, and service level agreements (SLAs).

4.API transformation

An API gateway can transform request and response payloads.

Some notable API gateways include: Netflix API Gateway: Zuul, Amazon API Gateway, Kong API Gateway, Apigee API Gateway, and MuleSoft.

API gateways can work together with load balancers, but they don’t require each other to function. A load balancer redirects multiple instances of a microservice component to scale the deployment.

What is load-balancing?

Load balancing refers to the efficient distribution of network traffic amongst the available servers, known as a server farm. Within a distributed architecture, individual services are able to communicate with each other, thus constituting network traffic of requests along with external requests made through the system interfaces.

A load-balancer sits in-front of the service instances to monitor the health of the instances and to direct traffic accordingly. If a service instance goes down, the load-balancer will automatically redirect traffic to healthy instances.

3.Aggrigator

The aggregator pattern is used to consolidate responses from multiple microservices into a single response for the client. In this pattern, an aggregator service communicates with the required microservices, collects and processes the data, and sends a unified response. This reduces the number of calls a client must make and simplifies the client-side logic.

Aggregator services can be implemented using technologies like GraphQL or RESTful APIs, and can be optimized for performance using caching and parallel processing techniques.

4. CQRS

CQRS (Command Query Responsibility Segregation) is an architectural pattern that separates read (query) and write (command) operations, enabling them to be scaled and optimized independently. In a microservices architecture, CQRS can be combined with Event Sourcing to create highly scalable and performant systems.

This pattern simplifies the codebase and reduces contention between read and write operations, but introduces additional complexity in handling eventual consistency and synchronization between write and read models. Implementing CQRS requires a thorough understanding of the domain and careful consideration of trade-offs.

5.Circuit Breaker

Circuit Breaker is a design pattern used in microservices architecture where different services interacting with each other over a network, and circuit breaker protects them from cascading failures to enhance the resiliency and fault tolerance of a distributed system.

In simple terms, a Circuit Breaker is a protective and safety mechanism that prevents your application from continuously making requests to a service that has problems or is down.

In a microservices architecture, it works the same way, monitors the health of a microservice and automatically blocks requests from that service if it becomes unhealthy.

The circuit breaker has three states:

Closed: In this state, the circuit breaker allows normal service communication, and requests go through to the service. Circuit breaker monitors the responses from the service for errors. If the responses are successful with no issues, it remains in the closed state.

Open: When the number of failures reaches a threshold, the circuit breaker switches to the open state, preventing requests from reaching the service and providing a fallback response. (Threshold Value like 5 failures within 10 seconds)

Half-Open: Once the timeout or reset interval passes, the circuit breaker goes to the “Half-Open” state. It allows a limited number of test requests to pass through to the service to see if the service has recovered or not. If the test requests succeed, it means the service has recovered and the circuit breaker goes back to “Closed” state. If any of the test requests fails, it means the service has still issues and the circuit breaker goes to “Open” state to block further requests.

There are several tools and frameworks implementing the circuit breaker pattern. Here are some popular options:

1. Netflix Hystrix: Hystrix is an open-source Java library that provides an implementation of the circuit breaker pattern to handle faults tolerance and latency in distributed systems and microservices architectures.

Note: Netflix has officially entered maintenance mode, and users are switching to use alternatives like resilience4j or Sentinel.

2. Resilience4j: Resilience4j is a lightweight, easy-to-use library, which offers a powerful circuit breaker implementation inspired by Netflix Hystrix but designed with functional programming approach.

The SAGA Pattern

ACID properties

The first letter in the ACID acronym stands for atomicity or atomic. ACID transactions are atomic, which means that all operations are executed successfully or everything fails together.

The second letter in ACID acronym stands for consistency which means that the data is in a consistent and a valid state when a transaction starts and when transaction ends. A very common example of it is with the two bank accounts. If you need to transfer funds from one account to another account then the consistency property means that the total value of funds in both accounts is the same at the start of a transaction and at the end of the transaction. Once transaction has ended, the data in the database should be valid and there should be no have done updates.

The next letter starts for isolation, which means that another transaction that is running concurrently cannot access the intermediate state of another transaction.

And the last letter in asset stands for durability which means that after transaction is done the changes in the database are stored durably. If an error or system failure takes place after transaction is done, then the changes made within this transaction will not be reverted.

As explained above, your business logic can use ACID transactions within services. However, it must use Saga Pattern in order to maintain data consistency across services.

Pattern: Maintain data consistency across services using a sequence of local transactions that are coordinated using asynchronous messaging .

A Saga is a sequence of local transactions. Each local transaction updates the local database using the familiar ACID transaction frameworks and publishes an event to trigger the next local transaction in the Saga. If a local transaction fails, then the Saga executes a series of compensating transactions that undo the changes, which were completed by the preceding local transactions

要查看或添加评论,请登录

Santosh Jadhavar的更多文章

  • System Design: Key Concepts

    System Design: Key Concepts

    In software development, designing a system involves more than just writing code. It requires a structured approach to…

  • jQuery Basics

    jQuery Basics

    In today’s web development landscape, creating interactive and dynamic websites has become an essential skill for…

  • Setting Up Kafka and Most used Kafka commands

    Setting Up Kafka and Most used Kafka commands

    Kafka on compose docker image Go to the path where the Docker compose file is present. →…

  • Axon Framework and Axon Server

    Axon Framework and Axon Server

    Axon Framework Here's a typical architecture of Axon-based application, So Axon Framework is based on architectural…

  • Spring Boot

    Spring Boot

    Spring Boot is an extension of the Spring framework that simplifies the process of building Spring applications. Spring…

  • Java 8 Features

    Java 8 Features

    1. Lambda Expressions Lambda expressions in Java are a concise way to represent anonymous functions, also known as…

  • Java Concurrency

    Java Concurrency

    1.What is Concurrency? Concurrency is the concept of executing two or more tasks at the same time (in parallel).

社区洞察

其他会员也浏览了