Q6: What could be your folder structure for MS project in C#?
Q7: What is circuit breaker design pattern? When to use.
Q8: What are the various states of Circuit breaker design pattern?
Q9: How Circuit monitors the failure and get activated. How it changes it states to normal again?
Q10: List various Microservices Architecture design pattern?
Circuit Design Pattern
-----------------------------------------------------------------------------------------------------------------------------
Q6: What could be your folder structure for MS project in C#?
Answer:
MyService/
│
├── MyService.Api/ # API layer (Controllers, Startup, Program)
│ ├── Controllers/
│ ├── Models/
│ ├── DTOs/
│ ├── Startup.cs
│ └── Program.cs
│
├── MyService.Application/ # Business logic layer
│ ├── Interfaces/
│ ├── Services/
│ └── DTOs/
│
├── MyService.Domain/ # Core domain logic
│ ├── Entities/
│ ├── ValueObjects/
│ ├── Exceptions/
│ └── Interfaces/
│
├── MyService.Infrastructure/ # Data access, external integrations
│ ├── Persistence/ # EF Core DbContext, Repositories
│ ├── Migrations/
│ └── ExternalServices/
│
├── MyService.Tests/ # Unit and integration tests
│
└── dockerfile # For containerization
Key points for microservices:
API layer → Handles HTTP endpoints (Controllers, minimal APIs).
Application layer → Contains business logic, services, and use cases.
Domain layer → Pure business models and rules, independent of frameworks.
Infrastructure layer → Database, external APIs, message queues.
Tests → Unit tests for each layer, integration tests for endpoints.
-----------------------------------------------------------------------------------------------------------------------------
Q7: What is circuit breaker design pattern? When to use.
Answer:
It acts like an electrical circuit breaker: it monitors for failures and stops the flow of requests to a failing service to prevent cascading failures and allow time for recovery.
When to Use:
- When calling remote services, APIs, or databases that might fail or become unresponsive.
- In microservices where one service depends on another.
- When you want to fail fast instead of waiting for timeouts.
In this pattern, a circuit breaker acts as a safety net between the client and the service, protecting the client from failures in the service. The circuit breaker monitors the status of the service and, if it detects that the service is failing, it can open the circuit and prevent further requests from being sent to the service until the service has recovered.
-----------------------------------------------------------------------------------------------------------------------------
Q8: What are the various states of Circuit breaker design pattern. How Circuit monitors the failure and get activated. How it changes it states to normal again?
Answer:
Different states in the circuit break pattern
Closed - When everything works well according to the normal way, the circuit breaker remains in this closed state.
Open - When the number of failures in the system exceeds the maximum threshold, this will lead to open up the open state. This will give the error for calls without executing the function.
Open -Half (Half Open Half Close) - After having run the system several times, the circuit breaker will go on to the half-open state in order to check the underlying problems are still exist.
-----------------------------------------------------------------------------------------------------------------------------
Q9: How Circuit monitors the failure and get activated. How it changes it states to normal again?
Answer:
Here’s how it works in simple terms:
1. Normal Operation (Closed State)
- Requests flow normally to the downstream service.
- The Circuit Breaker monitors failures (e.g., timeouts, exceptions).
- If the failure rate crosses a configured threshold (say, 5 failures in 10 requests), it opens the circuit.
2. Failure Mode (Open State)
- No new requests are sent to the failing service — they fail fast (avoiding long waits).
- Instead, the system may: Return a fallback response Queue the request for later retry
3. Recovery Check (Half-Open State)
- After a “cool-down period” (timeout), the Circuit Breaker lets a small number of requests through to test the service.
- If they succeed → circuit goes back to Closed (normal).
- If they fail → it returns to Open for another cooldown.
-----------------------------------------------------------------------------------------------------------------------------
Q10: List various Microservices Architecture design pattern?
Answer:
1. Database per Microservice
2. Event Sourcing
3. CQRS
4. Saga
5. BFF (Backend for FrontEnds)
6. API Gateway
7. Strangler
8. Circuit Breaker
9. Externalized Configuration
10. Consumer-Driven Contract Tracing
11. Aggregator Design pattern.
No comments:
Post a Comment