Skip to main content

Posts

Showing posts from February, 2025

Circuit Breaker Pattern in .net 8

  The Circuit Breaker Pattern will typically send an error response when it is in the open state . This means that the circuit breaker has detected too many failures in the underlying service or resource, and instead of trying to call it repeatedly (which could lead to further failures or resource exhaustion), it immediately returns an error. This helps protect the system from cascading failures. Key Points: Closed State: When all calls are successful, the circuit is closed and calls go through normally. Open State: If the error threshold is exceeded, the circuit opens, and all calls are immediately rejected with an error response without attempting to call the service. Half-Open State: After a cooling period, the circuit breaker allows a limited number of test calls. If these succeed, it closes the circuit; if they fail, it reopens it. In summary, the circuit breaker sends an error response when it is in the open state because it has determined that the underlying serv...

Deploying Microservices API using Azure Kubernetes Service (AKS)

  Deploying Microservices API using Azure Kubernetes Service (AKS) Azure Kubernetes Service (AKS) is a managed Kubernetes service that simplifies deploying, managing, and scaling microservices. 🚀 Step-by-Step Guide to Deploy Microservices on AKS We will deploy a .NET 8 microservices-based API on AKS using Azure Container Registry (ACR) and Kubernetes manifests . 1️⃣ Prerequisites ✅ Azure Subscription ✅ Azure CLI installed ( az ) ✅ Docker installed ✅ kubectl installed ( az aks install-cli ) ✅ .NET 8 installed 2️⃣ Build and Containerize Your .NET API Create a Dockerfile for your microservice (e.g., OrderService ). 📌 Dockerfile # Use the official .NET runtime as the base image FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base WORKDIR /app EXPOSE 80 # Build the application FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY ["OrderService/OrderService.csproj", "OrderService/"] RUN dotnet restore "OrderService/OrderService.csproj...

Types of Data Consistency Models

  Types of Data Consistency Models In distributed systems and databases, consistency models define how data is read and written across multiple nodes. The key types are: 1. Strong Consistency 🔹 Definition: Every read receives the most recent write. No stale or outdated data is ever read. Achieved using synchronous replication . 🔹 Example: Google Spanner ensures strong consistency across data centers. A banking system that updates an account balance immediately after a transaction. 🔹 Pros & Cons: ✅ No stale reads. ✅ Ensures correctness. ❌ High latency due to synchronization. ❌ Not highly scalable. 2. Eventual Consistency (BASE Model) 🔹 Definition: Data eventually becomes consistent across all nodes. Temporary inconsistencies (stale reads) may occur. Suitable for highly available and scalable systems. 🔹 Example: DNS Systems take time to propagate changes across the internet. Amazon DynamoDB, Apache Cassandra use eventual consistency for ...

What is the SAGA Pattern?

  What is the SAGA Pattern? The SAGA pattern is a design pattern used in microservices architecture to handle long-running transactions and ensure data consistency across multiple services. It is commonly used when distributed transactions with two-phase commits (2PC) are not feasible due to their blocking nature. A SAGA is a sequence of local transactions, where each step updates the database and triggers the next step. If a failure occurs, compensating transactions are executed to undo previous operations. Types of SAGA Patterns There are two primary ways to implement a SAGA pattern: Choreography (Event-driven) Each service listens to events and reacts accordingly. No centralized controller; services coordinate via events. Best for simple workflows with fewer services. Orchestration (Command-driven) A central orchestrator service manages the transaction flow. The orchestrator calls each service and waits for responses. Suitable for complex workflows with mu...