Wednesday, 13 August 2025

Micro Services

 1) what is micro services architecture and how does it work?

A)Microservices architecture is a way of designing software systems where an application is built as a collection of small, independent services that communicate with each other over a network.


Instead of having one big, tightly integrated monolithic codebase, you break it into smaller, self-contained components—each responsible for a specific business function.

How It Works

1. Decomposition into Services

    Each micro service handles a single, well-defined capability (e.g., User Management, Payment Processing, Inventory Tracking).

    Services are developed, deployed, and scaled independently.

2. Independent Deployment

    You can update or replace one service without redeploying the whole system.

    This enables faster releases and easier experimentation.

3. Communication Between Services

    Services talk to each other using APIs (often HTTP/REST, gRPC, or messaging systems like Kafka or RabbitMQ).

    Data sharing is typically minimal—each service usually has its own database to maintain independence.

4. Service Discovery & Load Balancing

    A service registry helps services find each other dynamically.

    Load balancers distribute requests across multiple instances.

5. Resilience & Scaling

    If one service fails, others can still operate (assuming proper design).

    You can scale only the services that need extra capacity instead of the whole system.

6. Technology Flexibility

    Teams can choose different programming languages, frameworks, and storage solutions for each micro service (as long as they speak the agreed-upon communication protocols).


Example

Imagine an e-commerce platform:

Auth Service – Handles login and registration

Catalog Service – Manages product listings

Cart Service – Handles shopping cart operations

Payment Service – Processes transactions

Shipping Service – Calculates delivery estimates and handles logistics


If you need to improve payment speed, you just update the Payment Service without touching the rest.

Advantages

Scalability – Scale services independently

Faster Development – Parallel work by small teams

Resilience – Failure in one service won’t necessarily crash the whole app

Tech Diversity – Use the right tool for each job

Challenges

Complexity – More moving parts than monolithic architecture

Data Consistency – No single database, so distributed transactions are harder

Networking Overhead – More API calls = higher latency potential

DevOps Skills Needed – CI/CD pipelines, containerization (Docker, Kubernetes) often required


1. Steps to Implement Microservices Architecture


 Step 1 – Identify Business Capabilities Break down your application into domains (e.g., Billing, Orders, Shipping, Inventory).

 Each domain becomes a microservice.


 Step 2 – Define Service Boundaries

 Clearly define what each service is responsible for.

 Use Domain-Driven Design (DDD) concepts like bounded contexts.


 Step 3 – Choose Communication Mechanism

 Synchronous: REST, gRPC (for request-response)

 Asynchronous: Message queues like RabbitMQ, Kafka (for event-driven)


 Step 4 – Assign Independent Databases

 Each service should have its own database to avoid tight coupling.

 Choose storage type based on needs (SQL, NoSQL, in-memory).


 Step 5 – Containerize Services

 Use Docker to package services.

 Orchestrate them with Kubernetes or ECS.


 Step 6 – Implement Service Discovery

 Use Eureka, Consul, or Kubernetes DNS to let services find each other dynamically.


 Step 7 – Ensure Observability

 Logging (ELK stack, Splunk)

 Metrics (Prometheus, Grafana)

 Tracing (Jaeger, Zipkin)


 Step 8 – Secure the Services

 API Gateway for routing & authentication.

 OAuth 2.0 / JWT for securing endpoints.


 2. Approaches to Building Microservices

 A. Top-Down (Greenfield Development)

 Build a brand-new system using microservices from scratch.

 Best when starting a new project with no legacy constraints.


 B. Bottom-Up (Refactoring Monolith)

 Start from your existing monolith and gradually extract services.

 Typical pattern:

  1. Identify a feature.

  2. Extract it as a microservice.

  3. Connect via API Gateway.

 Example: Extract Order Processing from your monolith into a separate service.


 C. Strangler Fig Pattern

 Replace monolith modules one by one with microservices until nothing of the monolith remains.

 Both old and new code run together during migration.


 D. Hybrid Approach

 Keep core features in the monolith, and build new features as microservices.

 Gradually replace monolith parts.



Tuesday, 12 August 2025

IQS


 1. Techniques for Generating Tokens


* JWT (JSON Web Token) – Common in Web API, contains claims, digitally signed.

* OAuth2 Access Tokens – Generated via authentication servers (e.g., IdentityServer).

* GUID Tokens – Random unique IDs for session/transaction purposes.

* Refresh Tokens – Long-lived tokens to get new access tokens.

* Encrypted Tokens – Using symmetric/asymmetric encryption.

Fastest: Usually JWT is faster for stateless APIs because no DB lookup is needed once issued.


---

 2. DB First vs Code First (Entity Framework)

* DB First – Start from an existing DB → generate model from DB schema.

* Code First – Start from C# classes → EF generates DB schema.

Which is faster?

* Development Speed: DB First is quicker if DB already exists.

* Flexibility/Maintenance: Code First is better for iterative development.


---

 3. Bundle Config & CDN

* Bundle Config – Combines and minifies multiple JS/CSS files into one bundle for fewer HTTP requests.

* CDN (Content Delivery Network) – Hosts static files across global servers to serve them faster to users.

Which is better?

* Use both: CDN for delivery speed, Bundle for minimizing HTTP requests.

---

 4. Application Object vs Session Object

* Application Object – Global data shared across all users in the application.

* Session Object – Data stored per user session.

Difference: Application is global, Session is user-specific.

---

 5. Abstract Class vs Interface

* Abstract Class – Can have implemented & abstract methods, fields, constructors.

* Interface – Only method/property/event signatures, no implementation (until default methods in C# 8+).

Key Difference: Abstract class supports inheritance with shared code; interface is a contract only.

---

 6. IIS Request Processing

1. Request hits HTTP.sys (kernel mode listener).

2. Passes to IIS Worker Process (w3wp.exe).

3. Request pipeline executes modules/handlers.

4. ASP.NET runtime processes request.

5. Response sent back to client.

---

 7. Status Codes

* 200 OK – Successful request.

* 403 Forbidden – Request understood but denied (permissions).

* 500 Internal Server Error – Server error.


---

 8. What is Render

* In ASP.NET MVC: `RenderBody`, `RenderSection`, `RenderPartial` methods output HTML to response.

* In general: Process of generating and sending the final output to browser.

---

 9. Web API Testing Techniques

* Manual Testing (Postman, Swagger).

* Unit Testing (NUnit, xUnit).

* Integration Testing.

* Automated UI + API Tests (Selenium + API tests).

---

 10. Difference: Web API vs WCF

* Web API – REST, lightweight, works over HTTP only, supports JSON/XML.

* WCF – SOAP, supports multiple protocols (HTTP, TCP, MSMQ), more configuration-heavy.

---

 11. Without Try Block Exception Handling

* Global.asax `Application_Error` event.

* Custom Middleware in .NET Core.

* Exception Filters (`IExceptionFilter`).

---

 12. Verbs in Web API

* GET – Retrieve.

* POST – Create.

* PUT – Update (replace).

* PATCH – Update (partial).

* DELETE – Remove.

* HEAD/OPTIONS – Metadata & pre-flight.

---

 13. Contracts

* A contract defines the shape of communication between service & client in WCF.

---

 14. Service Contract vs Message Contract

* Service Contract – Methods & operations exposed by service.

* Message Contract – Defines custom SOAP message structure.

---

 15. SOLID Principles

1. S – Single Responsibility.

2. O – Open/Closed.

3. L – Liskov Substitution.

4. I – Interface Segregation.

5. D – Dependency Inversion.

1. **S — Single Responsibility Principle (SRP)**

   * A class/module should have only **one reason to change** — meaning it should do **one thing well**.

2. **O — Open/Closed Principle (OCP)**

   * Code should be **open for extension but closed for modification**, allowing you to add features without altering existing, tested code.

3. **L — Liskov Substitution Principle (LSP)**

   * Subclasses should be **replaceable for their base classes** without breaking functionality.

4. **I — Interface Segregation Principle (ISP)**

   * Prefer many **small, specific interfaces** over one large, general-purpose interface to avoid forcing classes to implement things they don’t need.

5. **D — Dependency Inversion Principle (DIP)**

   * Depend on **abstractions, not concrete implementations**, so code is loosely coupled and more maintainable.

---

 16. Install Certificates in IIS

1. Open IIS → Server Certificates.

2. Import certificate (.pfx/.cer).

3. Bind it to HTTPS site in Bindings.

---

 17. Passport Authentication

* Microsoft’s old identity system.

* Redirects to passport.net, authenticates, returns ticket to site.

---

 18. Difference: Web Service vs WCF

* Web Service – SOAP over HTTP, only XML.

* WCF – Supports SOAP + multiple protocols, flexible serialization.

---

 19. Web API Token Types

* Bearer Tokens (JWT).

* OAuth Access Tokens.

* Refresh Tokens.

* Hawk/MAC Tokens (less common).

---

 20. Where Configure Endpoints in WCF

* `web.config` or `app.config` under `<system.serviceModel><services>`.

---

 21. Difference XML vs JSON

* XML – Verbose, supports attributes, tags, schema validation.

* JSON – Lightweight, easier to parse, widely used in REST.

---

 22. Bundle Config vs CDN – Which Better

* CDN – Better for public libraries (fast load globally).

* Bundle Config – Better for your own site scripts to reduce requests.

* Best: Use both.