Saturday, 11 November 2023

What is Microservice ?

Microservices are an architectural style that involves breaking down a large application into a collection of loosely coupled services that communicate over well-defined APIs. Each microservice is designed to perform a specific business function and can be developed, deployed, and scaled independently.

Here are some key characteristics and principles of microservices:

  1. Loose Coupling: Services are loosely coupled, meaning changes to one service don't require changes to others.
  2. Independent Deployment: Each microservice can be deployed independently, allowing for faster release cycles and reduced risk.
  3. Resilience: Failure in one microservice should not bring down the entire application. Services are expected to be resilient and handle failures gracefully.
  4. Scalability: Services can be scaled independently based on demand, optimizing resource usage.
  5. Technology Diversity: Each microservice can be implemented using different technologies, frameworks, and programming languages, as long as they communicate through standardized interfaces (typically APIs).
  6. Organizational Alignment: Microservices often align with DevOps principles, allowing development teams to take end-to-end ownership of services they develop and operate.
  7. Domain-Driven Design: Microservices are often organized around business capabilities or domains, which can improve development agility and maintainability.
  8. Data Management: Microservices may have their own databases, and data consistency between services is typically maintained through asynchronous communication and eventual consistency.
  9. Containerization: Microservices are often deployed in containers (e.g., Docker containers) to ensure consistency across different environments and simplify deployment.

What is API Gateway in Microservice?

In a microservices architecture, an API Gateway is a crucial component that acts as a single entry point for clients to interact with various microservices. It provides several important functions to facilitate communication between clients and the microservices behind it:

  1. Routing and Aggregation: The API Gateway routes incoming client requests to the appropriate microservices based on the request path, HTTP method, or other criteria. It can also aggregate multiple requests into a single one to reduce chattiness between clients and services.
  2. Protocol Translation: It can translate between different protocols (e.g., REST, WebSocket) used by clients and the internal protocols used by microservices.
  3. Request and Response Transformation: The API Gateway can modify requests and responses to adapt them to different schemas or versions, ensuring compatibility between clients and services.
  4. Authentication and Authorization: It handles authentication and authorization for incoming requests, ensuring that only authorized clients can access certain microservices or endpoints.
  5. Load Balancing: It can distribute incoming requests across multiple instances of a microservice to ensure optimal performance and scalability.
  6. Rate Limiting and Throttling: The API Gateway can enforce rate limits and throttling to protect microservices from being overwhelmed by too many requests.
  7. Logging and Monitoring: It can log requests and responses for auditing purposes and provide monitoring and analytics capabilities to track usage patterns and performance metrics.

Microservices Architecture Components

  1. API Gateway: A single entry point that handles incoming requests and forwards them to the appropriate microservices. It also handles common tasks like authentication, logging, and routing.

  2. Service Discovery: A mechanism for microservices to discover each other and communicate. It keeps track of service instances and their locations dynamically, especially important in large-scale systems.

  3. Load Balancer: Distributes incoming traffic to various instances of a microservice to ensure efficient use of resources and high availability.

  4. Database Per Service: Each microservice often has its own database to ensure independence and flexibility in choosing the right database technology for each service.

  5. Message Broker: For communication between services, message brokers such as RabbitMQ, Kafka, or NATS may be used to provide asynchronous communication and event-driven architecture.

  6. Logging and Monitoring: Tools for centralized logging (e.g., ELK Stack) and monitoring (e.g., Prometheus, Grafana) help ensure visibility and observability of all services in production.

How Microservices Communicate

  1. Synchronous Communication:

    • REST APIs: Services communicate with each other via HTTP using REST APIs. JSON is typically used as the data format.
    • gRPC: A high-performance, open-source RPC framework that allows services to communicate over HTTP/2, offering better performance and support for different languages.
  2. Asynchronous Communication:

    • Message Queues: Services communicate via message brokers like RabbitMQ, Kafka, or ActiveMQ. This approach decouples services and helps improve resilience.
    • Event-driven architecture: Microservices can emit events when a significant action happens (e.g., an order is placed), and other services react to those events asynchronously.

Tools and Technologies for Microservices

  1. Service Discovery:

    • Consul
    • Eureka
    • Kubernetes (with its built-in service discovery)
  2. API Gateway:

    • Kong
    • NGINX
    • Zuul (by Netflix)
  3. Message Brokers:

    • Apache Kafka
    • RabbitMQ
    • NATS
  4. Containerization:

    • Docker (for packaging microservices)
    • Kubernetes (for orchestration)
  5. Monitoring and Logging:

    • Prometheus, Grafana (for monitoring)
    • ELK Stack (Elasticsearch, Logstash, Kibana for logging)
  6. CI/CD:

    • Jenkins, GitLab CI, CircleCI
  7. Databases: Microservices may use various types of databases, including:

    • SQL databases (PostgreSQL, MySQL)
    • NoSQL databases (MongoDB, Cassandra)
    • Key-Value stores (Redis, DynamoDB)

By encapsulating these functionalities, the API Gateway simplifies the client-side experience and offloads common cross-cutting concerns from individual microservices. It promotes scalability, security, and flexibility in managing the interactions between clients and the microservices architecture.

0 comments:

Post a Comment

Topics

ADFS (1) ADO .Net (1) Ajax (1) Angular (47) Angular Js (15) ASP .Net (14) Authentication (4) Azure (3) Breeze.js (1) C# (55) CD (1) CI (2) CloudComputing (2) Coding (10) CQRS (1) CSS (2) Design_Pattern (7) DevOps (4) DI (3) Dotnet (10) DotnetCore (20) Entity Framework (5) ExpressJS (4) Html (4) IIS (1) Javascript (17) Jquery (8) jwtToken (4) Lamda (3) Linq (10) microservice (4) Mongodb (1) MVC (46) NodeJS (8) React (10) SDLC (1) Sql Server (32) SSIS (3) SSO (1) TypeScript (3) UI (1) UnitTest (2) WCF (14) Web Api (16) Web Service (1) XMl (1)

Dotnet Guru Archives