Search This Blog

Saturday, June 28, 2025

Q16-Q20

Q16: Tell me something about CQRS? 
Q17: Do we have two different databases in CQRS?
Q18: Techniques to keep two database in Sync?
Q19: Define Database per Microservice Architecture Design pattern? [Microservice Architecture Design patterns -- Database per Microservice, Event Sourcing, CQRS, Saga, BFF, API Gateway, Strangler, Circuit Breaker, Externalized Configuration, Consumer-Driven Contract Tracing]
-----------------------------------------------------------------------------------------------------------------------------
Q16: Tell me something about CQRS? 

Answer:
CQRS (Command Query Responsibility Segregation) is a powerful architectural pattern often used in microservices to separate the responsibilities of reading and writing data

Benefits:
>> This separation allows each side to be optimized independently for performance, scalability, and complexity.

CQRS splits the application into two distinct parts:

Command Side (Write Model): Handles operations that change data (Create, Update, Delete).
Query Side (Read Model): Handles operations that retrieve data (Read).

-----------------------------------------------------------------------------------------------------------------------------
Q17: Do we have two different databases in CQRS?

Answer:
In CQRS, it's common but not mandatory to use two separate databases for the read and write sides. 

Benefits of using Two databases:
1. Independent Scaling : We can scale READ DB horizontally to handle high query loads.
2. Technology Flexibility: You might use a relational database (e.g., PostgreSQL) for writes. And a NoSQL database (e.g., MongoDB, Elasticsearch) for reads.

-----------------------------------------------------------------------------------------------------------------------------
Q18: Techniques to keep two database in Sync?

Answer:
Techniques
1. Event-Driven Synchronization (Most Common)
  • How it works: After a write operation, the system emits a domain event (e.g., OrderCreated, CustomerUpdated).
  • These events are published to a message broker (like Kafka, RabbitMQ, or Azure Service Bus).
  • A consumer service listens to these events and updates the read database (e.g., MongoDB).
  • This enables eventual consistency (With little latency). 
2. Dual Writes (Not Recommended)#
The application writes to both databases in the same transaction or sequentially.
⚠️ Cons:
Risk of inconsistency if one write fails.
Hard to manage rollback and error handling.
-----------------------------------------------------------------------------------------------------------------------------
Q19: Define Database per Microservice Architecture Design pattern? 

Answer:
Each Microservice has its own dedicated Database and un related microservice can NOT access db of other domain directly. 

Advantages:
1. Understanding of Project and related DB is easy as it has limited tables and data. 
2. Scaling of DB is easy as required. 
-----------------------------------------------------------------------------------------------------------------------------


Friday, June 27, 2025

Q11-Q15

Q11: What is Docker?
Q12: What is Docker Containerization?
Q13: What is the basic structure of Docker file. What does it do?
Q14:  What is Docker image?
Q15: What is the difference between Docker image and Docker container?

Master Stroke:
Dockerfile → builds → Docker Image → runs as → Docker Container → managed inside → Kubernetes Pod


[Docker Related Questions]
-----------------------------------------------------------------------------------------------------------------------------
Q11: What is Docker

Answer:
Docker is an open-source platform that automates the deployment, scaling, and management of applications using containers. Containers are lightweight, portable units that package an application with all its dependencies, ensuring it runs consistently across environments—whether it's your laptop, a test server, or production
-----------------------------------------------------------------------------------------------------------------------------
Q12: What is Docker Containerization?

Answer:
Containerization is the process of packaging applications and their dependencies into containers.
Unlike Virtual Machines (VMs), containers don’t need a full guest OS. They share the host’s OS kernel but run isolated processes.
This makes containers faster, lighter, and more portable compared to VMs.
-----------------------------------------------------------------------------------------------------------------------------
Q13: What is the basic structure of Docker file. What does it do?

Answer: 

A Dockerfile is a text file that contains instructions for building a Docker image. It’s like a recipe for creating containers. 
So, a Dockerfile is essentially the blueprint for creating a Docker image.

A Dockerfile is a text file that contains a series of instructions on how to build a Docker image.

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY . .
RUN dotnet restore "MyMicroservice/MyMicroservice.csproj"

WORKDIR "/src/MyMicroservice"
RUN dotnet build "MyMicroservice.csproj" -c Release -o /app/build
RUN dotnet publish "MyMicroservice.csproj" -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
COPY --from=build /app/publish .

EXPOSE 8080
ENTRYPOINT ["dotnet", "MyMicroservice.dll"]


# 1. Uses the official .NET 8 SDK image to compile and build the application. This image contains the compiler, Build tools, Restore tools. Everything needed to build and publish your application
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

# 2. Sets the working directory inside the container to /src.
WORKDIR /src

# 3. Copy project files and all the source code into the container. Restores NuGet packages. Prepares all dependencies needed for the build.
COPY . .
RUN dotnet restore "MyMicroservice/MyMicroservice.csproj"

# 4. Changes the working directory to the project folder. Builds the application in Release mode.
WORKDIR "/src/MyMicroservice"
RUN dotnet build "MyMicroservice.csproj" -c Release -o /app/build

# 5. Publish the app. Prepares the app for runtime by including only necessary files.
RUN dotnet publish "MyMicroservice.csproj" -c Release -o /app/publish

# 6. Use the runtime image for the final container. Uses a smaller runtime-only image. Its just a core runtime image. Not like we have in Step 1, which is much bigger. 
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
COPY --from=build /app/publish .

# 7. Expose the port your service listens on
EXPOSE 8080

# 8. Set the entry point. Defines the command to run when the container starts.
ENTRYPOINT ["dotnet", "MyMicroservice.dll"]

-------------------------------------------------------------------------------------------------------------------------------
Q14:  What is Docker image?

Answer:
A Docker image is a snapshot of a container's file system and configuration. It’s built from a Dockerfile and contains everything needed to run an app:
Code, Runtime, Libraries, Environment variables
-----------------------------------------------------------------------------------------------------------------------------
Q15: What is the difference between Docker image and Docker container?

Answer:
Docker Image - 
1- Blueprint for creating containers
2. Created from Docker file. 
3. Its a static instance/snapshot of your application/code. 

Docker Containers: 
1- They are created from Image. They are running instance of an image. 
2. Created from an image. 
3. Running instance of an image. 

Points:
A single image can have multiple containers running on it. 
Image is like a class in dotnet while containers are like object of that class. 

-----------------------------------------------------------------------------------------------------------------------------

Q31-Q35

Q31: What is pods and how it is related to Docker images and Docker containers? Q32: What is the use of Compose Docker file? Q33. What are t...