Microservices FlashCard
Microservices FlashCard
Microservices FlashCard
------------
------------
Saga
------------
------------
------------
------------
Server-side Load balancing
Steps:-
1) Create a spring boot project with spring cloud gateway
and spring cloud eureka client dependencies.
- spring-cloud-starter-netflix-eureka-client
=> gateway project needs to register itself to the Eureka Server.
- spring-cloud-starter-gateway
=> converting your microservice into an API gateway
========================================
Commonly used Spring Cloud annotations:
1) @EnableCircuitBreaker
2) @EnableConfigServer
3) @EnableEurekaServer
4) @EnableFeignClients
5) @FeignClient(name=”ApplicationName”)
Annotations On Fault Tolerance provided by Resilience4j:
1) @RateLimiter
2) @Retry
3) @CircuitBreaker
4) @Bulkhead
5) @Timelimiter
========================================
JAR Vs WAR
WAR files are used for packaging and distributing web applications.
========================================
Useful Ports
========================================
Purpose of an API gateway in microservices
An API gateway in microservices acts as a central entry point
that handles client requests and
then routes them to the appropriate microservices.
Several purposes of API Gateway
1) Aggregation
- combine multiple backend microservices' responses into
a single cohesive response to fulfill a client request.
This reduces round-trips.
2) Load balancing
- can distribute incoming requests across
multiple instances of the same microservice.
4) Caching
- can cache responses from microservices to improve performance and
reduce redundant requests.
5) Protocol translation
- can translate client requests from one protocol.
========================================
How do microservices ensure fault tolerance and
resilience in distributed systems.
1) Redundancy
- By replicating microservices across multiple instances.
3) Bulkheads
- Microservices are isolated from each other.
Hence failures remain unaffected in any service.
4) Graceful Degradation
- can gracefully degrade their functionality.
or provide limited but essential features.
5) Timeouts
- Setting appropriate timeouts for communication between microservices.
========================================
Coupling and Cohesion
Service discovery:
When a microservice needs to communicate with another microservice,
it queries the service registry to discover the network location and
endpoint details of the target service.
1) Container orchestration
2) High availability - Kubernetes supports multiple replicas of services.
3) Auto-scaling
4) Service discovery
- Kubernetes provides built-in service discovery and
DNS resolution for communication between services
IMP:-
A materialized view and the data it includes are "disposable"
since they may be recreated entirely from the underlying data sources.
========================================
How does microservices architecture facilitate rolling updates and
backward compatibility
1) Service isolation
2) API versioning
3) Semantic versioning
4) Feature flags
5) Graceful degradation
E.g. 2.6.8
2.6.9 => for bug fix
2.7.0 => for adding new functionality
------------
Valid identifiers are in the set [A-Za-z0-9] and cannot be empty.
Pre-release metadata is identified by appending a hyphen
to the end of the SemVer sequence.
E.g. Pre-release for version "1.0.0" could be "1.0.0-alpha.1"
1) Codebase
2) Dependencies
3) Config
4) Backing Services
5) Build, release, and Run
6) Processes
7) Port Binding
8) Concurrency
9) Disposability
10) Dev/prod parity
11) Logs
12) Admin processes
Certain scripts which are required for the execution of certain tasks,
should be maintained in the codebase and managed by the version control system.
========================================
Use of configuration management tools in microservices
Facilitates the dynamic and centralized management of configuration settings
for individual services.
Tools like the ELK stack (Elasticsearch, Logstash, Kibana), Graylog, and Splunk
are commonly used to implement log aggregation and
centralized logging in microservices architectures.
========================================
Microservices Vs Serverless Architecture
Serverless:
• Serverless architecture allows developers to focus on writing code
without managing the underlying infrastructure.
• It operates on a pay-as-you-go model with developers only paying for the
actual compute resources used during code execution.
• Serverless functions are event-driven and stateless, meaning
they are triggered by specific events and
do not retain any state between executions.
• Scaling is automatic and based on demand,
ensuring that resources are allocated dynamically as needed.
• Serverless is ideal for event-driven applications,
real-time processing, and short-lived tasks.
========================================
How do you ensure data privacy and compliance in a microservices ecosystem?
1) Data encryption - Implement encryption techniques (e.g., TLS/SSL).
2) Access control and authentication
- Use robust authentication mechanisms, such as OAuth and JWT.
3) Role-based access control (RBAC)
- to manage permissions and
restrict access based on the roles of users or services.
4) Data masking
5) Compliance and auditing
6) Secure APIs
7) Least privilege principle
8) Data lifecycle management
8) Data governance
9) Regular security assessments
========================================
Domain-Driven Design (DDD)
Principles of DDD:-
1) Ubiquitous language
2) Bounded contexts
3) Aggregates
5) Domain events
6) Context mapping
Application in microservices:
In a microservices architecture, DDD principles can be applied as follows:
• Each microservice represents a bounded context,
containing its domain logic and data.
• Aggregates are mapped to individual microservices,
allowing for more focused and independent development.
• Domain events can be published and subscribed to by various microservices
to maintain consistency and provide loose coupling.
• By embracing the ubiquitous language, developers and
domain experts can have meaningful discussions,
leading to better-aligned solutions.
========================================
Best practices for versioning microservices APIs
1) URL versioning
2) Header versioning
3) Semantic versioning
4) Deprecation strategy
5) API documentation
6) Continuous integration and deployment
7) API gateways
8) Version negotiation
9) Graceful migration
10) Monitoring and analytics
========================================
Blue-green deployment strategy and its advantages in a microservices setup
1) Horizontal partitioning
- Data is distributed across multiple databases
based on a specific criterion like customer ID or date range
- Ensures that each microservice only deals with a subset of the data,
which improves performance and scalability.
2) Vertical partitioning
- Breaking down a large table into smaller, more focused tables
3) Sharding
- data is distributed across different databases
or clusters based on a specific shard key.
- Enables independent scaling of each shard.
4)
========================================
Canary testing is a deployment strategy that allows
the gradual release of new microservices versions to a subset of users.
========================================
Importance of contract testing in a microservices environment
1)Response time
2)Error rate
3)Throughput
4)CPU and memory usage
5)Network latency
6)Request rate distribution
7)Database performance
8)Service dependency health
========================================
========================================
========================================
========================================
========================================
========================================