29 January, 2025

Interview questions - full stack Developer(.net/auzre)

Below are best-practice answers to the common interview questions I listed earlier. These answers are designed to be concise, clear, and demonstrate your expertise.


.NET Questions

1. What is the difference between IEnumerable and IQueryable?

  • IEnumerable:

    • Works with in-memory collections (e.g., List, Array).

    • Executes queries on the client side (LINQ-to-Objects).

    • Suitable for small datasets.

  • IQueryable:

    • Works with remote data sources (e.g., databases).

    • Executes queries on the server side (LINQ-to-Entities).

    • Suitable for large datasets and optimized for performance.

  • Example:

    csharp
    Copy
    IEnumerable<Customer> customers = db.Customers.Where(c => c.Age > 30).ToList(); // Executes in memory
    IQueryable<Customer> customers = db.Customers.Where(c => c.Age > 30); // Executes on the database server

2. How does dependency injection work in ASP.NET Core?

  • Dependency Injection (DI) is a design pattern used to achieve Inversion of Control (IoC) between classes and their dependencies.

  • How it works:

    • Services are registered in the Startup.cs or Program.cs file using services.AddSingletonservices.AddScoped, or services.AddTransient.

    • The framework injects these services into controllers, views, or other services via constructor injection.

  • Example:

    csharp
    Copy
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddScoped<IMyService, MyService>(); // Register service
    }
    
    public class MyController : Controller
    {
        private readonly IMyService _myService;
        public MyController(IMyService myService) // Inject service
        {
            _myService = myService;
        }
    }

3. Explain the lifecycle of a .NET application.

  • Compilation:

    • Source code is compiled into Intermediate Language (IL) by the C# compiler.

  • Execution:

    • The Common Language Runtime (CLR) loads the IL code and compiles it into machine code using Just-In-Time (JIT) compilation.

  • Memory Management:

    • The Garbage Collector (GC) automatically manages memory allocation and deallocation.

  • Application Domains:

    • .NET applications run in isolated environments called application domains.


4. What is the difference between Task and Thread in C#?

  • Thread:

    • Represents an actual OS-level thread.

    • Resource-intensive and harder to manage.

  • Task:

    • Represents an asynchronous operation.

    • Uses the ThreadPool for efficient resource management.

    • Supports async/await for easier asynchronous programming.

  • Example:

    csharp
    Copy
    // Thread
    Thread thread = new Thread(() => DoWork());
    thread.Start();
    
    // Task
    Task.Run(() => DoWork());

5. How do you handle exceptions globally in ASP.NET Core?

  • Use middleware to handle exceptions globally.

  • Example:

    csharp
    Copy
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error"); // Global exception handler
        }
    }

Azure Questions

1. What is the difference between Azure App Service and Azure Functions?

  • Azure App Service:

    • Used for hosting web applications, APIs, and mobile backends.

    • Supports multiple languages and frameworks.

    • Ideal for long-running applications.

  • Azure Functions:

    • Serverless compute service for event-driven tasks.

    • Executes code in response to triggers (e.g., HTTP, timers, queues).

    • Ideal for short-lived, stateless functions.


2. How do you secure an Azure SQL Database?

  • Authentication:

    • Use Azure Active Directory (AAD) or SQL authentication.

  • Authorization:

    • Implement Role-Based Access Control (RBAC).

  • Encryption:

    • Enable Transparent Data Encryption (TDE) for data at rest.

    • Use SSL/TLS for data in transit.

  • Firewall Rules:

    • Restrict access to specific IP addresses or virtual networks.


3. Explain the difference between Azure Blob Storage and Azure Table Storage.

  • Azure Blob Storage:

    • Used for storing unstructured data like images, videos, and documents.

    • Supports tiered storage (Hot, Cool, Archive).

  • Azure Table Storage:

    • NoSQL key-value store for structured data.

    • Ideal for storing metadata or semi-structured data.


4. How do you implement CI/CD using Azure DevOps?

  • Steps:

    1. Create a repository in Azure DevOps.

    2. Define a build pipeline (e.g., using YAML) to compile and test the code.

    3. Define a release pipeline to deploy the application to Azure.

    4. Use triggers to automate the process (e.g., on code push).

  • Example:

    yaml
    Copy
    trigger:
      branches:
        include:
          - main
    
    pool:
      vmImage: 'windows-latest'
    
    steps:
    - task: UseDotNet@2
      inputs:
        packageType: 'sdk'
        version: '6.x'
    - script: dotnet build --configuration Release
    - script: dotnet test

5. What is the purpose of Azure Active Directory (AAD)?

  • AAD is a cloud-based identity and access management service.

  • Key Features:

    • Single Sign-On (SSO) for applications.

    • Multi-Factor Authentication (MFA) for enhanced security.

    • Integration with on-premises Active Directory.


Full Stack Questions

1. How do you optimize the performance of a web application?

  • Frontend:

    • Minify and bundle CSS/JS files.

    • Use lazy loading for images and components.

  • Backend:

    • Optimize database queries and use caching (e.g., Redis).

    • Use asynchronous programming to avoid blocking threads.

  • Infrastructure:

    • Scale horizontally using load balancers.

    • Use Content Delivery Networks (CDNs) for static assets.


2. What are the differences between REST and GraphQL?

  • REST:

    • Uses fixed endpoints for resources.

    • Over-fetching or under-fetching of data can occur.

  • GraphQL:

    • Uses a single endpoint for all queries.

    • Clients can request only the data they need.


3. How do you handle state management in a frontend application?

  • Local State:

    • Use component state (e.g., React useState).

  • Global State:

    • Use state management libraries like Redux or Context API.

  • Server State:

    • Use libraries like React Query or SWR for caching and synchronization.


4. Explain the concept of microservices and when to use them.

  • Microservices:

    • Architectural style where applications are built as a collection of small, independent services.

  • When to Use:

    • For large, complex applications requiring scalability and flexibility.

    • When different teams work on different parts of the application.


5. How do you ensure security in a full stack application?

  • Authentication:

    • Use OAuth, JWT, or AAD for secure authentication.

  • Authorization:

    • Implement role-based access control (RBAC).

  • Data Protection:

    • Encrypt sensitive data at rest and in transit.

  • Input Validation:

    • Sanitize user inputs to prevent SQL injection and XSS attacks.

No comments:

Post a Comment

Microservices vs Monolithic Architecture

 Microservices vs Monolithic Architecture Here’s a clear side-by-side comparison between Microservices and Monolithic architectures — fro...